Ask Your Question
0

How do I get a rosbridge image message into OpenCV (C++ or python)

asked 2015-03-30 13:04:13 -0500

JWest gravatar image

updated 2015-04-03 09:24:08 -0500

I have several "robots" running rosbridge servers on raspberry pis and publishing low frame rate images. On a desktop computer, I need to be able to open a websocket to one of the robots and subscribe to its images. I have used mjpegserver for other purposes and it works fine, but in this case I do not want the image to go to a webpage, but rather to OpenCV for some computationally heavy image processing.

I have the rosbridge servers and clients setup and communicating. The client on the PC gets the image messages and they seem to contain the correct data based on simply printing the messages to the console as they arrive. However I am unable to convert the image into an OpenCV mat so that I can process it. It seems that it is simply a message formatting problem, but I can't find a solution or example on the webpage so if someone can point me in the right direction I would greatly appreciate it.

the imgmsg_to_cv2 fails and produces a complaint about unicode. If I start converting unicode to strings then the "encoding" field is ok, but the data complains that it does not have an array interface. Hopefully there is a simple function to translate the message into a compatible format.

Thanks, Jonathan West

edit retag flag offensive close merge delete

Comments

Have you looked into cv_bridge and image_transport?

2ROS0 gravatar image 2ROS0  ( 2015-03-30 23:55:31 -0500 )edit

Thanks for the reply. Yes I am using image_transport on the server side of the rosbridge and I am trying to use cv_bridge on the PC side. that is part of the call "self.bridge.imgmsg_to_cv2"

JWest gravatar image JWest  ( 2015-03-31 17:25:40 -0500 )edit

Ah, I see - I wasn't familiar with the python interface

2ROS0 gravatar image 2ROS0  ( 2015-04-01 23:56:54 -0500 )edit

1 Answer

Sort by ยป oldest newest most voted
0

answered 2015-04-03 09:25:40 -0500

JWest gravatar image

I found a similar question and the (simple) solution The JSON file is encoded with "Base64" so all I needed is a line like

msg.data = msg.data.decode('Base64')

and then everything is fine.

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

Stats

Asked: 2015-03-30 13:04:13 -0500

Seen: 786 times

Last updated: Apr 03 '15