1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

ZED SDKを使いこなす point_cloud

Last updated at Posted at 2024-02-29

ZED SDK の使い方が覚えきれていないのでメモを残す。
ZED SDK はStereoLabs がZED2やZED Xなどのステレオカメラ用に提供しているSDKである。

point cloud に関する公式のドキュメント

前提

ZED SDK 4.0

コードの断片

color 付きの点群を取得したいとき

.py
point_cloud = sl.Mat() # まずは、データ構造の初期化
# 次の行で値が取得される。
zed.retrieve_measure(point_cloud, sl.MEASURE.XYZRGBA)
# xyz_rgba はnumpy のdtype=np.float32 のデータ形式になる。
xyz_rgba = point_cloud.get_data()

奥行きがZである。
カメラから遠くなるほど、マイナスの値が大きくなることに注意。
(ただし、IMUを使って座標変換をしたあとの奥行きである。)

xyz_rgba[:, :, 0] はx座標
xyz_rgba[:, :, 1] はy座標
xyz_rgba[:, :, 2] はz座標
xyz_rgba[:, :, 3] は(r, g, b, a) の各uint8 をfloat32のデータ形式として解釈した値が格納されている。

注意:

  • np.isfinite()を満たさないデータが格納されることがある。
  • runtime_parameters.enable_fill_mode = False としたときは、必ずといってよい。
.py
# 1画素づつアクセスすると、こうなる。
# 遅くなるので、こうする理由はない。
# (success の値は実行の成否の結果が入る。執筆時点での公式ドキュメントとは違っている。)
for i in range(h):
    for j in range(w):
        success, point3D = point_cloud.get_value(j, i)

Point cloud のデータメンバー、メソッドの表示を得るには

pythonのinspectモジュールを利用すると良い。
この方法で上記のget_data()メソッドに気づいた。
(ただし、使うのを推奨しないメソッドをも表示している可能性はある。)

.py
for k, v in inspect.getmembers(point_cloud):
    print("point_cloud", k, v)

メソッドの説明は, pythonのhelpを利用する。

.py
get_data(memory_type=<MEM.CPU: 1>, deep_copy=False) -> 'np.array' method of pyzed.sl.Mat instance
    Mat.get_data(self, memory_type=MEM.CPU, deep_copy=False) -> np.array

get_value(x: 'int', y: 'int', memory_type=<MEM.CPU: 1>) -> 'ERROR_CODE' method of pyzed.sl.Mat instance
    Mat.get_value(self, int x: int, int y: int, memory_type=MEM.CPU) -> ERROR_CODE

ply ファイルを出力する。

point_cloud のインスタンスにはwrite()メソッドがある。
point_cloud.write("sample.ply")

float32のRGBAをnp.uint8のnumpy array に変換するには

float32のrgbaデータをuint8に変換する
を参照してください。

point_cloudのメソッド

.py
point_cloud.get_height()
point_cloud.get_width()
1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?