CVBpy 15.0
cvb/CreateAndAccessCalibratedPointCloud
1"""
2CVBpy Example Script
3
41. Creates a calibrated point cloud from a range map aquired
5by a laser triangulation setup (for further information see
6<a htref="https://help.commonvisionblox.com/NextGen/15.0/md_theory_of_operation_tools__metric.html">here</a>).
72. Converts it to a numpy array without copying.
83. Modifies point cloud values through numpy.
94. Saves the point cloud.
10
11Requires: numpy
12"""
13
14import os
15import cvb
16
17# load range map
18print("Loading range map and calibration file.")
19rangemap = cvb.Image(os.path.join(cvb.install_path(
20), "tutorial", "Metric", "Images", "RangeMapCalibrationPattern.tif"))
21
22# load calibration file
23calibrator = cvb.Calibrator3D.load(os.path.join(
24 cvb.install_path(), "tutorial", "Metric", "Images", "SICalibration.json"))
25
26# create calibrated (dense) point cloud
27print("Creating calibrated point cloud.")
29 rangemap.planes[0], calibrator, cvb.PointCloudFlags.Float)
30
31# create a numpy array from point cloud
32# copy=False is default, but just a request
33np_array = cvb.as_array(cloud, copy=False)
34
35if np_array.flags["OWNDATA"]:
36 # use copy=True or
37 # np_array = cvb.to_array(cloud)
38 # or simply throw an error:
39 raise RuntimeError("cannot map to numpy array")
40
41# point cloud access
42print("Modifying point cloud data via numpy array.")
43# E.g. cut height values (z) below 0.
44for i in range(np_array.shape[0]):
45 for j in range(np_array.shape[1]):
46 if np_array[i, j, 2] < 0: # z value smaller zero
47 np_array[i, j, 2] = 0
48 # set confidence to false (note, that usually
49 np_array[i, j, 3] = 0
50 # only dense point clouds have the confidence layer!)
51
52# save point cloud
53print("Saving: ./calibrated_cloud.ply")
54cloud.save("calibrated_cloud.ply")
55
56# Attention: If you use cvb.as_array with copy=False, ensure, that your cloud object
57# lives as long as your numpy array!
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
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
str install_path()
Directory Common Vision Blox has been installed to.
Definition: __init__.py:8318
numpy.array as_array(Any buffer, bool copy=False)
Maps a cvb object to a numpy array.
Definition: __init__.py:8068