Common Vision Blox 15.0
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Events Friends Modules Pages
Image Manager/CVBpy/CreateAndAccessCalibratedPointCloud

This example program is located in your CVB installation under %CVB%Tutorial/Image Manager/CVBpy/CreateAndAccessCalibratedPointCloud.

calibrated_point_cloud_access.py:

# @brief Example for creating a calibrated point cloud from
# a range map and accessing point cloud values.
"""
CVBpy Example Script
1. Creates a calibrated point cloud from a range map aquired
by a laser triangulation setup (for further information see
<a htref="https://help.commonvisionblox.com/NextGen/15.0/md_theory_of_operation_tools__metric.html">here</a>).
2. Converts it to a numpy array without copying.
3. Modifies point cloud values through numpy.
4. Saves the point cloud.
Requires: numpy
"""
import os
import cvb
# load range map
print("Loading range map and calibration file.")
rangemap = cvb.Image(os.path.join(cvb.install_path(
), "tutorial", "Metric", "Images", "RangeMapCalibrationPattern.tif"))
# load calibration file
calibrator = cvb.Calibrator3D.load(os.path.join(
cvb.install_path(), "tutorial", "Metric", "Images", "SICalibration.json"))
# create calibrated (dense) point cloud
print("Creating calibrated point cloud.")
rangemap.planes[0], calibrator, cvb.PointCloudFlags.Float)
# create a numpy array from point cloud
# copy=False is default, but just a request
np_array = cvb.as_array(cloud, copy=False)
if np_array.flags["OWNDATA"]:
# use copy=True or
# np_array = cvb.to_array(cloud)
# or simply throw an error:
raise RuntimeError("cannot map to numpy array")
# point cloud access
print("Modifying point cloud data via numpy array.")
# E.g. cut height values (z) below 0.
for i in range(np_array.shape[0]):
for j in range(np_array.shape[1]):
if np_array[i, j, 2] < 0: # z value smaller zero
np_array[i, j, 2] = 0
# set confidence to false (note, that usually
np_array[i, j, 3] = 0
# only dense point clouds have the confidence layer!)
# save point cloud
print("Saving: ./calibrated_cloud.ply")
cloud.save("calibrated_cloud.ply")
# Attention: If you use cvb.as_array with copy=False, ensure, that your cloud object
# lives as long as your numpy array!
Union[cvb.Calibrator3DAT, cvb.LaserPlaneHomographyCalibrator3D, cvb.LaserPlaneZigZagCalibrator3D, cvb.FactorsCalibrator3D, cvb.MatrixCalibrator3D, cvb.PinholeCameraCalibrator3D] load(str file_name)
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)
str install_path()
numpy.array as_array(Any buffer, bool copy=False)