IDS peak ICV v1.2.0
Loading...
Searching...
No Matches
iimageview.py
Go to the documentation of this file.
1from __future__ import annotations
2
3from abc import ABC, abstractmethod
4from typing import TYPE_CHECKING
5
6if TYPE_CHECKING:
7 import numpy as np
9from ids_peak_common.datatypes.pixelformat import PixelFormat
10from ids_peak_common.datatypes.metadata import Metadata
11
12
13class IImageView(ABC):
14 """!
15 @brief
16 Interface for viewing image pixel data from arbitrary sources, for example a camera buffer.
17
18 @ingroup ids_peak_common_python_types
19 """
20
21 @abstractmethod
22 def to_numpy_array(self, copy: bool = True) -> np.ndarray:
23 """!
24 @brief
25 Returns the image data as a NumPy array.
26
27 By default, the data is copied. Setting copy=False makes the array share memory with
28 the internal buffer, so any changes to the array will be reflected in the image data.
29
30 The dimensionality of the returned NumPy array varies according to the pixel format:
31 * Packed formats produce a 1-dimensional array.
32 * Single-channel formats (for example, Mono8) produce a 2-dimensional array with shape (height, width).
33 * Multi-channel formats (for example, RGB8) produce a 3-dimensional array with shape (height, width, num_channels).
34
35 @param copy: Whether to copy the data. Default is True.
36 @return The image data as a NumPy array.
37 """
38 pass
39
40 @abstractmethod
41 def to_memoryview(self) -> memoryview:
42 """!
43 @brief
44 Return a zero-copy memoryview of the image data.
45
46 The returned memoryview provides direct access to the underlying image data
47 without copying data. Modifying the memoryview will modify the image data itself.
48 Ensure that the image view and its underlying buffer remain valid before
49 accessing or using the memoryview.
50 """
51 pass
52
53 @property
54 @abstractmethod
55 def pixel_format(self) -> PixelFormat:
56 """!
57 @brief
58 Returns the pixel format of the image.
59 """
60 pass
61
62 @property
63 @abstractmethod
64 def size(self) -> Size:
65 """!
66 @brief
67 Returns the image dimensions as a Size object.
68 """
69 pass
70
71 @property
72 @abstractmethod
73 def width(self) -> int:
74 """!
75 @brief
76 Returns the width of the image in pixels.
77 """
78 pass
79
80 @property
81 @abstractmethod
82 def height(self) -> int:
83 """!
84 @brief
85 Returns the height of the image in pixels.
86 """
87 pass
88
89 @property
90 @abstractmethod
91 def metadata(self) -> Metadata:
92 """!
93 @brief
94 Returns the metadata object which can be used to retrieve or set metadata belonging to the image.
95 """
96 pass
Interface for viewing image pixel data from arbitrary sources, for example a camera buffer.
Definition iimageview.py:13
memoryview to_memoryview(self)
Return a zero-copy memoryview of the image data.
Definition iimageview.py:41
PixelFormat pixel_format(self)
Returns the pixel format of the image.
Definition iimageview.py:55
int height(self)
Returns the height of the image in pixels.
Definition iimageview.py:82
Size size(self)
Returns the image dimensions as a Size object.
Definition iimageview.py:64
np.ndarray to_numpy_array(self, bool copy=True)
Returns the image data as a NumPy array.
Definition iimageview.py:22
int width(self)
Returns the width of the image in pixels.
Definition iimageview.py:73