Subscribing to /camera/image/compressed

asked 2019-09-18 10:48:31 -0500

aks gravatar image

updated 2019-09-18 11:46:39 -0500

I am publishing a video through rosbridge using roslibpy in a compressed format. Since rosbridge is based on JSON, i need to convert the image into a string (base64 encoding) to be able to publish using the rosbridge.

Here is a snippet from the code :

ros = roslibpy.Ros(host='localhost', port=9090)
ros.on_ready(lambda: print('Is ROS connected ?', ros.is_connected))
ros.imagePublisher = roslibpy.Topic(ros,'/camera/image/compressed','sensor_msgs/CompressedImage')

i = np.array(image.raw_data)
i2 = i.reshape((480, 680, 4)) 
i3 = i2[:, :, :3] 
imageProcessed = i3.array2string(i3) 
ros.imagePublisher.publish(roslibpy.Message({'format' : "jpeg", 'data' : imageProcessed}))

ros.run_forever()

Thus I publish an encoded string.

Now, First I need to decode my string back to a numpy array else I cannot subscribe to this topic since the message type are not same . Can i somehow do it using command line or I need to write another node for it ? Because as soon as I want try to subscribe it by rostopic echo /camera/image/compressed, I get an error saying the message type is not uint8. How can I solve this ?

Now on the ROS side, how can I visualize this in RVIZ ? Can I directly visualize the /camera/image/compressed topic or do i need to convert it first into /camera/image topic ?

For the latter, I can republish using the image_transport package, something like : rosrun image_transport republish [compressed] in:=camera/image/compressed raw out:=camera/image

Here is the link to discussion

edit retag flag offensive close merge delete