1from __future__
import annotations
4from typing
import Union, Any
7from ids_peak_icv
import lib_loader
11 check_init_for_classes_with_classmethods_only)
15from ids_peak_ipl
import ids_peak_ipl
21 Enumeration of interpolation methods used in image transformations.
23 These methods determine how pixel values are calculated
24 when performing geometric transformations on images,
25 such as undistortion and scaling.
27 @since ids_peak_icv 1.1
28 @ingroup ids_peak_icv_python_transformations
34 Calculates the output pixel value
35 as a weighted average of the four closest input pixels.
36 Suitable for smoother results.
42 Uses the nearest input pixel value directly.
43 Faster but may introduce aliasing or blocky artifacts.
50 Represents an undistortion transformation for images.
52 Provides geometric correction
53 to remove lens distortion using intrinsic calibration parameters.
54 The parameters can be obtained using `CameraCalibration.process()`.
56 This class also supports undistorting images with binning factors
57 that differ from those used during calibration,
58 as long as the image metadata includes valid binning information.
59 The binning factor of the image to be undistorted
60 must be greater than or equal
61 to that of the calibration images.
64 If the metadata of the images to be undistorted
65 differs from the metadata used during calibration (e.g. due to different binning),
66 internal parameters may need to be reinitialized.
67 In such cases, the first call to `process()` may take longer.
69 call `set_capture_information()` beforehand
70 with matching metadata.
73 - In-place undistortion is not supported.
74 - Maximum supported image size is 32767 × 32767 pixels.
76 @since ids_peak_icv 1.1
77 @ingroup ids_peak_icv_python_transformations
80 _intrinsic_parameters: IntrinsicParameters
82 def __init__(self, *args: Any, **kwargs: Any) ->
None:
85 In order to create an Image, please refer to the classmethods ``create_from_intrinsics`` and
86 ``create_from_intrinsics_and_metadata``.
88 @since ids_peak_icv 1.1
90 self.
_handle = check_init_for_classes_with_classmethods_only(self.__class__.__name__,
91 peak_icv_undistortion_handle,
95 self.
_handle = kwargs[
"_handle"]
103 @param intrinsic_parameters: Intrinsic parameters derived from a camera calibration.
106 @since ids_peak_icv 1.1
111 execute_and_map_return_codes(lib_loader.dll().peak_icv_Transform_Undistortion_Create,
121 metadata: Metadata) -> Undistortion:
125 @param intrinsic_parameters: Intrinsic parameters derived from a camera calibration.
126 @param metadata: Metadata of an image which contains information about the image capture settings.
128 @since ids_peak_icv 1.1
133 c_capture_information = metadata_to_capture_information(metadata)
134 execute_and_map_return_codes(
135 lib_loader.dll().peak_icv_Transform_Undistortion_Create_With_Image_CaptureInformation,
139 c_capture_information, ctypes.sizeof(c_capture_information),
147 Destroys the undistortion object and releases any associated resources.
149 @since ids_peak_icv 1.1
151 if hasattr(self,
'_handle'):
152 lib_loader.dll().peak_icv_Image_Destroy(self.
_handle)
154 def process(self, image: Union[Image, ids_peak_ipl.Image]) -> UndistortedImage:
157 Applies undistortion to the specified image.
159 This function undistorts the image
160 and returns an `UndistortedImage` that includes updated intrinsic parameters.
162 The returned image has the same size and pixel format as the input image.
165 If the input image specifies a region, that region is also undistorted.
166 When no region is specified (i.e., the full image is used), the output will also
167 represent the full image.
170 The image to be undistorted.
172 @supportedPixelformats{Undistortion}
175 An undistorted image with updated intrinsic parameters.
177 @exception NotPossibleException:
178 The image binning factor is too small
179 for the undistortion configuration.
180 @exception MismatchException:
181 The image size or capture information
182 does not match the undistortion configuration.
184 @since ids_peak_icv 1.1
186 _image = _check_and_get_icv_image(image)
188 output_image = Image.create_from_pixel_format_and_size(_image._pixel_format,
189 Size(_image.width, _image.height))
191 execute_and_map_return_codes(lib_loader.dll().peak_icv_Transform_Undistortion_Process,
194 output_image._handle)
204 The current @ref Interpolation "interpolation method" used by the undistortion.
206 @since ids_peak_icv 1.1
208 interpolation = ctypes.c_size_t()
209 execute_and_map_return_codes(lib_loader.dll().peak_icv_Transform_Undistortion_GetInterpolation,
211 ctypes.pointer(interpolation))
215 @interpolation.setter
219 Sets the @ref Interpolation "interpolation method" used for undistortion.
221 @param interpolation:
222 @ref Interpolation "Interpolation method" to use.
224 @since ids_peak_icv 1.1
226 execute_and_map_return_codes(lib_loader.dll().peak_icv_Transform_Undistortion_SetInterpolation,
228 ctypes.c_size_t(interpolation.value))
A size consists of width and height where width and height have to be greater than or equal to zero.
Class for intrinsic parameters.
The UndistortedImage class is a class derived from the Image class.