summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--capture.c25
1 files changed, 7 insertions, 18 deletions
diff --git a/capture.c b/capture.c
index 0c95796..4b6404c 100644
--- a/capture.c
+++ b/capture.c
@@ -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();