3from ids_peak_common
import PixelFormat, NotSupportedException
4from ids_peak_common.serialization
import IArchive
5from ids_peak_icv
import lib_loader
17 Transformation is an image pipeline module that provides mirror and rotation functionality.
19 Default configuration:
23 @since ids_peak_icv 1.0
24 @ingroup ids_peak_icv_python_pipeline_modules
27 DEFAULT_MIRROR_LEFT_RIGHT: bool =
False
28 DEFAULT_MIRROR_UP_DOWN: bool =
False
29 DEFAULT_ROTATION_ANGLE: Rotation = Rotation.NO_ROTATION
34 Creates a transformation module
36 @since ids_peak_icv 1.0
49 Returns the type of the module for serialization purposes.
53 @since ids_peak_icv 1.0
55 return self.__class__.__name__
60 Processes the input image and returns a mirrored and/or rotated copy based on current settings.
62 @supportedPixelformats{ImageTransformation}
64 @note When processing images with a Bayer pattern, the result may have a different pixel format,
65 though the bit depth remains unchanged.
67 @note This operation disregards any specified image regions and processes the entire image.
69 @param input: The input image to be processed.
71 @return A new image object that is the transformed result of the input.
73 @exception NotSupportedException: If the image has any other than the supported pixel formats.
75 @since ids_peak_icv 1.0
79 if not mirror_needs_processing
and not rotation_needs_processing:
82 output_pixelformat = ctypes.c_uint32()
87 execute_and_map_return_codes(
88 lib_loader.dll().peak_icv_Preprocessing_Transformation_GetOutputPixelFormat,
89 input.pixel_format.value,
90 transformation_parameters,
91 ctypes.pointer(output_pixelformat),
96 output_size = input.size.transposed()
if transpose
else input.size
97 output_image = Image.create_from_pixel_format_and_size(PixelFormat(output_pixelformat.value), output_size)
99 execute_and_map_return_codes(
100 lib_loader.dll().peak_icv_Preprocessing_Transformation_Process,
102 transformation_parameters,
103 output_image._handle,
111 Resets all settings to their defaults.
113 Default configuration:
114 - mirror_left_right = False
115 - mirror_up_down = False
116 - rotation_angle = Rotation.NO_ROTATION
118 @note The enabled state does not change when calling this function.
120 @since ids_peak_icv 1.0
130 Gets the current left-right mirroring setting.
132 @return True if left-right mirroring is enabled so that left and right will be flipped.
134 @since ids_peak_icv 1.0
138 @mirror_left_right.setter
142 Sets whether the image should be mirrored left-right.
144 @param value: If true, the image will be mirrored along the vertical axis.
146 @since ids_peak_icv 1.0
154 Gets the current up-down mirroring setting.
156 @return True if up-down mirroring is enabled so that up and down will be flipped.
158 @since ids_peak_icv 1.0
162 @mirror_up_down.setter
166 Sets whether the image should be mirrored up-down.
168 @param value: If true, the image will be mirrored along the horizontal axis.
170 @since ids_peak_icv 1.0
178 Gets the current rotation angle.
180 @return The currently configured rotation angle.
182 @since ids_peak_icv 1.0
186 @rotation_angle.setter
190 Sets the desired rotation angle.
192 @param value: The rotation angle to apply (see RotationAngle enum).
194 @since ids_peak_icv 1.0
202 Gets whether this module is enabled.
204 When disabled, :func:`process` returns the input image unchanged.
206 @return True if the module is enabled, False otherwise.
208 @since ids_peak_icv 1.0
216 Enables or disables the module.
218 When disabled, :func:`process` returns the input image unchanged.
220 @param enabled: True to enable, False to disable.
222 @since ids_peak_icv 1.0
230 Serializes the object's internal state into an archive.
232 This function populates an archive with all parameters required to fully represent the current state of the object.
233 It ensures that the object can be reconstructed or transmitted accurately by saving all relevant data members
234 in a consistent and structured format.
236 @param archive: The target archive that will store the serialized parameters.
238 @since ids_peak_icv 1.0
246 archive.set(
"Mirror", mirror_archive)
251 archive.set(
"Rotation", rotation_archive)
256 Restores the object's state from the provided archive.
258 This function reads and applies all necessary parameters from the given ``archive`` to reconstruct the internal
260 It ensures that the object is restored to a valid and consistent state.
262 @note This function requires that the archive contains all expected fields as produced by a
263 corresponding serialize call.
265 @param archive: The source archive containing the serialized parameters.
267 @exception CorruptedException: If Archive is malformed, misses keys or the values are invalid
268 @exception NotSupportedException: If the 'Version' entry indicates an unsupported version or if the rotation angle
269 is not transformable into RotationAngle.
271 @since ids_peak_icv 1.0
275 rotation_archive = archive.get_archive(
"Rotation")
278 mirror_archive = archive.get_archive(
"Mirror")
285 except ValueError
as e:
286 raise NotSupportedException(str(e))
Base class for all pipeline modules.
int version(self)
Return the module version.
None _validate_version(self, IArchive archive)
Represents discrete rotation angles in degrees for use in rotation operations.
A key-value store with type checking, based on a dict.