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

Image viewer in undecorated window?

asked 2014-12-17 09:25:10 -0600

lucasw gravatar image

updated 2020-11-21 11:41:58 -0600

Are there any solutions for viewing sensor_msgs::Image messages in an undecorated window (no menu or border) with ros dynamically controlled width, height, x and y screen position?

I think I can implement this in Qt, or barring that X or maybe GDK (I want some optimal mix of ease-of-implementation and performance, and portability at least across linux distributions), but if it already exists, or something close to it I can adapt exists, I'd rather use that.

edit retag flag offensive close merge delete

2 Answers

Sort by ยป oldest newest most voted

answered 2014-12-19 08:00:42 -0600

lucasw gravatar image

updated 2014-12-19 08:10:23 -0600

Qt in python turned out to be a lot easier than I was expecting.

The full code is , and the important lines are

class UndecoratedWindow(QtGui.QLabel): 

And in response to a new x,y and width and height:

    self.resize(roi.width, roi.height)
    self.move(roi.x_offset, roi.y_offset)

and converting the image for use in Qt:

def imageCallback(self, msg):
    np_arr = np.fromstring(, np.uint8)
    sz = (msg.height, msg.width, msg.step / msg.width)
    image = np.reshape(np_arr, sz)

    ... do some stuff with image to keep aspect raio ...

     self.qimage = QImage.rgbSwapped(QImage(image.tostring(), 

Do this in qt thread to update the display, not the callback thread:


(I think my code might lack some thread safetyness regarding self.qimage)

edit flag offensive delete link more

answered 2014-12-17 11:24:09 -0600

kramer gravatar image

updated 2014-12-17 11:28:13 -0600

Since I'm not all that familiar with rqt (nor rqt_image_view) and I think that you may be looking for more than image_view, I'll have to leave it to someone else to provide an answer there. I (currently) do most of my UI work using librviz, which allows incorporating the various RViz pieces directly into a Qt application. The librviz tutuorial is quite instructive if you choose to go this route.

First, I'd note that image display width, height, and screen position is not really dependent on the incoming image message, but rather the graphical container, so you're thinking about that wrong. Now, with a reference to the rviz::VisualizationManager, you can do this:

rviz::VisualizationManager* visMan;
QString dispName("MyImage");
QString dispPlugin("rviz/Image");
QString imgTopic("/image/topic");
rviz::Display *disp = visMan->createDisplay(dispPlugin, dispName);
disp->subProp("Image Topic")->setValue(imgTopic);

Or, if you prefer to work a little closer to basic Qt, you might do something like this:

// NOTE: I'm guessing at the image format; change as needed
// NOTE: I'm assuming the image will be displayed in a QLabel
QLabel* m_imgLabel;
void MyClass::imageCb(const sensor_msgs::ImageConstPtr &msg) { // read message contents into QImage const unsigned char* databeg = &(msg->data.front()); QByteArray imgData = QByteArray((char*)databeg, msg->data.size()); QImage* qimg((uchar*), msg->width, msg->height, QImage::Format_RGB32);
// stuff QLabel with QPixmap derived from the QImage int w = m_imgLabel->width(), h= m_imgLabel->height(); QPixmap* qpxm; qpxm->convertFromImage(*qimg); qpxm = qpxm->scaled(w, h, Qt::KeepAspectRatio); m_imgLabel->setPixmap(qpxm); }

That's just a sketch, not a full definition, and there are complexities that need to be handled (e.g., QImage documentation states that the data buffer must remain valid throughout the life of the QImage).

It may also be instructive to look at a post (that I answered) concerning the use of occupancy grids with QImage and a post about setting up multiple, unadorned views in RViz (that doesn't really have a solution yet).

edit flag offensive delete link more


The window screen position and dimensions would be controlled through a topic- possibly of type RegionOfInterest. The question is about being able to do that- and more importantly toggling off window menus and borders, it needs to be pure image and possibly letterboxing to keep aspect ratio.

lucasw gravatar image lucasw  ( 2014-12-18 11:04:26 -0600 )edit

Question Tools

1 follower


Asked: 2014-12-17 09:25:10 -0600

Seen: 1,247 times

Last updated: Dec 19 '14