0
4

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 3 years have passed since last update.

RealSenseによるフィルター処理後の距離取得に関して

Last updated at Posted at 2021-06-11

困ったこと

以下のソースコードでRealSenseで得た画像からピクセル座標指定で深度を取得しようとしました

test.py
frames = pipeline.wait_for_frames()  # realsenseから画像取得
depth_frame = flames.get_depth_frame # 画像から深度画像取得

# フィルター処理
temporal = rs.temporal_filter()
depth_frame = temporal.process(depth_frame)

# 深度画像からピクセル座標(100, 100)の深度を取得
distance = depth_frame.get_distance(100, 100)

すると以下のようなエラーが起きます。

distance = depth_frame.get_distance(100, 100)
AttributeError: 'pyrealsense2.pyrealsense2.frame' object has no attribute 'get_distance'

フィルター処理しなければこのようなエラーは起きません。
しかしフィルター処理した後のdepth_frameからはget_distance関数が呼べないそうです。

解決方法

フィルター処理した後に以下のコードを追加します。
 depth_frame = depth_frame.as_depth_frame()

すなわち最初のソースコードは以下のように修正されます

test.py
frames = pipeline.wait_for_frames()  # realsenseから画像取得
depth_frame = flames.get_depth_frame # 画像から深度画像取得

# フィルター処理
temporal = rs.temporal_filter()
depth_frame = temporal.process(depth_frame)
depth_frame = depth_frame.as_depth_frame() # ←追加

# 深度画像からピクセル座標(100, 100)の深度を取得
distance = depth_frame.get_distance(100, 100)

0
4
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
0
4

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?