Common Vision Blox 15.0
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Events Friends Modules Pages
Access to Composites in Python

Analyze your Composite

When receiving a composite from a camera, its content may not be immediately known. Therefore, you should analyze the composite first:

# Analyze composite.
if composite.purpose == cvb.CompositePurpose.PointCloud: # (1)
print("Purpose of composite is PointCloud.")
# Loop over all composite items.
for k in range(0,composite.item_count):
item = composite[k] # (2)
print("Type of item[{}]: {}".format(k, type(item))) # (3)
}

(1) The composite's purpose is checked. When working with 3D area scan cameras, it should be cvb.CompositePurpose.PointCloud.
(2) All composite items are iterated over in a loop and retrieved.
(3) The item's type is displayed, which can be either cvb.PlaneEnumerator, cvb.Plane, cvb.Image, cvb.PFNCBuffer or None.

If you only need access to the X, Y, Z, and optional confidence values, you can convert the composite into a point cloud for simplified data access. For all other cases, use the generic composite access described in Generic Access to Composite.

Convert a Composite to a Point Cloud

Note
To take advantage of the more convenient methods described in the section Access to Simple Point Clouds, it is recommended to convert a Composite into a Point Cloud whenever possible, as outlined in this section.

If you only need access to the X, Y, Z, and optional confidence values, you can simply convert the cvb.Composite into a cvb.PointCloud:

Union[cvb.DensePointCloud, cvb.SparsePointCloud] from_composite(cvb.Composite composite)

Generic Access to Composite

If, after analyzing your composite, you find that it contains additional data beyond what was covered in the previous section, you need to access it in a more generic way. This can be done retrieving the items of a composite and mapping them to a NumPy array:

idx = ...
item = composite[idx]: # (1)
# Convert to NumPy array.
np_array = cvb.as_array(item, copy=False) # 2
# Verify if the mapping was successful.
if np_array.flags["OWNDATA"]:
raise RuntimeError("cannot map to numpy array")
numpy.array as_array(Any buffer, bool copy=False)

(1) Retrieve the item. To convert it into a NumPy array, it must be either a cvb.PointCloud, cvb.Plane, cvb.Image, or cvb.PFNCBuffer.
(2) The item 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 item could not be mapped. In this case, the item has to be copied by setting copy=True in previous call

If your data has a specific type, refer to the more detailed sections:

Examples and Further Reading

Point Cloud Stream
Composite Stream
Image Pixel Access in Python