CVBpy 14.1
foundation/MetricCalibration
1"""
2CVBpy Example Script for AQS12 Calibration - Use Case 1.
3
4This example shows how to calibrate range maps acquired by a modular laser
5triangulation setup (camera and laser separated), where the intrinsic calibration
6parameters are not given.
7
8See also use case 1 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 homography and 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 homography and affine transformation (correcting an inclined laser plane)")
53
54# load range map of the calibration target AQS12
55print("Loading range map.")
56rangemap = cvb.Image(os.path.join(cvb.install_path(
57), "tutorial", "Metric", "Images", "RangeMapCalibrationPattern.tif"))
58
59# create AQS12 object with known reference coordinates of corner points
60aqs12 = create_aqs12()
61
62# create calibration configuration object
64config.is_homography_calculated = True
65config.is_correction_of_laser_plane_inclination_calculated = True
66
67# create segmentor (segmenting AQS12 faces on range map)
68print("Estimating homography and affine matrix.")
70 cvb.foundation.SegmentationMethod.KmeansClustering)
71
72# estimate calibration parameters
74 rangemap.planes[0], segmentor, config)
75
76# check residuals
77desired_accuracy = 0.05 # mm
78if check_accuracy(result[1], desired_accuracy):
79 print("The calibration was successful and accuracy is < ",
80 desired_accuracy, "mm.")
81
82 # create calibrated cloud
83 print("Creating calibrated point cloud.")
85 rangemap.planes[0], result[0], cvb.PointCloudFlags.Float)
86
87 # save calibrated point cloud
88 if save:
89 cloud.save("cloud.ply")
90else:
91 print("Results do not have desired accuracy. Check face segmentation and extracted AQS12 points...")
92
93 # segement AQS12 faces
94 print("Segmenting AQ12 faces on range map.")
95 facesAqs12 = segmentor.face_segmentation_from_piece(rangemap.planes[0])
96
97 # save image with segmentated faces:
98 if save:
99 facesAqs12.save("AQS12faces.bmp")
100
101 # extract AQS12 points on range map (might take some time...)
102 print("Extracting AQ12 corner points on range map.")
103 aqs12points = segmentor.extract_projected_points_from_piece(
104 rangemap.planes[0])
The Common Vision Blox image.
Definition: __init__.py:2038
Multi-purpose 3D vector class.
Definition: __init__.py:4261
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
Object to collect all input parameters for the AQS12 calibration piece.
Definition: __init__.py:76
cvb.foundation.AQS12RangeMapSegmentor create(int method)
Creates an AQS12 segmentor for range maps based on given segmentation method.
Definition: __init__.py:101
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.LaserPlaneHomographyCalibrator3D, List[cvb.Point3D]] create_calibrator_from_aqs12_piece(cvb.ImagePlane image_plane, cvb.foundation.AQS12RangeMapSegmentor segmentor, cvb.foundation.CalibrationConfiguration config, Optional[cvb.Rect] aoi)
Calculates intrinsic calibration parameters from the given range map image of an AQS12 calibration pi...
Definition: __init__.py:2851
str install_path()
Directory Common Vision Blox has been installed to.
Definition: __init__.py:8257