views:

1287

answers:

2

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?

Solved:

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);
+1  A: 

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.

Karl Voigtland
Thanks, works great. I modified it to be more Gtkmm style.
bse
A: 

This works fine for still Images. What about motion images? The example code on the forum doesn't work for motion images for video streaming. In this case we also cannot use V4L APIs as camera input is not standard usb webcam but image by ethernet/IP cam!

virgoptrex