ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | Q&A
Ask Your Question

Qt - Display topic image_raw on GUI

asked 2016-06-09 14:25:19 -0500

Geaper gravatar image

I think the title says all. I have a GUI on qt and I have a topic called robot/image_raw.

The problem is how can i display it on my gui project?


edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted

answered 2016-06-10 06:07:16 -0500

Dimitri Schachmann gravatar image

A possible solution:

Your Qt program needs to to also be a ROS node, which is not a problem in principle. A caveat is that Qt needs to run in the main thread, so you need to put ros::spin() into it's own thread:

auto t = std::thread([&]() {

You may need not make sure you t.join() at the end of you main(...) and also handle ros::shutdown() and QCoreApplication::quit() in a custom signal handler.

Then I would recommend to convert the image into a cv::Mat with opencv_bridge and after that to a QImage by using the data pointer of cv::Mat. Something like that:

    QImage dest((const uchar *), cvmat.cols, cvmat.rows, QImage::Format_RGB888);

The RGB888 assumes it is already debayered, image_raw is NOT debayered. You need to do it yourself, or use image_proc for that.

I also think that QImage takes owenership of the image data, so make sure you give it a copy that is not destroyed by some other destructor.

How to display a QImage in Qt is a question for a Qt forum. ;)

edit flag offensive delete link more


Oh sorry. Ok Thank you very much.

Geaper gravatar image Geaper  ( 2016-06-10 07:38:17 -0500 )edit

I don't see what there is to be sorry about!

Dimitri Schachmann gravatar image Dimitri Schachmann  ( 2016-06-10 08:05:08 -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


Asked: 2016-06-09 14:25:19 -0500

Seen: 1,323 times

Last updated: Jun 10 '16