CVBpy 14.1
foundation/MetricCalibrationInclinationLaserPlane
1"""
2CVBpy Example Script for AQS12 Calibration - Use Case 2.
3
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.
7
8See also use case 2 described in the CVB Metric documentation:
9https://help.commonvisionblox.com/NextGen/14.1/md_theory_of_operation_tools__metric.html#calibration_setup
10
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
16points of the AQS12
17"""
18
19import os
20import cvb
21import cvb.foundation
22
23
24def create_aqs12():
25 # list of known point coordinates of the AQS12
26 points = [
27 cvb.Point3D(20.0018, 44.9941, 15.0000),
28 cvb.Point3D(24.0018, 39.9942, 14.9994),
29 cvb.Point3D(23.9994, 24.9972, 15.0001),
30 cvb.Point3D(20.0021, 20.0035, 15.0011),
31 cvb.Point3D(15.9994, 25.0079, 15.0016),
32 cvb.Point3D(16.0000, 39.9919, 15.0010),
33 cvb.Point3D(20.0095, 59.9985, 4.9902),
34 cvb.Point3D(32.0093, 44.9958, 4.9909),
35 cvb.Point3D(32.0052, 19.9925, 4.9920),
36 cvb.Point3D(20.0021, 4.9961, 4.9939),
37 cvb.Point3D(8.0024, 19.9980, 5.0009),
38 cvb.Point3D(8.0065, 45.0009, 4.9984)]
39 return cvb.foundation.AQS12Piece(points, 0)
40
41
42def check_accuracy(residuals, desired_accuracy):
43 for point in residuals:
44 if abs(point.x) > desired_accuracy or abs(point.y) > desired_accuracy or abs(point.z) > desired_accuracy:
45 return False
46 return True
47
48
49# If you like to save intermediate and final results, turn this flag on:
50save = False
51
52print("Estimation of an affine transformation (correcting an inclined laser plane)")
53
54# load range map of the calibration target AQS12
55print("Loading range map and calibration file.")
56rangemap = cvb.Image(os.path.join(cvb.install_path(
57), "tutorial", "Metric", "Images", "RangeMapCalibrationPattern.tif"))
58
59# create (intrinsically) calibrated dense point cloud
60calibrator = cvb.Calibrator3D.load(os.path.join(
61 cvb.install_path(), "tutorial", "Metric", "Images", "SICalibration.json"))
62calibrator.range_map_ignore_value = 0
64 rangemap.planes[0], calibrator, cvb.PointCloudFlags.Float)
65
66# create AQS12 object with known reference coordinates of corner points
67aqs12 = create_aqs12()
68
69# create calibration configuration object
71config.is_homography_calculated = False
72config.is_correction_of_laser_plane_inclination_calculated = True
73
74# create segmentor (segmenting AQS12 faces on dense point cloud)
76 cvb.foundation.SegmentationMethod.KmeansClustering)
77
78# estimate calibration parameters
79print("Estimating affine transformation.")
81 cloud_intrinsic, segmentor, config)
82calibrator.correction_of_laser_plane_inclination = result[0]
83
84# check residuals
85desired_accuracy = 0.05 # mm
86if check_accuracy(result[1], desired_accuracy):
87 print("The calibration was successful and accuracy is < ",
88 desired_accuracy, "mm.")
89
90 # create calibrated cloud
91 print("Creating calibrated point cloud.")
93 rangemap.planes[0], calibrator, cvb.PointCloudFlags.Float)
94
95 # save calibrated point cloud
96 if save:
97 cloud.save("cloud.ply")
98else:
99 print("Results do not have desired accuracy. Check face segmentation and extracted AQS12 points...")
100
101 # segement AQS12 facesmap
102 print("Extracting AQ12 faces on intrinsically calibrated point cloud.")
103 facesAqs12 = segmentor.face_segmentation_from_piece(cloud_intrinsic)
104
105 # save image with segmentated faces:
106 if save:
107 facesAqs12.save("AQS12faces.bmp")
108
109 # extract AQS12 points on range map (might take some time...)
110 print("Extracting AQ12 corner points on intrinsically calibrated point cloud.")
111 aqs12points = segmentor.extract_projected_points_from_piece(
112 cloud_intrinsic)
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:612
The Common Vision Blox image.
Definition: __init__.py:2038
Multi-purpose 3D vector class.
Definition: __init__.py:4261
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:4671
Union[cvb.PointCloud, cvb.DensePointCloud, cvb.SparsePointCloud] create(cvb.ImagePlane range_map, cvb.Calibrator3D calibrator, int flags, Optional[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:4640
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:270
Common Vision Blox Foundation module for Python.
Definition: __init__.py:1
Tuple[cvb.AffineMatrix3D, List[cvb.Point3D]] calculate_correction_of_laser_plane_inclination_from_aqs12_piece(cvb.DensePointCloud cloud, cvb.foundation.AQS12DensePointCloudSegmentor segmentor, cvb.foundation.CalibrationConfiguration config, Optional[cvb.Rect] aoi)
Calculates the correction of the laser plane inclination (affine transformation) from the given dense...
Definition: __init__.py:2127
str install_path()
Directory Common Vision Blox has been installed to.
Definition: __init__.py:8257