#include#include #include static void destroy(GtkWidget *widget, gpointer data ) { gtk_main_quit (); } IplImage *openFile(const char * fname) { IplImage* img = cvLoadImage( fname, CV_LOAD_IMAGE_UNCHANGED); cvConvertImage( img, img, CV_CVTIMG_SWAP_RB); return img; } GtkImage *image_from_ocv(IplImage * img, int dst_w, int dst_h) { GdkPixbuf *pix_src, *pix_dst; pix_src = gdk_pixbuf_new_from_data((guchar*)img->imageData, GDK_COLORSPACE_RGB, FALSE, 8, img->width, img->height, img->widthStep, NULL, NULL); pix_dst = gdk_pixbuf_scale_simple(pix_src, dst_w, dst_h, GDK_INTERP_BILINEAR); GtkImage *image = (GtkImage*)gtk_image_new_from_pixbuf (pix_dst); return image; } int main(int argc, char *argv[]) { GtkWidget *window; GtkImage *gtk_image; IplImage *ocv_image; /* Open the OCV image */ ocv_image = openFile("lena.tif"); /* Create the GTK main window */ gtk_init (&argc, &argv); window = gtk_window_new (GTK_WINDOW_TOPLEVEL); g_signal_connect (G_OBJECT (window), "delete_event", G_CALLBACK (destroy), NULL); g_signal_connect (G_OBJECT (window), "destroy", G_CALLBACK (destroy), NULL); gtk_container_set_border_width (GTK_CONTAINER (window), 100); gtk_widget_show (window); /* Convert the OCV image to the GTK image */ gtk_image = image_from_ocv(ocv_image, window->allocation.width, window->allocation.height); /* Add the GtkImage to the GtkWindow */ gtk_container_add (GTK_CONTAINER (window), GTK_WIDGET(gtk_image)); gtk_widget_show (GTK_WIDGET(gtk_image)); /* Gtk Loop */ gtk_main (); return 0; }