[aravis] tests: new test file based on the camera API.



commit 6b87a711f3d0c506d7dd927d54c90beb27ca84c2
Author: Emmanuel Pacaud <emmanuel gnome org>
Date:   Fri Apr 2 20:40:29 2010 +0200

    tests: new test file based on the camera API.

 src/.gitignore      |    1 +
 src/Makefile.am     |    5 ++-
 src/arvcameratest.c |  140 +++++++++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 145 insertions(+), 1 deletions(-)
---
diff --git a/src/.gitignore b/src/.gitignore
index fbf0eb9..91c0f78 100644
--- a/src/.gitignore
+++ b/src/.gitignore
@@ -3,6 +3,7 @@ arv-load-xml
 arv-genicam-test
 arv-evaluator-test
 arv-zip-test
+arv-camera-test
 arvenumtypes.c
 arvenumtypes.h
 arvconfig.h
diff --git a/src/Makefile.am b/src/Makefile.am
index baab8aa..1f3cdcc 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -103,7 +103,7 @@ arvenumtypes.h: arvenumtypes.h.template $(ARAVIS_HDRS) $(GLIB_MKENUMS)
 arvenumtypes.c: arvenumtypes.c.template $(ARAVIS_HDRS) $(GLIB_MKENUMS)
 	$(AM_V_GEN) (cd $(srcdir) && $(GLIB_MKENUMS) --template arvenumtypes.c.template $(libaravis_la_HEADERS)) > $@
 
-bin_PROGRAMS = arv-test arv-load-xml arv-genicam-test arv-evaluator-test arv-zip-test
+bin_PROGRAMS = arv-test arv-load-xml arv-genicam-test arv-evaluator-test arv-zip-test arv-camera-test
 
 arv_test_SOURCES = arvtest.c
 arv_test_LDADD = $(ARAVIS_LIBS) libaravis.la
@@ -120,6 +120,9 @@ arv_evaluator_test_LDADD = $(ARAVIS_LIBS) libaravis.la
 arv_zip_test_SOURCES = arvziptest.c
 arv_zip_test_LDADD = $(ARAVIS_LIBS) libaravis.la
 
+arv_camera_test_SOURCES = arvcameratest.c
+arv_camera_test_LDADD = $(ARAVIS_LIBS) libaravis.la
+
 CLEANFILES = $(BUILT_SOURCES)
 
 if HAVE_INTROSPECTION
