代码之家  ›  专栏  ›  技术社区  ›  enthusiasticgeek

使用C编程在gtk中为视频流linux更新opencv图像

  •  0
  • enthusiasticgeek  · 技术社区  · 16 年前

    我使用的是opencv 1.0.0和gtk2.0。我想从视频流中连续抓取图像。到目前为止,我已经成功地抓取了静态图像。这是非标准的IP摄像头,不是VGA/USB/V4L摄像头,所以需要知道明确的方法来不断刷新或更新视频流图像!

    GtkWidget *image;
    
    ...
    ...
    
    IplImage*   bayerImage = NULL;
    IplImage*   rgbImage = NULL;
    
    ...
    ...
    ...
    
    cvCvtColor( bayerImage, rgbImage, CV_BayerBG2RGB );
    // Usually opencv image is BGR, so we need to change it to RGB
    
    pix = gdk_pixbuf_new_from_data ((guchar*)rgbImage->imageData,
                     GDK_COLORSPACE_RGB,
                     FALSE,
                    rgbImage->depth,
                    rgbImage->width,
                    rgbImage->height,
                     (rgbImage->widthStep),
                      NULL,
                      NULL);
    image = gtk_image_new_from_pixbuf (pix);  
    
    1 回复  |  直到 15 年前
        1
  •  0
  •   enthusiasticgeek    15 年前
    /* (c) 2010 Virgoptrex. Feel Free to use. Leave credits intact */
    
    #include gtk/gtk.h
    
    gint t=0;
    
         gboolean
         expose_event_callback (GtkWidget *widget, GdkEventExpose *event, gpointer data)
         {
    
    
         //g_object_ref_sink (widget->window);
    
         // gdk_drawable_ref (widget->window);
    
           gdk_draw_arc (widget->window,
                         widget->style->fg_gc[GTK_WIDGET_STATE (widget)],
                         TRUE,
                         0, 0, widget->allocation.width, widget->allocation.height,
                         0, 64 * 18*t);
    
          //gdk_drawable_unref (widget->window);
    
    
    
           return TRUE;
         }
    
    
    
    static gboolean
    time_handler(GtkWidget *widget)
    {    
    
    
     gtk_widget_queue_draw(GTK_WIDGET(widget));
    
      if (t<20)
      { t++; }
      else if (t >=20)
      { t=0; } 
    
     printf("hello %d\n",t);
       return TRUE;
    
    
    } 
    
    int main( int argc,
              char *argv[] )
    {
        GtkWidget *window;
        GtkWidget *aspect_frame;
        GtkWidget *drawing_area;
        gtk_init (&argc, &argv);
    
        window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
    
    
    
        gtk_window_set_title (GTK_WINDOW (window), "Aspect Frame");
        g_signal_connect (G_OBJECT (window), "destroy",
                      G_CALLBACK (gtk_main_quit), NULL);
        gtk_container_set_border_width (GTK_CONTAINER (window), 10);
    
        /* Create an aspect_frame and add it to our toplevel window */
    
        aspect_frame = gtk_aspect_frame_new ("2x1", /* label */
                                             0.5, /* center x */
                                             0.5, /* center y */
                                             2, /* xsize/ysize = 2 */
                                             FALSE /* ignore child's aspect */);
    
        gtk_container_add (GTK_CONTAINER (window), aspect_frame);
        gtk_widget_show (aspect_frame);
    
        /* Now add a child widget to the aspect frame */
    
        drawing_area = gtk_drawing_area_new ();
    
        /* Ask for a 200x200 window, but the AspectFrame will give us a 200x100
         * window since we are forcing a 2x1 aspect ratio */
        gtk_widget_set_size_request (drawing_area, 200, 200);
        gtk_container_add (GTK_CONTAINER (aspect_frame), drawing_area);
        gtk_widget_show (drawing_area);
    
         g_signal_connect (G_OBJECT (drawing_area), "expose_event",
                             G_CALLBACK (expose_event_callback), NULL);
    
        g_timeout_add(100, (GSourceFunc) time_handler, (gpointer)drawing_area);
    
    
        gtk_widget_show (window);
        gtk_main ();
        return 0;
    }