Obtener la nube de puntos
Los ejemplos utilizan la biblioteca de Python e inician sesión con una clave de aplicación. Sustituya qb2-xxxxxxxxx por el nombre de host o la dirección IP de su sensor y application-key-for-qb2-xxxxxxxxx por el secreto de su clave.
Obtener fotogramas de la nube de puntos
El servicio gRPC PointCloud de blickfeld_qb2.core_processing.services devuelve fotogramas.
Obtener un único fotograma
El método get devuelve un fotograma.
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)
Salida:
Received frame with ID: 2029
Transmitir fotogramas de forma continua
El método stream devuelve un fotograma tras otro. El ejemplo se detiene después de tres fotogramas.
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
Salida:
Received frame with ID: 2041
Received frame with ID: 2042
Received frame with ID: 2043
Leer los puntos de un fotograma
Este ejemplo continúa el de Obtener un único fotograma y utiliza su frame. Calcula el acimut y la elevación de cada punto a partir de sus coordenadas cartesianas 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)
Representar el fotograma
Este ejemplo continúa los dos anteriores y utiliza sus frame, np, azimuth y elevation. Representa la elevación frente al acimut de los puntos entre 20° y 30° de acimut y por encima de 5° de elevación, coloreados según su recuento de fotones.
Necesita 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()