How can I display an OpenCV IplImage in Gtk+/Gtkmm?
-
19-09-2019 - |
Question
I've got images as IplImage that I want to display in a small Gtkmm application. How can I convert them to something Gtk can display?
Solution
You can create a new pixbuf using gdk_new_pixbuf_from_data()
passing it the image format parameters corresponding to the format of the IplImage. The IplImage image data is accessed via the imageData
field.
Here is some example code from a Gtk forum.
OTHER TIPS
Posting OP's solution as answer:
IplImage* image;
cvCvtColor(image, image, CV_BGR2RGB);
Glib::RefPtr<Gdk::Pixbuf> pixbuf = Gdk::Pixbuf::create_from_data(
(guint8*)image->imageData,
Gdk::COLORSPACE_RGB,
false,
image->depth,
image->width,
image->height,
image->widthStep);
Gtk::Image gtk_img;
gtk_img.set(pixbuf);
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow