From 38d6d18e83b0c33a18ef6f68c22c161d39abc449 Mon Sep 17 00:00:00 2001 From: Volker Kaiser Date: Tue, 8 May 2012 14:49:11 +0200 Subject: basler camera works --- CMakeLists.txt | 2 ++ cmake/FindPylon.cmake | 2 +- src/CMakeLists.txt | 7 ++++--- src/cameras/pylon_camera.cpp | 34 +++++++++++----------------------- src/cameras/uca-pylon-camera.c | 20 +++++++++++--------- src/cameras/uca-pylon-camera.h | 1 - test/grab_pylon.c | 3 ++- 7 files changed, 31 insertions(+), 38 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 91f0d14..c0685ba 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,6 +1,8 @@ cmake_minimum_required(VERSION 2.8) project(uca) +set(CMAKE_VERBOSE_MAKEFILE TRUE) + set(TARNAME "libuca") set(UCA_VERSION_MAJOR "0") set(UCA_VERSION_MINOR "6") diff --git a/cmake/FindPylon.cmake b/cmake/FindPylon.cmake index f446df2..142f432 100644 --- a/cmake/FindPylon.cmake +++ b/cmake/FindPylon.cmake @@ -43,5 +43,5 @@ pkg_check_modules(BASLER_PYLON baslerpylon>=0.1.0 REQUIRED) MESSAGE(LIBRARY_DIRS ${BASLER_PYLON_LIBRARY_DIRS}) find_library(BASLERPYLON_LIB baslerpylon PATHS ${BASLER_PYLON_LIBRARY_DIRS}) -#set (PYLON_LIBS ${PYLON_LIBS} ${BASLERPYLON_LIB}) +set (PYLON_LIBS ${PYLON_LIBS} ${BASLERPYLON_LIB}) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 5a3c014..9630a72 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -15,14 +15,14 @@ set(cameras) set(CMAKE_MODULE_PATH ${CMAKE_SOURCE_DIR}/cmake) # --- Find camera interfaces -#find_package(PCO) +find_package(PCO) find_package(PF) find_package(IPE) find_package(Pylon) # --- Find frame grabber interfaces -#find_package(FgLib5) -#find_package(ClSerMe4) +find_package(FgLib5) +find_package(ClSerMe4) # --- Miscellanous packages find_package(PkgConfig) @@ -101,6 +101,7 @@ if (PYLON_FOUND) set(uca_LIBS ${uca_LIBS} ${PYLON_LIBS}) include_directories(${PYLON_INCLUDE_DIRS}) + link_directories(/opt/pylon/lib64) endif() endif() diff --git a/src/cameras/pylon_camera.cpp b/src/cameras/pylon_camera.cpp index eafcf06..d27b6c4 100644 --- a/src/cameras/pylon_camera.cpp +++ b/src/cameras/pylon_camera.cpp @@ -8,24 +8,19 @@ namespace { GrabAPI::IGrabber* pGrabber = 0; - //yat::Mutex* pImageMutex = NULL; - //yat::Condition* pImageCondition = NULL; - //yat::Mutex pImageMutex; - //yat::Condition pImageCondition(pImageMutex); + yat::Mutex pImageMutex; + yat::Condition pImageCondition(pImageMutex); guint imageCounter = 0; guint currentImage = 0; GrabAPI::Image* image = NULL; void handle_image(GrabAPI::Image* newImage) { - //g_assert(pImageMutex); - //g_assert(pImageCondition); - //yat::MutexLock lock(pImageMutex); + yat::MutexLock lock(pImageMutex); delete image; image = newImage; imageCounter++; - std::cerr << "signal next image ready " << std::endl; - //pImageCondition.signal(); + pImageCondition.signal(); } void yat_exception_to_gerror(const yat::Exception& e, GError** error) @@ -70,13 +65,9 @@ namespace { void pylon_camera_new(const char* lib_path, const char* camera_ip, GError** error) { - g_assert(!pGrabber); try { - //pImageMutex = new yat::Mutex; - //pImageCondition = new yat::Condition(*pImageMutex); - yat::PlugInManager pm; std::pair pp = pm.load((std::string(lib_path) + "/libbaslerpylon.so").c_str()); @@ -91,7 +82,6 @@ void pylon_camera_new(const char* lib_path, const char* camera_ip, GError** erro pGrabber->initialize(); pGrabber->set_image_handler(GrabAPI::ImageHandlerCallback::instanciate(handle_image)); pGrabber->open(); - } catch (const yat::Exception& e) { yat_exception_to_gerror(e, error); @@ -146,6 +136,7 @@ void pylon_camera_get_sensor_size(guint* width, guint* height, GError** error) void pylon_camera_get_bit_depth(guint* depth, GError** error) { + std::cerr << __func__ << std::endl; g_assert(pGrabber); try { @@ -162,11 +153,10 @@ void pylon_camera_get_bit_depth(guint* depth, GError** error) void pylon_camera_start_acquision(GError** error) { g_assert(pGrabber); - //g_assert(pImageMutex); try { { - //yat::MutexLock lock(pImageMutex); + yat::MutexLock lock(pImageMutex); imageCounter = 0; currentImage = 0; } @@ -194,24 +184,22 @@ void pylon_camera_stop_acquision(GError** error) void pylon_camera_grab(gpointer *data, GError** error) { g_assert(pGrabber); - //g_assert(pImageMutex); - //g_assert(pImageCondition); - sleep(1); try { - //yat::MutexLock lock(pImageMutex); + yat::MutexLock lock(pImageMutex); g_assert(currentImage <= imageCounter); while (currentImage == imageCounter) { std::cerr << "wait for next image... " << currentImage << std::endl; - //pImageCondition.wait(); + pImageCondition.wait(); } - std::cerr << "grab next image " << currentImage << ", " << imageCounter << std::endl; + std::cerr << "grab next image " << currentImage << ", " << imageCounter + << "; width: " << image->width() << ", height: " << image->height() << std::endl; g_assert(currentImage < imageCounter); currentImage = imageCounter; - //memcpy(*data, image->base(), image->width() * image->height() * 2); + memcpy(*data, image->base(), image->width() * image->height() * 2); } catch (const yat::Exception& e) diff --git a/src/cameras/uca-pylon-camera.c b/src/cameras/uca-pylon-camera.c index 82380bc..1bc8ee2 100644 --- a/src/cameras/uca-pylon-camera.c +++ b/src/cameras/uca-pylon-camera.c @@ -77,8 +77,6 @@ static GParamSpec *pylon_properties[N_PROPERTIES] = { NULL, }; struct _UcaPylonCameraPrivate { - guint frame_width; - guint frame_height; guint bit_depth; gsize num_bytes; @@ -99,6 +97,11 @@ UcaPylonCamera *uca_pylon_camera_new(GError **error) return NULL; } + pylon_camera_get_sensor_size(&priv->width, &priv->height, error); + if (*error) { + g_print("Error when calling pylon_camera_get_sensor_size %s\n", (*error)->message); + return NULL; + } return camera; } @@ -115,7 +118,6 @@ static void uca_pylon_camera_start_recording(UcaCamera *camera, GError **error) static void uca_pylon_camera_stop_recording(UcaCamera *camera, GError **error) { g_return_if_fail(UCA_IS_PYLON_CAMERA(camera)); - UcaPylonCameraPrivate *priv = UCA_PYLON_CAMERA_GET_PRIVATE(camera); pylon_camera_stop_acquision(error); } @@ -125,14 +127,14 @@ static void uca_pylon_camera_grab(UcaCamera *camera, gpointer *data, GError **er UcaPylonCameraPrivate *priv = UCA_PYLON_CAMERA_GET_PRIVATE(camera); if (*data == NULL) { - *data = g_malloc0(priv->frame_width * priv->frame_height * priv->num_bytes); + *data = g_malloc0(priv->width * priv->height * priv->num_bytes); } pylon_camera_grab(data, error); } static void uca_pylon_camera_set_property(GObject *object, guint property_id, const GValue *value, GParamSpec *pspec) { - UcaPylonCameraPrivate *priv = UCA_PYLON_CAMERA_GET_PRIVATE(object); + /*UcaPylonCameraPrivate *priv = UCA_PYLON_CAMERA_GET_PRIVATE(object);*/ switch (property_id) { default: @@ -143,7 +145,7 @@ static void uca_pylon_camera_set_property(GObject *object, guint property_id, co static void uca_pylon_camera_get_property(GObject *object, guint property_id, GValue *value, GParamSpec *pspec) { - printf("pylon_get_property\n"); + fprintf(stderr, "pylon_get_property\n"); UcaPylonCameraPrivate *priv = UCA_PYLON_CAMERA_GET_PRIVATE(object); GError* error = NULL; @@ -152,13 +154,13 @@ static void uca_pylon_camera_get_property(GObject *object, guint property_id, GV case PROP_SENSOR_WIDTH: pylon_camera_get_sensor_size(&priv->width, &priv->height, &error); g_value_set_uint(value, priv->width); - printf("pylon_get_property sensor width %d\n", priv->width); + g_print("pylon_get_property sensor width %d\n", priv->width); break; case PROP_SENSOR_HEIGHT: pylon_camera_get_sensor_size(&priv->width, &priv->height, &error); g_value_set_uint(value, priv->height); - printf("pylon_get_property sensor height %d\n", priv->height); + g_print("pylon_get_property sensor height %d\n", priv->height); break; /* @@ -170,7 +172,7 @@ static void uca_pylon_camera_get_property(GObject *object, guint property_id, GV case PROP_SENSOR_BITDEPTH: pylon_camera_get_bit_depth(&priv->bit_depth, &error); g_value_set_uint(value, priv->bit_depth); - printf("pylon_get_property depth %d\n", priv->bit_depth); + g_print("pylon_get_property depth %d\n", priv->bit_depth); break; /* diff --git a/src/cameras/uca-pylon-camera.h b/src/cameras/uca-pylon-camera.h index 2f441dc..eebf63c 100644 --- a/src/cameras/uca-pylon-camera.h +++ b/src/cameras/uca-pylon-camera.h @@ -19,7 +19,6 @@ #define __UCA_PYLON_CAMERA_H #include - #include "uca-camera.h" G_BEGIN_DECLS diff --git a/test/grab_pylon.c b/test/grab_pylon.c index cb1e534..2f9b5a0 100644 --- a/test/grab_pylon.c +++ b/test/grab_pylon.c @@ -55,6 +55,7 @@ int main(int argc, char *argv[]) NULL); const int pixel_size = bits == 8 ? 1 : 2; + g_print("allocate buffer %u, %u, %d\n", width, height, pixel_size); gpointer buffer = g_malloc0(width * height * pixel_size); gchar filename[FILENAME_MAX]; @@ -65,7 +66,7 @@ int main(int argc, char *argv[]) uca_camera_start_recording(camera, &error); g_assert_no_error(error); - while (counter < 50) { + while (counter < 10) { g_print(" grab frame ... "); uca_camera_grab(camera, &buffer, &error); if (error != NULL) { -- cgit v1.2.3