IDS peak ICV v1.3.0
Loading...
Searching...
No Matches
extrinsic_parameters.py
Go to the documentation of this file.
1from __future__ import annotations
2
3import ctypes
4from typing import Any, cast
5import numpy as np
6
7from ids_peak_icv import lib_loader
8from ids_peak_icv.backend.datatypes import peak_icv_extrinsic_parameters, ctypes_objects_equal
9from ids_peak_icv.backend.utils import execute_and_map_return_codes
10from ids_peak_icv.exceptions import NotPossibleException
12
13
15 """!
16 @brief
17 Class for handling extrinsic parameters related to camera calibration.
18
19 This class stores and provides access to the extrinsic parameters, which include
20 the translation, rotation, and transformation matrix.
21
22 It is a result of the camera calibration or the workspace calibration.
23
24 The extrinsic camera parameters describe the transformation between the camera's coordinate system and the world coordinate system.
25 They can be used to convert points from the world coordinate system into the camera coordinate system.
26
27 @ingroup ids_peak_icv_python_calibration
28 @since ids_peak_icv 1.1
29 """
30
31 def __init__(self, *args: Any, **kwargs: Any) -> None:
32 """!
33 @brief
34 Initializes an instance of ExtrinsicParameters.
35
36 @since ids_peak_icv 1.1
37 """
38
39 try:
40 self._parameters: peak_icv_extrinsic_parameters = kwargs["_parameters"]
41 except KeyError:
42 raise NotPossibleException("{} shall not be initialized directly".format(self.__class__.__name__))
43
44 self._transformation_matrix: np.ndarray | None = None
45
46 @property
47 def translation(self) -> PointXYZ:
48 """!
49 @brief
50 Returns the translation vector associated with the extrinsic parameters.
51
52 @return The translation as a numpy array (3D vector).
53
54 @since ids_peak_icv 1.1
55 """
56 return PointXYZ(
57 self._parameters.translation.x, self._parameters.translation.y, self._parameters.translation.z)
58
59 @property
60 def rotation(self) -> PointXYZ:
61 """!
62 @brief
63 Returns the rotation vector (Rodrigues rotation) associated with the extrinsic parameters.
64
65 @return The rotation as a numpy array (3D vector).
66
67 @since ids_peak_icv 1.1
68 """
69 return PointXYZ(self._parameters.rotation.x, self._parameters.rotation.y,
70 self._parameters.rotation.z)
71
72 @property
73 def transformation_matrix(self) -> np.ndarray:
74 """!
75 @brief
76 Returns the transformation matrix calculated from the rotation and translation vectors.
77
78 @return A 4x4 transformation matrix.
79
80 @since ids_peak_icv 1.1
81 """
82
83 if self._transformation_matrix is not None:
84 return self._transformation_matrix
85
86 self._transformation_matrix = np.zeros((4, 4), dtype=np.float32)
87
88 execute_and_map_return_codes(
89 lib_loader.dll().peak_icv_Calibration_Extrinsic_CalculateTransformationMatrix,
90 self._parameters, ctypes.sizeof(self._parameters),
91 self._transformation_matrix.ctypes.data_as(ctypes.POINTER(ctypes.c_float)))
92
93 return cast(np.ndarray, self._transformation_matrix)
94
95 def __eq__(self, other: object) -> bool:
96 if not isinstance(other, ExtrinsicParameters):
97 return False
98 return ctypes_objects_equal(self._parameters, other._parameters)
Class for handling extrinsic parameters related to camera calibration.
PointXYZ translation(self)
Returns the translation vector associated with the extrinsic parameters.
np.ndarray transformation_matrix(self)
Returns the transformation matrix calculated from the rotation and translation vectors.
None __init__(self, *Any args, **Any kwargs)
Initializes an instance of ExtrinsicParameters.
PointXYZ rotation(self)
Returns the rotation vector (Rodrigues rotation) associated with the extrinsic parameters.
Occurs when an operation cannot be performed due to logical constraints (e.g., camera calibration wit...
Definition exceptions.py:72