summaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
authorVolker Kaiser <volker.kaiser@softwareschneiderei.de>2012-04-24 08:53:21 +0200
committerVolker Kaiser <volker.kaiser@softwareschneiderei.de>2012-07-26 15:36:43 +0200
commitb5c90a21f289bb67c4806a8563d96fc674bba583 (patch)
tree604d4f0ad4ac6e6c8ebec639995ce02f1a15f4e6 /test
parent642a047ce60c9e071b9815d11ea9a81761598c9c (diff)
downloaduca-b5c90a21f289bb67c4806a8563d96fc674bba583.tar.gz
uca-b5c90a21f289bb67c4806a8563d96fc674bba583.tar.bz2
uca-b5c90a21f289bb67c4806a8563d96fc674bba583.tar.xz
uca-b5c90a21f289bb67c4806a8563d96fc674bba583.zip
pylon (basler) camera added
Diffstat (limited to 'test')
-rw-r--r--test/CMakeLists.txt12
-rw-r--r--test/grab.c3
-rw-r--r--test/grab_pylon.c95
3 files changed, 109 insertions, 1 deletions
diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt
index 9050ce5..f6ca865 100644
--- a/test/CMakeLists.txt
+++ b/test/CMakeLists.txt
@@ -16,6 +16,18 @@ configure_file(${CMAKE_CURRENT_SOURCE_DIR}/control.glade ${CMAKE_CURRENT_BINARY_
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/run.py ${CMAKE_CURRENT_BINARY_DIR})
# --- Build targets -----------------------------------------------------------
+#add_executable(enum enum.c)
+add_executable(grab grab.c)
+add_executable(grab_pylon grab_pylon.c)
+#add_executable(grab-async grab-async.c)
+#add_executable(benchmark benchmark.c)
+
+#target_link_libraries(enum uca)
+target_link_libraries(grab uca-gobject ${GLIB2_LIBRARIES} ${GOBJECT2_LIBRARIES})
+target_link_libraries(grab_pylon uca-gobject ${GLIB2_LIBRARIES} ${GOBJECT2_LIBRARIES})
+#target_link_libraries(grab-async uca)
+#target_link_libraries(benchmark uca)
+
include_directories(
${GLIB2_INCLUDE_DIRS}
${GOBJECT2_INCLUDE_DIRS}
diff --git a/test/grab.c b/test/grab.c
index a4d4aa3..41e6d88 100644
--- a/test/grab.c
+++ b/test/grab.c
@@ -114,7 +114,7 @@ int main(int argc, char *argv[])
uca_camera_start_recording(camera, &error);
g_assert_no_error(error);
- while (counter < 2) {
+ while (counter < 5) {
g_print(" grab frame ... ");
g_timer_start(timer);
uca_camera_grab(camera, &buffer, &error);
@@ -131,6 +131,7 @@ int main(int argc, char *argv[])
FILE *fp = fopen(filename, "wb");
fwrite(buffer, roi_width * roi_height, pixel_size, fp);
fclose(fp);
+ g_usleep(2 * G_USEC_PER_SEC);
}
g_print("Stop recording\n");
diff --git a/test/grab_pylon.c b/test/grab_pylon.c
new file mode 100644
index 0000000..cb1e534
--- /dev/null
+++ b/test/grab_pylon.c
@@ -0,0 +1,95 @@
+/* Copyright (C) 2011, 2012 Matthias Vogelgesang <matthias.vogelgesang@kit.edu>
+ (Karlsruhe Institute of Technology)
+
+ This library is free software; you can redistribute it and/or modify it
+ under the terms of the GNU Lesser General Public License as published by the
+ Free Software Foundation; either version 2.1 of the License, or (at your
+ option) any later version.
+
+ This library is distributed in the hope that it will be useful, but WITHOUT
+ ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
+ FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
+ details.
+
+ You should have received a copy of the GNU Lesser General Public License along
+ with this library; if not, write to the Free Software Foundation, Inc., 51
+ Franklin St, Fifth Floor, Boston, MA 02110, USA */
+
+#include <glib-object.h>
+#include <signal.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include "uca-camera.h"
+
+#define handle_error(errno) {if ((errno) != UCA_NO_ERROR) printf("error at <%s:%i>\n", \
+ __FILE__, __LINE__);}
+
+static UcaCamera *camera = NULL;
+
+void sigint_handler(int signal)
+{
+ printf("Closing down libuca\n");
+ uca_camera_stop_recording(camera, NULL);
+ g_object_unref(camera);
+ exit(signal);
+}
+
+int main(int argc, char *argv[])
+{
+ GError *error = NULL;
+ (void) signal(SIGINT, sigint_handler);
+
+ g_type_init();
+ camera = uca_camera_new("pylon", &error);
+
+ if (camera == NULL) {
+ g_print("Couldn't initialize camera\n");
+ return 1;
+ }
+
+ guint width, height, bits;
+ g_object_get(G_OBJECT(camera),
+ "sensor-width", &width,
+ "sensor-height", &height,
+ "sensor-bitdepth", &bits,
+ NULL);
+
+ const int pixel_size = bits == 8 ? 1 : 2;
+ gpointer buffer = g_malloc0(width * height * pixel_size);
+
+ gchar filename[FILENAME_MAX];
+
+ for (int i = 0; i < 2; i++) {
+ gint counter = 0;
+ g_print("Start recording\n");
+ uca_camera_start_recording(camera, &error);
+ g_assert_no_error(error);
+
+ while (counter < 50) {
+ g_print(" grab frame ... ");
+ uca_camera_grab(camera, &buffer, &error);
+ if (error != NULL) {
+ g_print("\nError: %s\n", error->message);
+ goto cleanup;
+ }
+ g_print("done\n");
+
+ snprintf(filename, FILENAME_MAX, "frame-%08i.raw", counter++);
+ FILE *fp = fopen(filename, "wb");
+ fwrite(buffer, width*height, pixel_size, fp);
+ fclose(fp);
+ //g_usleep(2 * G_USEC_PER_SEC);
+ }
+
+ g_print("Stop recording\n");
+ uca_camera_stop_recording(camera, &error);
+ g_assert_no_error(error);
+ }
+
+cleanup:
+ uca_camera_stop_recording(camera, NULL);
+ g_object_unref(camera);
+ g_free(buffer);
+
+ return error != NULL ? 1 : 0;
+}