2CVBpy Example Script for AQS12 Calibration - Use Case 2.
4This example shows how to calibrate range maps acquired by a compact 3D
5sensor where the intrinsic calibration parameters are given, but the
6laser plane is not exactly vertical to the direction of movement.
8See also use case 2 described in the CVB Metric documentation:
9https://help.commonvisionblox.com/NextGen/15.0/md_theory_of_operation_tools__metric.html#calibration_setup
11This example program estimates an affine transformation.
12The affine transformation:
13- corrects errors induced by an incline laser plane
14- corrects scaling in x, y, z
15- moves the point cloud to the coordinate system given by the reference
25def print_trafo(trafo: cvb.AffineMatrix3D) ->
None:
26 print(
"Estimated transformation:")
28 print(f
"[{trafo.translation.x}, {trafo.translation.y}, "
29 f
"{trafo.translation.z}]")
30 print(
"Transformation matrix:")
31 print(f
"[[{trafo.matrix.at(0, 0)}, "
32 f
"{trafo.matrix.at(0, 1)}, "
33 f
"{trafo.matrix.at(0, 2)}],")
34 print(f
"[{trafo.matrix.at(1, 0)}, "
35 f
"{trafo.matrix.at(1, 1)}, "
36 f
"{trafo.matrix.at(1, 2)}],")
37 print(f
"[{trafo.matrix.at(2, 0)}, "
38 f
"{trafo.matrix.at(2, 1)}, "
39 f
"{trafo.matrix.at(2, 2)}]]")
42def print_trafo_parameters(atp: cvb.AffineTransformationParameters) ->
None:
43 print(
"Rotation angles about X, Y, Z axis in degrees:")
44 print(f
"{atp.rotation_angles.x}, {atp.rotation_angles.y}, "
45 f
"{atp.rotation_angles.z}")
46 print(
"Shear Syx, Syz:")
47 print(f
"{atp.s_yx}, {atp.s_yz}")
48 print(
"Inclination of laser plane about X, Z axis in degrees:")
49 print(f
"{atp.inclination_x}, {atp.inclination_z}")
50 print(
"Scale in X, Y, Z:")
51 print(f
"{atp.scale.x}, {atp.scale.y}, {atp.scale.z}")
54def print_point_3d_list(points: list[
cvb.Point3D]) ->
None:
57 data_list.append(f
"[{p.x}, {p.y}, {p.z}]")
59 print(f
"[{delimiter.join(data_list)}]")
62def print_residuals(points: list[
cvb.Point3D]) ->
None:
64 print_point_3d_list(points)
67def print_aqs12_points(points: list[
cvb.Point3D]) ->
None:
68 print(
"AQS12 points:")
69 print_point_3d_list(points)
90def check_accuracy(residuals, desired_accuracy):
91 for point
in residuals:
92 if (abs(point.x) > desired_accuracy
or
93 abs(point.y) > desired_accuracy
or
94 abs(point.z) > desired_accuracy):
102print(
"Estimation of an affine transformation (correcting an inclined laser "
106print(
"Loading range map and calibration file.")
108 "tutorial",
"Metric",
"Images",
109 "RangeMapCalibrationPattern.tif")
113print(f
"Range map loaded with size of {range_map.width} x {range_map.height} "
114 f
"from {range_map_file}.")
117aqs12 = create_aqs12()
119config.is_homography_calculated =
False
123 "tutorial",
"Metric",
"Images",
124 "SICalibration.json")
126calibrator.range_map_ignore_value = 0
128 range_map.planes[0], calibrator,
129 cvb.PointCloudFlags.Float)
131print(
"Dense point cloud created from range map and calibration file "
132 f
"with {cloud_intrinsic.num_points} points.")
135aqs12 = create_aqs12()
139 cvb.foundation.SegmentationMethod.KmeansClustering)
142print(
"Estimating affine transformation.")
143transformation_, residuals_, transformation_parameters_ = \
145 cloud_intrinsic, segmentor, config)
147calibrator.correction_of_laser_plane_inclination = \
148 transformation_, transformation_parameters_
152 print_trafo(transformation_)
154if transformation_parameters_:
155 print_trafo_parameters(transformation_parameters_)
158desired_accuracy_ = 0.05
160 print_residuals(residuals_)
161 if check_accuracy(residuals_, desired_accuracy_):
162 print(
"The calibration was successful and accuracy is < "
163 f
"{desired_accuracy_} mm.")
166 print(
"Creating calibrated point cloud.")
168 range_map.planes[0], calibrator,
169 cvb.PointCloudFlags.Float | cvb.PointCloudFlags.XYZConfidence)
173 calibrator_cloud.save(
"cloud.ply")
176 "Results do not have desired accuracy. Check face segmentation and "
177 "extracted AQS12 points...")
180 print(
"Extracting AQ12 faces on intrinsically calibrated point cloud.")
181 faces_aqs12 = segmentor.face_segmentation_from_piece(cloud_intrinsic)
185 faces_aqs12.save(
"AQS12faces.bmp")
188 print(
"Extracting AQ12 corner points on intrinsically calibrated "
190 points_aqs12 = segmentor.extract_projected_points_from_piece(
192 print_aqs12_points(points_aqs12)
Union[cvb.Calibrator3DAT, cvb.LaserPlaneHomographyCalibrator3D, cvb.LaserPlaneZigZagCalibrator3D, cvb.FactorsCalibrator3D, cvb.MatrixCalibrator3D, cvb.PinholeCameraCalibrator3D] load(str file_name)
Loads a 3D calibration from file.
Definition: __init__.py:671
The Common Vision Blox image.
Definition: __init__.py:2097
Multi-purpose 3D vector class.
Definition: __init__.py:4322
Union[cvb.PointCloud, cvb.DensePointCloud, cvb.SparsePointCloud] create(cvb.ImagePlane range_map, cvb.Calibrator3D calibrator, int flags, Union[Type[cvb.PointCloud|cvb.DensePointCloud|cvb.SparsePointCloud]] point_cloud_type=DensePointCloud)
Creates a new Cartesian 3D point cloud from the given 2.5D range map image.
Definition: __init__.py:4701
cvb.DensePointCloud create_dense(cvb.ImagePlane range_map, cvb.Calibrator3D calibrator, int flags)
Creates a new dense Cartesian 3D point cloud from the given 2.5D range map image.
Definition: __init__.py:4732
cvb.foundation.AQS12DensePointCloudSegmentor create(int method)
Creates an AQS12 segmentor for dense point clouds based on given segmentation method.
Definition: __init__.py:18
Object to collect all input parameters for the AQS12 calibration piece.
Definition: __init__.py:76
cvb.foundation.CalibrationConfiguration create(cvb.foundation.AQS12Piece aqs12)
Creates a calibration configuration object.
Definition: __init__.py:272
Common Vision Blox Foundation module for Python.
Definition: __init__.py:1
Tuple[cvb.AffineMatrix3D, Optional[List[cvb.Point3D]], Optional[cvb.AffineTransformationParameters]] calculate_correction_of_laser_plane_inclination_from_aqs12_piece(cvb.DensePointCloud cloud, cvb.foundation.AQS12DensePointCloudSegmentor segmentor, cvb.foundation.CalibrationConfiguration config, Optional[cvb.Rect] aoi=None)
Calculates an extrinsic calibration and the correction for the laser plane inclination (affine transf...
Definition: __init__.py:2212
str install_path()
Directory Common Vision Blox has been installed to.
Definition: __init__.py:8318