3from ids_peak_common
import PixelFormat, NotSupportedException
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.
52 @since ids_peak_icv 1.0
54 return self.__class__.__name__
59 Processes the input image and returns a mirrored and/or rotated copy based on current settings.
61 @supportedPixelformats{ImageTransformation}
63 @note When processing images with a Bayer pattern, the result may have a different pixel format,
64 though the bit depth remains unchanged.
66 @note This operation disregards any specified image regions and processes the entire image.
68 @param input: The input image to be processed.
70 @return A new image object that is the transformed result of the input.
72 @exception NotSupportedException: If the image has any other than the supported pixel formats.
74 @since ids_peak_icv 1.0
78 if not mirror_needs_processing
and not rotation_needs_processing:
81 output_pixelformat = ctypes.c_uint32()
86 execute_and_map_return_codes(
87 lib_loader.dll().peak_icv_Preprocessing_Transformation_GetOutputPixelFormat,
88 input.pixel_format.value,
89 transformation_parameters,
90 ctypes.pointer(output_pixelformat),
95 output_size = input.size.transposed()
if transpose
else input.size
96 output_image = Image.create_from_pixel_format_and_size(PixelFormat(output_pixelformat.value), output_size)
98 execute_and_map_return_codes(
99 lib_loader.dll().peak_icv_Preprocessing_Transformation_Process,
101 transformation_parameters,
102 output_image._handle,
110 Resets all settings to the default values:
114 @since ids_peak_icv 1.0
124 Gets the current left-right mirroring setting.
126 @return True if left-right mirroring is enabled so that left and right will be flipped.
128 @since ids_peak_icv 1.0
132 @mirror_left_right.setter
136 Sets whether the image should be mirrored left-right.
138 @param value: If true, the image will be mirrored along the vertical axis.
140 @since ids_peak_icv 1.0
148 Gets the current up-down mirroring setting.
150 @return True if up-down mirroring is enabled so that up and down will be flipped.
152 @since ids_peak_icv 1.0
156 @mirror_up_down.setter
160 Sets whether the image should be mirrored up-down.
162 @param value: If true, the image will be mirrored along the horizontal axis.
164 @since ids_peak_icv 1.0
172 Gets the current rotation angle.
174 @return The currently configured rotation angle.
176 @since ids_peak_icv 1.0
180 @rotation_angle.setter
184 Sets the desired rotation angle.
186 @param value: The rotation angle to apply (see RotationAngle enum).
188 @since ids_peak_icv 1.0
196 Checks if the module is currently enabled.
198 @return True if the module is enabled, false otherwise.
200 @since ids_peak_icv 1.0
208 Sets the enabled state of this module.
210 @param value: If true, the module is enabled; otherwise, it is disabled.
212 @since ids_peak_icv 1.0
220 Serializes the object's internal state into an archive.
222 This function populates an archive with all parameters required to fully represent the current state of the object.
223 It ensures that the object can be reconstructed or transmitted accurately by saving all relevant data members
224 in a consistent and structured format.
226 @return The serialized module's internal state.
228 @since ids_peak_icv 1.0
236 archive.set(
"Mirror", mirror_archive)
241 archive.set(
"Rotation", rotation_archive)
246 Restores the object's state from the provided archive.
248 This function reads and applies all necessary parameters from the given ``archive`` to reconstruct the internal
250 It ensures that the object is restored to a valid and consistent state.
252 @note This function requires that the archive contains all expected fields as produced by a
253 corresponding serialize call.
255 @param archive: The source archive containing the serialized parameters.
257 @exception CorruptedException: If Archive is malformed, misses keys or the values are invalid
258 @exception NotSupportedException: If the 'Version' entry indicates an unsupported version or if the rotation angle
259 is not transformable into RotationAngle.
261 @since ids_peak_icv 1.0
265 rotation_archive = archive.get_archive(
"Rotation")
268 mirror_archive = archive.get_archive(
"Mirror")
275 except ValueError
as e:
Thrown when an unsupported operation or feature is used.
Represents discrete rotation angles in degrees for use in rotation operations.
Base class for all pipeline modules.
int version(self)
Return the module version.
None _validate_version(self, IArchive archive)
A simple key-value store with type checking, similar to a dict.