depth subscriber roslibpy
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.