Advertisement
inckka

videoOpencv

Feb 19th, 2016
340
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 2.07 KB | None | 0 0
  1. /*
  2.  *  compile with:
  3.  *  gcc -o weby3 att3.c `pkg-config --libs --cflags gtk+-2.0 opencv`
  4.  */
  5.  
  6. #include "highgui.h"
  7. #include <gtk/gtk.h>
  8. #include <opencv/cv.h>
  9. #include <opencv/cxcore.h>
  10.  
  11. GdkPixbuf* pix;
  12. IplImage* frame;
  13. CvCapture* capture;
  14.  
  15.  
  16. gboolean
  17. expose_event_callback(GtkWidget *widget, GdkEventExpose *event, gpointer data)
  18. {
  19.  
  20.   printf("Exposed\n");
  21.  
  22.  
  23.   //while(1){
  24.     frame = cvQueryFrame( capture );
  25.  
  26.     pix = gdk_pixbuf_new_from_data((guchar*) frame->imageData,
  27.            GDK_COLORSPACE_RGB, FALSE, frame->depth, frame->width,
  28.            frame->height, (frame->widthStep), NULL, NULL);
  29.  
  30.  
  31.     gdk_draw_pixbuf(widget->window,
  32.      widget->style->fg_gc[GTK_WIDGET_STATE (widget)], pix, 0, 0, 0, 0,
  33.      -1, -1, GDK_RGB_DITHER_NONE, 0, 0); /* Other possible values are  GDK_RGB_DITHER_MAX,  GDK_RGB_DITHER_NORMAL */
  34.   //}
  35.  
  36.  
  37.     return TRUE;
  38. }
  39.  
  40.  
  41. int main( int argc, char** argv ) {
  42.    /* GtkWidget is the storage type for widgets */
  43.    GtkWidget *window;
  44.    GtkWidget *drawing_area;
  45.  
  46.    gtk_init (&argc, &argv);
  47.  
  48.    capture = cvCreateCameraCapture(0);
  49.  
  50.    /* create a new window */
  51.    window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
  52.    gtk_window_set_title (GTK_WINDOW (window), "Hello WebCam and OpenCV!");
  53.    g_signal_connect (G_OBJECT (window), "destroy",
  54.     G_CALLBACK (gtk_main_quit), NULL);
  55.  
  56.    /* Sets the border width of the window. */
  57.    gtk_container_set_border_width (GTK_CONTAINER (window), 10);
  58.  
  59.    /* Now add a child widget to the aspect frame */
  60.    drawing_area = gtk_drawing_area_new();
  61.  
  62.  
  63.    /* window since we are forcing a aspect ratio */
  64.    gtk_widget_set_size_request(drawing_area, 600, 400);
  65.    gtk_container_add(GTK_CONTAINER (window), drawing_area);
  66.    gtk_widget_show(drawing_area);
  67.  
  68.    g_signal_connect (G_OBJECT (drawing_area), "expose-event",
  69.    G_CALLBACK (expose_event_callback), NULL);
  70.  
  71.    /* and the window */
  72.    gtk_widget_show (window);
  73.  
  74.    /* All GTK applications must have a gtk_main(). Control ends here
  75.     * and waits for an event to occur (like a key press or
  76.     * mouse event). */
  77.    gtk_main ();
  78. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement