Punktwolke abrufen
Die Beispiele verwenden die Python-Bibliothek und melden sich mit einem Anwendungsschlüssel an. Ersetzen Sie qb2-xxxxxxxxx durch den Hostnamen oder die IP-Adresse Ihres Sensors und application-key-for-qb2-xxxxxxxxx durch das Geheimnis Ihres Schlüssels.
Punktwolken-Frames abrufen
Der gRPC-Dienst PointCloud in blickfeld_qb2.core_processing.services liefert Frames.
Einzelnen Frame abrufen
Die Methode get liefert einen 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)
Ausgabe:
Received frame with ID: 2029
Frames fortlaufend streamen
Die Methode stream liefert einen Frame nach dem anderen. Das Beispiel endet nach drei 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
Ausgabe:
Received frame with ID: 2041
Received frame with ID: 2042
Received frame with ID: 2043
Punkte eines Frames auslesen
Dieses Beispiel setzt das unter Einzelnen Frame abrufen fort und verwendet dessen frame. Es berechnet für jeden Punkt den Azimut und die Elevation aus seinen kartesischen Koordinaten 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)
Frame darstellen
Dieses Beispiel setzt die beiden obigen fort und verwendet deren frame, np, azimuth und elevation. Es stellt die Elevation über dem Azimut der Punkte zwischen 20° und 30° Azimut und oberhalb von 5° Elevation dar, eingefärbt nach ihrer Photonenzahl.
Es benötigt 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()