Converting ROS image to QImage
Hello.
I'm making a Qt based GUI for our ROS application and part of it is to display images from a ROS topic.
I've managed to create a descendant class of QLabel that displays an RGB image from our cameras (/camera/image_raw topic) but when I try to display a grayscale image /camera/image_mono) I get weird results.
Here is the code I'm using:
img_format_table = {'rgb8': QtGui.QImage.Format_RGB888, 'mono8': QtGui.QImage.Format_Mono}
...
def up_camera_callback(self, data):
try:
format = img_format_table[data.encoding]
image = QtGui.QImage(data.data, data.width, data.height, format)
self.up_camera_signal.emit(image)
except Exception, e:
rospy.logerr(e)
The up_camera_signal is connected to my "video display" widget and just displays the image on it. As I said, this works fine for RGB images (when the data.encoding is 'rgb8') but if I do this for 'mono8' images I see strange results:
I have also tried mapping 'mono8' to QtGui.QImage.Format_MonoLSB but that doesn't change anything (documentation for the QImage formatting is at http://www.pyside.org/docs/pyside/PySide/QtGui/QImage.html).
Can anyone comment on this? Is there anything specific about the mono8 format in ROS that might be causing these problems?
Kind regards, Stefan Freyr