1from __future__
import annotations
4from typing
import TypeAlias, Any
7import numpy.typing
as npt
9from ids_peak_icv
import lib_loader
12 peak_icv_calibration_parameters)
14 check_init_for_classes_with_classmethods_only)
19CalibrationViewArray: TypeAlias = npt.NDArray[np.object_]
25 Class for holding the results of a camera calibration.
27 The CalibrationResult stores intrinsic and extrinsic parameters as well as the
28 mean reprojection error calculated by CameraCalibration.process().
30 @ingroup ids_peak_icv_python_calibration
31 @since ids_peak_icv 1.1
38 Creates an instance of CalibrationResult by loading the calibration result from a file.
40 @param file_path: An existing file path to a JSON file containing the calibration result.
41 @return A new instance of CalibrationResult
43 @exception IOException: If the given file_path does not exist, or the permissions are not sufficient
45 @exception CorruptedException: If the file content is corrupted.
47 @since ids_peak_icv 1.1
49 c_file_path = file_path.encode(
'utf-8')
53 execute_and_map_return_codes(lib_loader.dll().peak_icv_Calibration_Result_CreateFromFile,
54 ctypes.pointer(handle),
55 ctypes.c_char_p(c_file_path),
56 ctypes.c_size_t(len(c_file_path)))
57 return cls(_handle=handle)
62 execute_and_map_return_codes(lib_loader.dll().peak_icv_Calibration_Result_Create,
63 ctypes.pointer(handle))
67 def __init__(self, *args: Any, **kwargs: Any) ->
None:
70 In order to create a CalibrationResult, please refer to the classmethods.
72 @since ids_peak_icv 1.1
74 self.
_handle = check_init_for_classes_with_classmethods_only(self.__class__.__name__,
75 peak_icv_calibration_result_handle,
77 self.
_views: np.ndarray |
None =
None
80 if hasattr(self,
'_handle'):
81 lib_loader.dll().peak_icv_Calibration_Result_Destroy(self.
_handle)
87 Provides the mean reprojection error from calibration result.
89 The mean reprojection error is the root-mean-square of distances between the marker points extracted from the
90 calibration images and the projected world points from the used calibration plate.
92 @since ids_peak_icv 1.1
94 c_mean_reprojection_error = ctypes.c_double()
96 execute_and_map_return_codes(lib_loader.dll().peak_icv_Calibration_Result_GetMeanReprojectionError,
97 self.
_handle, ctypes.pointer(c_mean_reprojection_error))
98 return c_mean_reprojection_error.value
101 def views(self) -> CalibrationViewArray:
104 Provides a list of ``CalibrationView``.
106 The order in which the CalibrationViews are provided, is equivalent to the order of images provided to
107 CameraCalibration.CameraCalibration.Process.
109 @since ids_peak_icv 1.1
111 if self.
_views is not None:
114 view_count = ctypes.c_size_t()
115 execute_and_map_return_codes(lib_loader.dll().peak_icv_Calibration_Result_GetCalibrationViews_GetCount,
116 self.
_handle, ctypes.pointer(view_count))
118 if view_count.value == 0:
121 self.
_views = np.array([])
125 view_handles = create_array(peak_icv_calibration_view_handle, view_count.value)
126 execute_and_map_return_codes(lib_loader.dll().peak_icv_Calibration_View_Array_Create,
127 view_handles, view_count)
129 execute_and_map_return_codes(lib_loader.dll().peak_icv_Calibration_Result_GetCalibrationViews,
130 self.
_handle, view_handles, view_count)
132 except ICVException
as e:
133 lib_loader.dll().peak_icv_Calibration_View_Array_Destroy(view_handles, view_count)
139 def save(self, file_path: str) ->
None:
142 Saves calibration result to a JSON file for later use.
144 @param file_path: An existing file path to save calibration result.
146 @exception IOException: If the specified file path is invalid, you lack the necessary permissions, or
147 the file already exists.
149 @since ids_peak_icv 1.1
151 c_file_path = file_path.encode(
'utf-8')
152 execute_and_map_return_codes(lib_loader.dll().peak_icv_Calibration_Result_SaveToFile,
154 ctypes.c_char_p(c_file_path))
157 def calibration_parameters(self) -> CalibrationParameters:
160 Provides the @p CalibrationParameters that contain the necessary information to use the camera calibration.
162 @return An instance of CalibrationParameters
164 @since ids_peak_icv 1.1
167 execute_and_map_return_codes(lib_loader.dll().peak_icv_Calibration_Result_ToParameters,
168 self.
_handle, ctypes.pointer(parameters), ctypes.sizeof(parameters))
Represents the calibration parameters, which include intrinsic and extrinsic parameters.
Class for holding the results of a camera calibration.
None __init__(self, *Any args, **Any kwargs)
In order to create a CalibrationResult, please refer to the classmethods.
None save(self, str file_path)
Saves calibration result to a JSON file for later use.
CalibrationResult _create_empty(cls)
CalibrationResult create_from_file(cls, str file_path)
Creates an instance of CalibrationResult by loading the calibration result from a file.
CalibrationViewArray views(self)
Provides a list of CalibrationView.
float mean_reprojection_error(self)
Provides the mean reprojection error from calibration result.
Class for holding the extrinsic result for one image of a camera calibration and also the reprojectio...