Qt - Display topic image_raw on GUI
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?
Thanks
ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | Q&A answers.ros.org |
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?
Thanks
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([&]() {
ros::spin();
});
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.data, 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. ;)
Please start posting anonymously - your entry will be published after you log in or create a new account.
Asked: 2016-06-09 14:25:19 -0500
Seen: 1,323 times
Last updated: Jun 10 '16