[aravis/wip/emmanuel/wakeup] tests: new dynamic ROI test
- From: Emmanuel Pacaud <emmanuel src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [aravis/wip/emmanuel/wakeup] tests: new dynamic ROI test
- Date: Mon, 4 May 2015 19:07:46 +0000 (UTC)
commit 14d889e8c07b7fddbe1c851a1353302bd57986c7
Author: Emmanuel Pacaud <emmanuel gnome org>
Date: Mon May 4 21:07:28 2015 +0200
tests: new dynamic ROI test
tests/.gitignore | 1 +
tests/Makefile.am | 4 +
tests/arvroitest.c | 188 ++++++++++++++++++++++++++++++++++++++++++++++++++++
3 files changed, 193 insertions(+), 0 deletions(-)
---
diff --git a/tests/.gitignore b/tests/.gitignore
index b9a1e6c..7a06f12 100644
--- a/tests/.gitignore
+++ b/tests/.gitignore
@@ -12,5 +12,6 @@ arv-camera-test
arv-chunk-parser-test
arv-heartbeat-test
arv-example
+arv-roi-test
time-test
realtime-test
diff --git a/tests/Makefile.am b/tests/Makefile.am
index ea440a3..9a7096d 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -16,6 +16,7 @@ noinst_PROGRAMS = \
arv-camera-test \
arv-chunk-parser-test \
arv-heartbeat-test \
+ arv-roi-test \
arv-example \
time-test \
realtime-test
@@ -41,6 +42,9 @@ arv_chunk_parser_test_LDADD = $(test_progs_ldadd)
arv_heartbeat_test_SOURCES = arvheartbeattest.c
arv_heartbeat_test_LDADD = $(test_progs_ldadd)
+arv_roi_test_SOURCES = arvroitest.c
+arv_roi_test_LDADD = $(test_progs_ldadd)
+
arv_example_SOURCES = arvexample.c
arv_example_LDADD = $(test_progs_ldadd)
diff --git a/tests/arvroitest.c b/tests/arvroitest.c
new file mode 100644
index 0000000..99d9b9f
--- /dev/null
+++ b/tests/arvroitest.c
@@ -0,0 +1,188 @@
+#include <arv.h>
+#include <arvstr.h>
+#include <stdlib.h>
+#include <signal.h>
+#include <stdio.h>
+
+#define N_BUFFERS 50
+
+#define WIDTH_MIN 100
+#define HEIGHT_MIN 100
+#define WIDTH_MAX 600
+#define HEIGHT_MAX 600
+#define SIZE_INC 10
+
+typedef struct {
+ ArvCamera *camera;
+ ArvStream *stream;
+ GMainLoop *main_loop;
+ int buffer_count;
+ int width, height;
+} ApplicationData;
+
+static gboolean cancel = FALSE;
+
+static void
+set_cancel (int signal)
+{
+ cancel = TRUE;
+}
+
+static void
+new_buffer_cb (ArvStream *stream, ApplicationData *data)
+{
+ ArvBuffer *buffer;
+
+ buffer = arv_stream_try_pop_buffer (stream);
+ if (buffer != NULL) {
+ if (arv_buffer_get_status (buffer) == ARV_BUFFER_STATUS_SUCCESS)
+ data->buffer_count++;
+
+ /* Image processing here */
+
+ arv_stream_push_buffer (stream, buffer);
+ }
+}
+
+static gboolean
+periodic_task_cb (void *abstract_data)
+{
+ ApplicationData *data = abstract_data;
+
+ printf ("Frame rate = %d Hz\n", data->buffer_count);
+ data->buffer_count = 0;
+
+ if (cancel) {
+ g_main_loop_quit (data->main_loop);
+ return FALSE;
+ }
+
+ return TRUE;
+}
+
+static gboolean
+switch_roi (gpointer user_data)
+{
+ ApplicationData *data = user_data;
+ gint payload;
+ gint width;
+ gint height;
+ guint i;
+
+ arv_camera_stop_acquisition (data->camera);
+ arv_stream_delete_buffers (data->stream);
+
+ data->width += SIZE_INC;
+ if (data->width > WIDTH_MAX)
+ data->width = WIDTH_MIN;
+ data->height += SIZE_INC;
+ if (data->height > HEIGHT_MAX)
+ data->height = HEIGHT_MIN;
+
+ arv_camera_set_region (data->camera, 0, 0, data->width, data->height);
+ arv_camera_get_region (data->camera, NULL, NULL, &width, &height);
+
+ printf ("image size = %dx%d\n", width, height);
+
+ payload = arv_camera_get_payload (data->camera);
+
+ for (i = 0; i < N_BUFFERS; i++)
+ arv_stream_push_buffer (data->stream, arv_buffer_new (payload, NULL));
+
+ arv_camera_start_acquisition (data->camera);
+
+ return TRUE;
+}
+
+int
+main (int argc, char **argv)
+{
+ ApplicationData data;
+ const char *camera_name = NULL;
+ int i;
+
+ data.buffer_count = 0;
+ data.width = WIDTH_MIN;
+ data.height = HEIGHT_MIN;
+
+ arv_g_thread_init (NULL);
+ arv_g_type_init ();
+
+ if (argc > 2) {
+ printf ("Usage: arv-roi-test <camera-name>\n");
+
+ return EXIT_FAILURE;
+ }
+
+ if (argc == 1) {
+ g_print ("Looking for the first available camera\n");
+ } else {
+ camera_name = argv[1];
+ g_print ("Looking for camera '%s'\n", camera_name);
+ }
+
+ data.camera = arv_camera_new (camera_name);
+ if (data.camera != NULL) {
+ void (*old_sigint_handler)(int);
+ gint payload;
+ gint x, y, width, height;
+ guint64 n_completed_buffers;
+ guint64 n_failures;
+ guint64 n_underruns;
+
+ arv_camera_set_region (data.camera, 0, 0, data.width, data.height);
+ arv_camera_set_frame_rate (data.camera, 20.0);
+ arv_camera_get_region (data.camera, &x, &y, &width, &height);
+
+ payload = arv_camera_get_payload (data.camera);
+
+ printf ("vendor name = %s\n", arv_camera_get_vendor_name (data.camera));
+ printf ("model name = %s\n", arv_camera_get_model_name (data.camera));
+ printf ("device id = %s\n", arv_camera_get_device_id (data.camera));
+ printf ("image x = %d\n", x);
+ printf ("image y = %d\n", y);
+ printf ("image width = %d\n", width);
+ printf ("image height = %d\n", height);
+
+ data.stream = arv_camera_create_stream (data.camera, NULL, NULL);
+ if (data.stream != NULL) {
+ g_signal_connect (data.stream, "new-buffer", G_CALLBACK (new_buffer_cb), &data);
+ arv_stream_set_emit_signals (data.stream, TRUE);
+
+ for (i = 0; i < N_BUFFERS; i++)
+ arv_stream_push_buffer (data.stream, arv_buffer_new (payload, NULL));
+
+ arv_camera_set_acquisition_mode (data.camera, ARV_ACQUISITION_MODE_CONTINUOUS);
+ arv_camera_start_acquisition (data.camera);
+
+ data.main_loop = g_main_loop_new (NULL, FALSE);
+
+ old_sigint_handler = signal (SIGINT, set_cancel);
+
+ g_timeout_add_seconds (1, periodic_task_cb, &data);
+ g_timeout_add (197, switch_roi, &data);
+
+ g_main_loop_run (data.main_loop);
+
+ signal (SIGINT, old_sigint_handler);
+
+ g_main_loop_unref (data.main_loop);
+
+ arv_stream_get_statistics (data.stream, &n_completed_buffers, &n_failures,
&n_underruns);
+
+ printf ("Completed buffers = %Lu\n", (unsigned long long) n_completed_buffers);
+ printf ("Failures = %Lu\n", (unsigned long long) n_failures);
+ printf ("Underruns = %Lu\n", (unsigned long long) n_underruns);
+
+ arv_camera_stop_acquisition (data.camera);
+
+ g_object_unref (data.stream);
+ } else
+ printf ("Can't create stream thread (check if the device is not already used)\n");
+
+ g_object_unref (data.camera);
+ } else
+ printf ("No camera found\n");
+
+ return 0;
+}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]