ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange
Ask Your Question
0

depth subscriber roslibpy

asked 2022-07-19 07:25:48 -0500

dwd394 gravatar image

updated 2022-07-19 09:16:08 -0500

How do we get a proper sized (640x480) array from the depth message?

my subscribed depth final array is a (640x480x2).... when it should be (640x480). The rgb topic is fine at (640x480x3). I tried both topics that publish depth data. i suspect that this is a decoding error given that the depth is UC16? this is a quirk of the roslibpy rosbridge library....you have to decode the base64 data that travels through the rosbridge.

code snippet of the depth callback.

def subscribe_depth(depth_raw_msg):
  print('depth_raw_msg keys: ', depth_raw_msg.keys())
  print('depth_raw_msg encoding: ', depth_raw_msg['encoding'])
  depth_data_raw = depth_raw_msg['data']
  depth_header = depth_raw_msg['header']
  depth_base64_bytes = depth_raw_msg['data']
  depth_bytes = base64.b64decode(depth_base64_bytes)
  depth_data = np.frombuffer(depth_bytes, dtype=np.uint8)
  depth_data = depth_data.reshape(480, 640)

i think its a problem specifically with this line:

 depth_data = np.frombuffer(depth_bytes, dtype=np.uint8)

driving test code:

Topic = roslibpy.Topic(ros, '/wx250s/camera/depth/image_raw', 'sensor_msgs/Image')
print('is connected:', ros.is_connected)
while ros.is_connected:
  test_depth_data = Topic.subscribe(subscribe_depth)

error: ValueError: cannot reshape array of size 614400 into shape (480,640)

Thanks for coming to my dumpsterfire :)

UPDATE: We get the right array size when changing the suspect line to np.frombuffer(depth_bytes, dtype=np.uint16), but I don't know if that's right.

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
1

answered 2022-07-19 11:11:51 -0500

Mike Scheutzow gravatar image

It is common for depth values to be published as type uint16.

edit flag offensive delete link more

Comments

Thank You, yep that worked.

dwd394 gravatar image dwd394  ( 2022-07-19 15:10:28 -0500 )edit

Question Tools

1 follower

Stats

Asked: 2022-07-19 07:25:48 -0500

Seen: 91 times

Last updated: Jul 19 '22