Ask Your Question
0

Image viewer in undecorated window?

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

lucasw gravatar image

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
0

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

lucasw gravatar image

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

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

The full code is https://github.com/lucasw/vimjay/blob... , and the important lines are

class UndecoratedWindow(QtGui.QLabel): 
...
    self.setWindowFlags(Qt.FramelessWindowHint)

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(msg.data, 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(), 
            self.wd, self.ht, 
            QImage.Format_RGB888))

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

    self.setPixmap(QtGui.QPixmap.fromImage(self.qimage))

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

edit flag offensive delete link more
0

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

kramer gravatar image

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

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*)imgData.data(), 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

Comments

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 imagelucasw ( 2014-12-18 11:04:26 -0500 )edit

Your Answer

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

Add Answer

Question Tools

1 follower

Stats

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

Seen: 701 times

Last updated: Dec 19 '14