IDS peak ICV v1.3.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
6from ids_peak_common.datatypes.geometry.size import Size
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 Represents a three-channel image encoding cartesian coordinates (x, y, z) of a 3D point.
23
24 This image is derived from an undistorted depth map
25 that contains embedded intrinsic parameters and uses radial coordinates.
26
27 In contrast to radial coordinates,
28 which measure the direct distance from the optical center to the object,
29 cartesian coordinates project these measurements onto a uniform plane.
30
31 For example:
32 If the camera faces a flat wall,
33 only the cartesian coordinates will form a flat plane,
34 whereas radial values will increase towards the image edges.
35
36 @ingroup ids_peak_icv_python_types
37 @since ids_peak_icv 1.1
38 """
39
40 @classmethod
41 def create_from_undistorted_image(cls, undistorted_depth_map: UndistortedImage) -> XYZImage:
42 """!
43 @brief
44 Constructs a cartesian coordinate image from an undistorted depth map.
45
46 To convert a distorted depth map into the required format,
47 use the `Undistortion` class beforehand.
48
49 @supportedPixelformats{XYZImageTransformer}
50
51 @param undistorted_depth_map:
52 An image encoding radial distances to 3D points
53 that contains embedded intrinsic camera parameters.
54
55 @since ids_peak_icv 1.1
56 """
57 return cls(_undistorted_depth_map=undistorted_depth_map)
58
59 def __init__(self, *args: Any, **kwargs: Any) -> None:
60 """!
61 @brief
62 In order to create a xyz image, please refer to the class methods.
63
64 @since ids_peak_icv 1.1
65 """
66 if "_undistorted_depth_map" in kwargs:
67 image = Image.create_from_pixel_format_and_size(PixelFormat.COORD3D_ABC32F,
68 Size(kwargs["_undistorted_depth_map"].width,
69 kwargs["_undistorted_depth_map"].height))
70 super().__init__(_handle=image._handle)
71 image._handle = peak_icv_image_handle(None) # necessary to ensure only one handle delete call
72
73 execute_and_map_return_codes(lib_loader.dll().peak_icv_Transform_DepthMap_To_XYZImage,
75 kwargs["_undistorted_depth_map"].intrinsic_parameters._parameters,
76 ctypes.sizeof(
77 kwargs["_undistorted_depth_map"].intrinsic_parameters._parameters),
78 kwargs["_undistorted_depth_map"]._handle)
79 elif "_handle" in kwargs:
80 super().__init__(_handle=kwargs["_handle"])
81 else:
83 "Cannot initialize {} with __init__. Please use a classmethod.".format(self.__class__.__name__))
84
85 def transform_to_workspace(self, extrinsic_parameters: ExtrinsicParameters) -> XYZImage:
86 """!
87 @brief
88 Transforms the camera-centric coordinates into workspace coordinates.
89
90 This applies the inverse of the provided extrinsic matrix
91 to map the 3D points
92 from the camera's perspective
93 into the physical workspace.
94
95 @param extrinsic_parameters:
96 Extrinsic parameters from the workspace calibration.
97
98 @since ids_peak_icv 1.1
99 """
100 output_handle = peak_icv_image_handle()
101 image_size = peak_common_size(self._size.width, self._size.height)
102
103 execute_and_map_return_codes(lib_loader.dll().peak_icv_Image_Create,
104 ctypes.pointer(output_handle),
105 ctypes.c_int(PixelFormat.COORD3D_ABC32F.value),
106 image_size)
107 execute_and_map_return_codes(lib_loader.dll().peak_icv_Image_TransformToWorkspace,
109 extrinsic_parameters._parameters, ctypes.sizeof(extrinsic_parameters._parameters),
110 output_handle)
111
112 return XYZImage(_handle=output_handle)
Image Class for working with algorithms.
Definition image.py:40
Represents a three-channel image encoding cartesian coordinates (x, y, z) of a 3D point.
Definition xyz_image.py:19
None __init__(self, *Any args, **Any kwargs)
In order to create a xyz image, please refer to the class methods.
Definition xyz_image.py:59
XYZImage transform_to_workspace(self, ExtrinsicParameters extrinsic_parameters)
Transforms the camera-centric coordinates into workspace coordinates.
Definition xyz_image.py:85
XYZImage create_from_undistorted_image(cls, UndistortedImage undistorted_depth_map)
Constructs a cartesian coordinate image from an undistorted depth map.
Definition xyz_image.py:41
Occurs when an operation cannot be performed due to logical constraints (e.g., camera calibration wit...
Definition exceptions.py:72