diff --git a/src/arvcameratest.c b/src/arvcameratest.c
new file mode 100644
index 0000000..e688c90
--- /dev/null
+++ b/src/arvcameratest.c
@@ -0,0 +1,140 @@
+#include <arv.h>
+#ifdef ARAVIS_WITH_CAIRO
+#include <cairo.h>
+#endif
+#include <stdlib.h>
+
+static gboolean cancel = FALSE;
+
+static void
+set_cancel (int signal)
+{
+	cancel = TRUE;
+}
+
+static char *arv_option_camera_name = NULL;
+static char *arv_option_debug_domains = NULL;
+static gboolean arv_option_snaphot = FALSE;
+static gboolean arv_option_auto_buffer = FALSE;
+static int arv_option_width = -1;
+static int arv_option_height = -1;
+static int arv_option_horizontal_binning = -1;
+static int arv_option_vertical_binning = -1;
+
+static const GOptionEntry arv_option_entries[] =
+{
+	{ "name",		'n', 0, G_OPTION_ARG_STRING,
+		&arv_option_camera_name,"Camera name", NULL},
+	{ "snapshot",		's', 0, G_OPTION_ARG_NONE,
+		&arv_option_snaphot,	"Snapshot", NULL},
+	{ "auto",		'a', 0, G_OPTION_ARG_NONE,
+		&arv_option_auto_buffer,	"AutoBufferSize", NULL},
+	{ "width", 		'w', 0, G_OPTION_ARG_INT,
+		&arv_option_width,		"Width", NULL },
+	{ "height", 		'h', 0, G_OPTION_ARG_INT,
+		&arv_option_height, 		"Height", NULL },
+	{ "h-binning", 		'\0', 0, G_OPTION_ARG_INT,
+		&arv_option_horizontal_binning,"Horizontal binning", NULL },
+	{ "v-binning", 		'\0', 0, G_OPTION_ARG_INT,
+		&arv_option_vertical_binning, 	"Vertical binning", NULL },
+	{ "debug", 		'd', 0, G_OPTION_ARG_STRING,
+		&arv_option_debug_domains, 	"Debug mode", NULL },
+	{ NULL }
+};
+
+int
+main (int argc, char **argv)
+{
+	ArvCamera *camera;
+	ArvStream *stream;
+	ArvBuffer *buffer;
+	GOptionContext *context;
+	GError *error = NULL;
+	int i;
+
+	g_thread_init (NULL);
+	g_type_init ();
+
+	context = g_option_context_new (NULL);
+	g_option_context_add_main_entries (context, arv_option_entries, NULL);
+
+	if (!g_option_context_parse (context, &argc, &argv, &error)) {
+		g_option_context_free (context);
+		g_print ("Option parsing failed: %s\n", error->message);
+		g_error_free (error);
+		return EXIT_FAILURE;
+	}
+
+	g_option_context_free (context);
+
+	arv_debug_enable (arv_option_debug_domains);
+
+	if (arv_option_camera_name == NULL)
+		g_print ("Looking for the first available camera\n");
+	else
+		g_print ("Looking for camera '%s'\n", arv_option_camera_name);
+
+	camera = arv_camera_new (arv_option_camera_name);
+	if (camera != NULL) {
+		gint payload;
+		gint x, y, width, height;
+		gint dx, dy;
+		double exposure;
+		guint64 n_processed_buffers;
+		guint64 n_failures;
+		guint64 n_underruns;
+
+		arv_camera_set_region (camera, 0, 0, arv_option_width, arv_option_height);
+		arv_camera_set_binning (camera, arv_option_horizontal_binning, arv_option_vertical_binning);
+
+		arv_camera_get_region (camera, &x, &y, &width, &height);
+		arv_camera_get_binning (camera, &dx, &dy);
+		exposure = arv_camera_get_exposure_time (camera);
+		payload = arv_camera_get_payload (camera);
+
+		g_print ("image width         = %d\n", width);
+		g_print ("image height        = %d\n", height);
+		g_print ("horizontal binning  = %d\n", dx);
+		g_print ("vertical binning    = %d\n", dy);
+		g_print ("exposure            = %g µs\n", exposure);
+
+		stream = arv_camera_get_stream (camera);
+		if (arv_option_auto_buffer)
+			arv_gv_stream_set_option (ARV_GV_STREAM (stream),
+						  ARV_GV_STREAM_OPTION_SOCKET_BUFFER_AUTO,
+						  0);
+
+		for (i = 0; i < 30; i++)
+			arv_stream_push_buffer (stream, arv_buffer_new (payload, NULL));
+
+		arv_camera_start_acquisition (camera);
+
+		signal (SIGINT, set_cancel);
+
+		do {
+			g_usleep (100000);
+
+			do  {
+				buffer = arv_stream_pop_buffer (stream);
+				if (buffer != NULL) {
+					/* Image processing here */
+					arv_stream_push_buffer (stream, buffer);
+				}
+			} while (buffer != NULL);
+		} while (!cancel);
+
+		arv_stream_get_statistics (stream, &n_processed_buffers, &n_failures, &n_underruns);
+
+		g_print ("Processed buffers = %Ld\n", n_processed_buffers);
+		g_print ("Failures          = %Ld\n", n_failures);
+		g_print ("Underruns         = %Ld\n", n_underruns);
+
+		arv_camera_stop_acquisition (camera);
+
+		g_object_unref (stream);
+		g_object_unref (camera);
+	} else
+		g_print ("No camera found\n");
+
+	return 0;
+}



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]