IDS peak ICV v1.2.0
Loading...
Searching...
No Matches
xyz_image.py
Go to the documentation of this file.
1from __future__ import annotations
2
3import ctypes
4from typing import Any, TYPE_CHECKING
5
7from ids_peak_common.datatypes.pixelformat import PixelFormat
8from ids_peak_icv import lib_loader
9from ids_peak_icv.backend.datatypes import peak_icv_image_handle, peak_common_size
10from ids_peak_icv.backend.utils import execute_and_map_return_codes
11from ids_peak_icv.datatypes.image import Image
12from ids_peak_icv.exceptions import NotPossibleException
13
14if TYPE_CHECKING:
15 from ids_peak_icv.datatypes.undistorted_image import UndistortedImage
16 from ids_peak_icv.calibration.extrinsic_parameters import ExtrinsicParameters
17
18
20 """!
21 @brief
22 Transforms a depth map with radial coordinates to a three-channel image with cartesian coordinates.
23
24 This class converts an undistorted depth map with radial coordinates to a three-channel image with cartesian coordinates.
25 Radial coordinates represent the distance directly from the optical center to the reflected object, resulting in
26 values that appear more distant as you move outwards from the image center. In contrast, Cartesian coordinates
27 interpret the optical center as a plane, resulting in straight lines from the camera to the reflected object. For
28 example, if the camera is placed in front of a flat wall, only the Cartesian values will show a flat plane.
29
30 @ingroup ids_peak_icv_python_types
31 @since ids_peak_icv 1.1
32 """
33
34 @classmethod
35 def create_from_undistorted_image(cls, undistorted_depth_map: UndistortedImage) -> XYZImage:
36 """!
37 @brief
38 Creates an instance of XYZImage using an undistorted depth map image and intrinsic parameters
39
40 @param undistorted_depth_map: Undistorted depth map with radial coordinates.
41
42 @since ids_peak_icv 1.1
43 """
44 return cls(_undistorted_depth_map=undistorted_depth_map)
45
46 def __init__(self, *args: Any, **kwargs: Any) -> None:
47 """!
48 @brief
49 In order to create a point cloud, please refer to the class methods.
50
51 @since ids_peak_icv 1.1
52 """
53 if "_undistorted_depth_map" in kwargs:
54 image = Image.create_from_pixel_format_and_size(PixelFormat.COORD3D_ABC32F,
55 Size(kwargs["_undistorted_depth_map"].width,
56 kwargs["_undistorted_depth_map"].height))
57 super().__init__(_handle=image._handle)
58 image._handle = peak_icv_image_handle(None) # necessary to ensure only one handle delete call
59
60 execute_and_map_return_codes(lib_loader.dll().peak_icv_Transform_DepthMap_To_XYZImage,
62 kwargs["_undistorted_depth_map"].intrinsic_parameters._parameters,
63 ctypes.sizeof(
64 kwargs["_undistorted_depth_map"].intrinsic_parameters._parameters),
65 kwargs["_undistorted_depth_map"]._handle)
66 elif "_handle" in kwargs:
67 super().__init__(_handle=kwargs["_handle"])
68 else:
70 "Cannot initialize {} with __init__. Please use a classmethod.".format(self.__class__.__name__))
71
72 def transform_to_workspace(self, extrinsic_parameters: ExtrinsicParameters) -> XYZImage:
73 """!
74 @brief
75 Transforms the image to workspace coordinates using the specified extrinsic parameters.
76
77 The transformation uses the inverse of the extrinsic matrix
78 to convert from camera to workspace coordinate system.
79
80 @param extrinsic_parameters: Extrinsic parameters from the workspace calibration.
81
82 @since ids_peak_icv 1.1
83 """
84 output_handle = peak_icv_image_handle()
85 image_size = peak_common_size(self._size.width, self._size.height)
86
87 execute_and_map_return_codes(lib_loader.dll().peak_icv_Image_Create,
88 ctypes.pointer(output_handle),
89 ctypes.c_int(PixelFormat.COORD3D_ABC32F.value),
90 image_size)
91 execute_and_map_return_codes(lib_loader.dll().peak_icv_Image_TransformToWorkspace,
93 extrinsic_parameters._parameters, ctypes.sizeof(extrinsic_parameters._parameters),
94 output_handle)
95
96 return XYZImage(_handle=output_handle)
A size consists of width and height where width and height have to be greater than or equal to zero.
Definition size.py:9
Image Class for working with algorithms.
Definition image.py:40
Transforms a depth map with radial coordinates to a three-channel image with cartesian coordinates.
Definition xyz_image.py:19
None __init__(self, *Any args, **Any kwargs)
In order to create a point cloud, please refer to the class methods.
Definition xyz_image.py:46
XYZImage transform_to_workspace(self, ExtrinsicParameters extrinsic_parameters)
Transforms the image to workspace coordinates using the specified extrinsic parameters.
Definition xyz_image.py:72
XYZImage create_from_undistorted_image(cls, UndistortedImage undistorted_depth_map)
Creates an instance of XYZImage using an undistorted depth map image and intrinsic parameters.
Definition xyz_image.py:35
Thrown when an operation cannot be performed due to logical constraints.
Definition exceptions.py:85