diff options
author | Benjamin Franzke <benjaminfranzke@googlemail.com> | 2012-04-04 20:32:14 +0200 |
---|---|---|
committer | Benjamin Franzke <benjaminfranzke@googlemail.com> | 2012-04-05 12:08:25 +0200 |
commit | 5cc6ddd70bde11c9bc2670d8a6555ec8e1bc800b (patch) | |
tree | 90b1f22fd014393cba4928a64d0895170c9c7872 | |
parent | 863dae68a4e71c93dcea3ec599088bc44276ae01 (diff) | |
download | cv-5cc6ddd70bde11c9bc2670d8a6555ec8e1bc800b.tar.gz cv-5cc6ddd70bde11c9bc2670d8a6555ec8e1bc800b.tar.bz2 cv-5cc6ddd70bde11c9bc2670d8a6555ec8e1bc800b.zip |
capture: Use cvQueryFrame
The splitted cvGrabFrame + cvRetrieveFrame doesnt work as documented
anyway. cvGrabFrame _should_ be fast, but does select(2) with a timeout
of 2 seconds on the v4l fd.
-rw-r--r-- | capture.c | 25 |
1 files changed, 7 insertions, 18 deletions
@@ -130,14 +130,15 @@ draw_cb(GtkWidget *widget, cairo_t *cr, gpointer userdata) return FALSE; } -static void -capture(struct ct *ct) +static gboolean +capture(gpointer userdata) { + struct ct *ct = userdata; IplImage *image; guchar *row1, *row2, *p1, *p2; int x, y; - image = cvRetrieveFrame(ct->capture, 0); + image = cvQueryFrame(ct->capture); if (!image) { fprintf(stderr, "ERROR: frame is null...\n"); exit(EXIT_FAILURE); @@ -174,19 +175,7 @@ capture(struct ct *ct) row1 += image->widthStep; row2 += cairo_image_surface_get_stride(ct->surface); } -} - -static gboolean -grab(gpointer userdata) -{ - struct ct *ct = userdata; - - if (cvGrabFrame(ct->capture) == 0) - return TRUE; - - capture(ct); gtk_widget_queue_draw(ct->drawing_area); - return TRUE; } @@ -212,12 +201,12 @@ main(int argc, char *argv[]) cvGetCaptureProperty(ct.capture, CV_CAP_PROP_FRAME_WIDTH), cvGetCaptureProperty(ct.capture, CV_CAP_PROP_FRAME_HEIGHT)); - while (cvGrabFrame(ct.capture) == 0); - capture(&ct); ct.window = gtk_window_new(GTK_WINDOW_TOPLEVEL); ct.drawing_area = gtk_drawing_area_new(); + capture(&ct); + gtk_widget_set_size_request(ct.drawing_area, cairo_image_surface_get_width(ct.surface), cairo_image_surface_get_height(ct.surface)); @@ -240,7 +229,7 @@ main(int argc, char *argv[]) g_signal_connect(ct.drawing_area, "motion-notify-event", G_CALLBACK(motion_notify_event), &ct); - g_idle_add(grab, &ct); + g_idle_add(capture, &ct); gtk_widget_show_all(ct.window); gtk_main(); |