Fetch the point cloud

This page documents an earlier firmware release. Read this page for the latest release

The examples use the Python library and sign in with an application key. Replace qb2-xxxxxxxxx with the hostname or IP address of your sensor and application-key-for-qb2-xxxxxxxxx with the secret of your key.

Fetch point cloud frames

The gRPC PointCloud service in blickfeld_qb2.core_processing.services returns frames.

Fetch a single frame

The method get returns one frame.

import blickfeld_qb2

token_factory = blickfeld_qb2.TokenFactory(application_key_secret="application-key-for-qb2-xxxxxxxxx")

# Open a secure and authenticated connection to the sensor
with blickfeld_qb2.Channel(fqdn_or_ip="qb2-xxxxxxxxx", token=token_factory) as channel:
    service = blickfeld_qb2.core_processing.services.PointCloud(channel)

    frame = service.get().frame

    # Print the frame ID
    print("Received frame with ID:", frame.id)

Output:

Received frame with ID: 2029

Stream frames continuously

The method stream returns one frame after the other. The example stops after three frames.

import blickfeld_qb2

token_factory = blickfeld_qb2.TokenFactory(application_key_secret="application-key-for-qb2-xxxxxxxxx")

# Open a secure and authenticated connection to the sensor
with blickfeld_qb2.Channel(fqdn_or_ip="qb2-xxxxxxxxx", token=token_factory) as channel:
    service = blickfeld_qb2.core_processing.services.PointCloud(channel)

    # Request a point cloud stream from the sensor
    for i, response in enumerate(service.stream()):

        # Extract a point cloud frame from the response
        frame = response.frame

        # Print the frame ID
        print("Received frame with ID:", frame.id)

        # Get 3 frames and stop
        if i == 2:
            break

Output:

Received frame with ID: 2041
Received frame with ID: 2042
Received frame with ID: 2043

Read the points of a frame

This example continues the one under Fetch a single frame and uses its frame. It calculates the azimuth and the elevation of each point from its Cartesian coordinates xyz.

import numpy as np

# Get the x,y,z coordinates of the points in the frame
xyz = frame.binary.cartesian

# Calculate the azimuth and elevation
distance = np.sqrt(xyz[:,0] ** 2 + xyz[:,1] ** 2 + xyz[:,2] ** 2)
azimuth = np.arctan2(xyz[:,0], xyz[:,1])
elevation = np.arcsin(xyz[:,2] / distance)

Plot the frame

This example continues the two above and uses their frame, np, azimuth and elevation. It plots the elevation over the azimuth of the points between 20° and 30° azimuth and above 5° elevation, coloured by their photon count. It needs Matplotlib:

pip install matplotlib
import matplotlib.pyplot as plt

index = np.argwhere((azimuth > np.deg2rad(20)) & (azimuth < np.deg2rad(30)) & (elevation > np.deg2rad(5)))
plt.scatter(azimuth[index], elevation[index], c=frame.binary.photon_count[index], s=0.1)
plt.xlabel("Azimuth [rad]")
plt.ylabel("Elevation [rad]")
plt.show()
Scatter plot of elevation from 0.09 to 0.34 rad over azimuth from 0.35 to 0.52 rad: the points lie on the scan lines of the sensor, with gaps where it saw nothing
Figure 1. The plotted part of the point cloud frame