3from ids_peak_common.datatypes.pixelformat
import PixelFormat
4from ids_peak_common.serialization
import IArchive
5from ids_peak_icv
import lib_loader
16 Pixel format conversion module that transforms images to a specified output pixel format.
18 The pixel format conversion module allows explicit control over the output pixel format.
20 \defaults{defaults_module_pixelformat_conversion_py|
24 @since ids_peak_icv 1.0
26 @ingroup ids_peak_icv_python_pipeline_modules
29 DEFAULT_OUTPUT_PIXEL_FORMAT: PixelFormat = PixelFormat.RGB_8
34 Initializes a pixel format conversion module
35 with \ref defaults_module_pixelformat_conversion_py "default output pixelformat".
37 @since ids_peak_icv 1.0
41 execute_and_map_return_codes(lib_loader.dll().peak_icv_Preprocessing_ImageConverter_Create,
42 ctypes.pointer(image_converter_handle))
49 if hasattr(self,
'_handle'):
50 lib_loader.dll().peak_icv_Preprocessing_ImageConverter_Destroy(self.
_handle)
56 Returns the type of the module for serialization purposes.
60 @since ids_peak_icv 1.0
62 return "PixelFormatConversion"
67 Resets the output pixel format
68 to its \ref defaults_module_pixelformat_conversion_py "default value".
70 @note The enabled state does not change when calling this function.
72 @since ids_peak_icv 1.0
80 Returns the currently set output pixel format.
82 @return The current output pixel format.
84 @since ids_peak_icv 1.0
88 @output_pixel_format.setter
92 Sets the desired output pixel format.
94 @param output_pixel_format: The desired output pixel format.
96 @since ids_peak_icv 1.0
100 def process(self, input_image: Image) -> Image:
103 Converts the input image to the configured output pixel format.
105 @note This operation disregards any specified image regions and processes the entire image.
107 @param input_image: The input image to convert.
109 @return The converted image in the specified pixel format.
111 @since ids_peak_icv 1.0
121 execute_and_map_return_codes(
122 lib_loader.dll().peak_icv_Preprocessing_ImageConverter_Convert, self.
_handle, input_image._handle,
125 ctypes.pointer(output_image_handle))
127 return Image(_handle=output_image_handle)
132 Frees unused internal buffers.
134 This module uses pre-allocated internal buffers to accelerate conversions.
135 When the image size or pixel format changes, new buffers are allocated, which may cause
136 the internal buffer pool to grow over time. This function can be used to release
137 unused buffers and reduce memory usage.
139 @note Avoid calling this function too frequently (e.g., after every resize or format change),
140 as it introduces some overhead.
142 @since ids_peak_icv 1.0
145 execute_and_map_return_codes(
146 lib_loader.dll().peak_icv_Preprocessing_ImageConverter_ReleaseBuffers, self.
_handle)
153 Serializes the object's internal state into the provided archive.
155 This function populates the given archive with all parameters required to fully represent the current state of the object.
156 It ensures that the object can be reconstructed or transmitted accurately by saving all relevant data members
157 in a consistent and structured format.
159 @param archive: The target archive that will store the serialized parameters.
161 @since ids_peak_icv 1.0
169 Restores the object's state from the provided archive.
171 This function reads and applies all necessary parameters from the given archive to reconstruct the internal state of the object.
172 It ensures that the object is restored to a valid and consistent state.
174 @param archive: The source archive containing the serialized parameters.
176 @exception CorruptedException: If Archive is malformed, misses keys or the values are invalid
177 @exception NotSupportedException: If the 'Version' entry indicates an unsupported version.
179 @note This function requires that the archive contains all expected fields as produced by a corresponding serialize() call.
181 @since ids_peak_icv 1.0
185 self.
_output_pixel_format = PixelFormat.create_from_string_value(archive.get(
"OutputPixelFormat", str))
Image Class for working with algorithms.
Base class for all pipeline modules.