This section explains how to access data from the CVB point cloud classes in Python cvb.PointCloud, cvb.DensePointCloud, cvb.SparsePointCloud.
For more details on the concept behind the CVB point cloud classes, please refer to the section CVB Point Cloud.
(1) A point cloud is loaded, acquired or created. The with statement should be used to manage the point cloud's lifetime automatically.
(2) The point cloud is mapped to a NumPy array without copying, allowing direct access to pixel data.
(3) Check whether the mapping was successful; if OWNDATA is True, the image could not be mapped. In this case, the image has to be copied by setting copy=True in previous call.
Note that the shape of the mapped NumPy array depends on the type of point cloud. For an organized cvb.DensePointCloud, the shape[0] represents the height, shape[1] represents the width, and shape[2] denotes the number of planes, as the following code example illustrates:
(1) Print dimensions of the (dense) point cloud array.
(2) Modify point cloud values in the NumPy array. If the array has been previously mapped with option copy=False, this operation directly updates the underlying image data. In this case the modified point cloud can be saved to a file as done in step (3).
The following code example demonstrates the dimensions and how to access the array for an un-organized cvb.SparsePointCloud:
(1) Print dimensions of the (sparse) point cloud array.
(2) Modify point cloud values in the NumPy array. If the array has been previously mapped with option copy=False, this operation directly updates the underlying image data. In this case the modified point cloud can be saved to a file as done in step (3).