CVBpy 15.0
All Classes Namespaces Functions Variables Enumerations Enumerator Properties Modules Pages
cvb/CreateAndAccessCalibratedPointCloud
1# @brief Example for creating a calibrated point cloud from
2# a range map and accessing point cloud values.
3
4"""
5CVBpy Example Script
6
71. Creates a calibrated point cloud from a range map aquired
8by a laser triangulation setup (for further information see
9<a htref="https://help.commonvisionblox.com/NextGen/15.0/md_theory_of_operation_tools__metric.html">here</a>).
102. Converts it to a numpy array without copying.
113. Modifies point cloud values through numpy.
124. Saves the point cloud.
13
14Requires: numpy
15"""
16
17import os
18import cvb
19
20# load range map
21print("Loading range map and calibration file.")
22rangemap = cvb.Image(os.path.join(cvb.install_path(
23), "tutorial", "Metric", "Images", "RangeMapCalibrationPattern.tif"))
24
25# load calibration file
26calibrator = cvb.Calibrator3D.load(os.path.join(
27 cvb.install_path(), "tutorial", "Metric", "Images", "SICalibration.json"))
28
29# create calibrated (dense) point cloud
30print("Creating calibrated point cloud.")
32 rangemap.planes[0], calibrator, cvb.PointCloudFlags.Float)
33
34# create a numpy array from point cloud
35# copy=False is default, but just a request
36np_array = cvb.as_array(cloud, copy=False)
37
38if np_array.flags["OWNDATA"]:
39 # use copy=True or
40 # np_array = cvb.to_array(cloud)
41 # or simply throw an error:
42 raise RuntimeError("cannot map to numpy array")
43
44# point cloud access
45print("Modifying point cloud data via numpy array.")
46# E.g. cut height values (z) below 0.
47for i in range(np_array.shape[0]):
48 for j in range(np_array.shape[1]):
49 if np_array[i, j, 2] < 0: # z value smaller zero
50 np_array[i, j, 2] = 0
51 # set confidence to false (note, that usually
52 np_array[i, j, 3] = 0
53 # only dense point clouds have the confidence layer!)
54
55# save point cloud
56print("Saving: ./calibrated_cloud.ply")
57cloud.save("calibrated_cloud.ply")
58
59# Attention: If you use cvb.as_array with copy=False, ensure, that your cloud object
60# 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