ポイントクラウドの取得
このページは自動翻訳されたもので、まだレビューされていません。内容に相違がある場合は、英語の原文が優先されます。 英語の原文を読む
これらの例は Pythonライブラリを使用し、アプリケーションキーでサインインします。qb2-xxxxxxxxx をお使いのセンサーのホスト名またはIPアドレスに、application-key-for-qb2-xxxxxxxxx をキーのシークレットに置き換えてください。
ポイントクラウドフレームの取得
blickfeld_qb2.core_processing.services のgRPC PointCloud サービスがフレームを返します。
単一フレームの取得
メソッド get は、1つのフレームを返します。
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)
出力:
Received frame with ID: 2029
フレームの連続ストリーミング
メソッド stream は、フレームを次々に返します。この例では3フレームの後に停止します。
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
出力:
Received frame with ID: 2041
Received frame with ID: 2042
Received frame with ID: 2043
フレームのポイントの読み取り
この例は単一フレームの取得の例の続きで、その frame を使用します。各ポイントの直交座標 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)
フレームのプロット
この例は上記2つの例の続きで、その frame、np、azimuth、elevation を使用します。方位角20°から30°の間かつ仰角5°以上のポイントを、方位角に対する仰角としてプロットし、フォトン数で色分けします。
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()
図 1. プロットしたポイントクラウドフレームの一部