Récupérer le nuage de points
Les exemples utilisent la bibliothèque Python et se connectent avec une clé d’application. Remplacez qb2-xxxxxxxxx par le nom d’hôte ou l’adresse IP de votre capteur et application-key-for-qb2-xxxxxxxxx par le secret de votre clé.
Récupérer des images du nuage de points
Le service gRPC PointCloud de blickfeld_qb2.core_processing.services renvoie des images.
Récupérer une image unique
La méthode get renvoie une image.
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)
Sortie :
Received frame with ID: 2029
Diffuser des images en continu
La méthode stream renvoie les images l’une après l’autre. L’exemple s’arrête après trois images.
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
Sortie :
Received frame with ID: 2041
Received frame with ID: 2042
Received frame with ID: 2043
Lire les points d’une image
Cet exemple poursuit celui de Récupérer une image unique et utilise sa frame. Il calcule l’azimut et l’élévation de chaque point à partir de ses coordonnées cartésiennes 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)
Tracer l’image
Cet exemple poursuit les deux précédents et utilise leurs frame, np, azimuth et elevation. Il trace l’élévation en fonction de l’azimut des points situés entre 20° et 30° d’azimut et au-dessus de 5° d’élévation, colorés selon leur nombre de photons.
Il nécessite 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()