summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorVolker Kaiser <volker.kaiser@softwareschneiderei.de>2012-08-01 14:06:50 +0200
committerVolker Kaiser <volker.kaiser@softwareschneiderei.de>2012-08-01 14:06:50 +0200
commit0b5720d0414f7e9f196664677899e999179a49f6 (patch)
treefb070d27abbbe0dccc23a85b34ce1b6239c4222b
parent7c5a0bdefd27180da32aaaf9b1331c69c66e1693 (diff)
downloadlibuca-0b5720d0414f7e9f196664677899e999179a49f6.tar.gz
libuca-0b5720d0414f7e9f196664677899e999179a49f6.tar.bz2
libuca-0b5720d0414f7e9f196664677899e999179a49f6.tar.xz
libuca-0b5720d0414f7e9f196664677899e999179a49f6.zip
extracted pylon_camera C-wrapper into own project; enhanced cmake build for pylon cameras
-rw-r--r--cmake/FindPylon.cmake55
-rw-r--r--src/CMakeLists.txt9
-rw-r--r--src/cameras/pylon_camera.cpp289
-rw-r--r--src/cameras/pylon_camera.h32
-rw-r--r--src/cameras/uca-pylon-camera.c2
-rw-r--r--test/CMakeLists.txt14
6 files changed, 39 insertions, 362 deletions
diff --git a/cmake/FindPylon.cmake b/cmake/FindPylon.cmake
index 142f432..be3ce85 100644
--- a/cmake/FindPylon.cmake
+++ b/cmake/FindPylon.cmake
@@ -3,45 +3,30 @@
#
# Defines
#
-# PCO_FOUND - system has libpco
-# PCO_INCLUDE_DIRS - libpco include directory
-# PCO_LIBRARIES - pco library
+# PYLON_FOUND - system has libpco
+# PYLON_INCLUDE_DIR - libpco include directory
+# PYLON_LIB - pco library
-find_package(YAT)
+# check for environment variable PYLON_ROOT
+message("DEFINED PYLON ROOT $ENV{PYLON_ROOT}")
+if (NOT "$ENV{PYLON_ROOT}" STREQUAL "")
+ message("PYLON_ROOT=$ENV{PYLON_ROOT}")
+ set(ENV{LD_LIBRARY_PATH} "$ENV{LD_LIBRARY_PATH}:$ENV{PYLON_ROOT}/lib")
+ set(ENV{LD_LIBRARY_PATH} "$ENV{LD_LIBRARY_PATH};$ENV{PYLON_ROOT}/lib64")
+ set(ENV{LD_LIBRARY_PATH} "$ENV{LD_LIBRARY_PATH};$ENV{PYLON_ROOT}/genicam/bin/Linux64_x64")
+ set(ENV{LD_LIBRARY_PATH} "$ENV{LD_LIBRARY_PATH};$ENV{PYLON_ROOT}/genicam/bin/Linux32_i86")
-find_package(PackageHandleStandardArgs)
-find_path(PYLON_DIRS include/pylon/PylonBase.h HINTS /opt/pylon ENV PYLON_ROOT)
-set(GENICAM_ROOT ${PYLON_DIRS}/genicam)
-set(PYLON_INCLUDE_DIRS ${PYLON_DIRS}/include ${GENICAM_ROOT}/library/CPP/include)
+ find_package(YAT)
+ find_package(PackageHandleStandardArgs)
-# check for 32/64 bit
-if (CMAKE_SIZEOF_VOID_P EQUAL 8)
- set(PYLON_LIB_DIRS ${PYLON_DIRS}/lib64 ${PYLON_DIRS}/bin ${GENICAM_ROOT}/bin/Linux64_x64
- ${GENICAM_ROOT}/bin/Linux64_x64/GenApi/Generic)
-else()
- set(PYLON_LIB_DIRS ${PYLON_DIRS}/lib64 ${PYLON_DIRS}/bin ${GENICAM_ROOT}/bin/Linux32_i86
- ${GENICAM_ROOT}/bin/Linux32_i86/GenApi/Generic)
-endif()
-
-find_library(PYLONBASE_LIB pylonbase PATHS ${PYLON_LIB_DIRS})
-find_library(PYLONUTILITY_LIB pylonutility PATHS ${PYLON_LIB_DIRS})
-find_library(PYLONGIGESUPP_LIB pylongigesupp PATHS ${PYLON_LIB_DIRS})
-find_library(GENAPI_LIB GenApi_gcc40_v2_1 PATHS ${PYLON_LIB_DIRS})
-find_library(GCBASE_LIB GCBase_gcc40_v2_1 PATHS ${PYLON_LIB_DIRS})
-set (PYLON_LIBS ${PYLONBASE_LIB}
- ${PYLONUTILITY_LIB}
- ${PYLONGIGESUPP_LIB}
- ${GENAPI_LIB}
- ${GCBASE_LIB}
- ${YAT_LIB})
+ find_path(PYLON_INCLUDE_DIR libpyloncam/pylon_camera.h)
+ find_library(PYLON_LIB pyloncam)
-find_package_handle_standard_args(PYLON DEFAULT_MSG PYLON_LIBS PYLON_INCLUDE_DIRS)
+ message("INCLUDE ${PYLON_INCLUDE_DIR}")
-find_package(PkgConfig)
-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})
+ find_package_handle_standard_args(PYLON DEFAULT_MSG PYLON_LIB PYLON_INCLUDE_DIR)
+else()
+ message("Environment variable PYLON_ROOT not found! => unable to build pylon camera support")
+endif()
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index 931ca9b..13d677a 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -15,7 +15,7 @@ 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)
@@ -96,13 +96,12 @@ if (PYLON_FOUND)
option(HAVE_PYLON_CAMERA "Camera: Pylon based (Basler)" ON)
if (HAVE_PYLON_CAMERA)
- list(APPEND uca_SRCS cameras/uca-pylon-camera.c cameras/pylon_camera.cpp)
+ list(APPEND uca_SRCS cameras/uca-pylon-camera.c)
list(APPEND uca_HDRS cameras/uca-pylon-camera.h)
list(APPEND cameras "Pylon")
- set(uca_LIBS ${uca_LIBS} ${PYLON_LIBS})
+ set(uca_LIBS ${uca_LIBS} ${PYLON_LIB})
- include_directories(${PYLON_INCLUDE_DIRS})
- link_directories(/opt/pylon/lib64)
+ include_directories(${PYLON_INCLUDE_DIR})
endif()
endif()
diff --git a/src/cameras/pylon_camera.cpp b/src/cameras/pylon_camera.cpp
deleted file mode 100644
index 094e3c8..0000000
--- a/src/cameras/pylon_camera.cpp
+++ /dev/null
@@ -1,289 +0,0 @@
-
-#include "pylon_camera.h"
-#include <yat/plugin/PlugInManager.h>
-#include <yat/threading/Condition.h>
-#include <baslerpylon/IGrabber.h>
-#include <iostream>
-
-namespace {
-
- GrabAPI::IGrabber* pGrabber = 0;
- yat::Mutex pImageMutex;
- yat::Condition pImageCondition(pImageMutex);
- guint imageCounter = 0;
- guint currentImage = 0;
- GrabAPI::Image* image = NULL;
- guint bytesPerPixel = 0;
-
- void handle_image(GrabAPI::Image* newImage)
- {
- yat::MutexLock lock(pImageMutex);
- delete image;
- image = newImage;
- imageCounter++;
- pImageCondition.signal();
- }
-
- void yat_exception_to_gerror(const yat::Exception& e, GError** error)
- {
- if (e.errors.size() == 2)
- {
- g_set_error(error, 0, 0,
- "%s : %s : %s\n%s : %s : %s",
- e.errors[0].reason.c_str(),
- e.errors[0].desc.c_str(),
- e.errors[0].origin.c_str(),
- e.errors[1].reason.c_str(),
- e.errors[1].desc.c_str(),
- e.errors[1].origin.c_str());
- return;
- }
- if (e.errors.size() == 3)
- {
- g_set_error(error, 0, 0,
- "%s : %s : %s\n%s : %s : %s\n%s : %s : %s",
- e.errors[0].reason.c_str(),
- e.errors[0].desc.c_str(),
- e.errors[0].origin.c_str(),
- e.errors[1].reason.c_str(),
- e.errors[1].desc.c_str(),
- e.errors[1].origin.c_str(),
- e.errors[2].reason.c_str(),
- e.errors[2].desc.c_str(),
- e.errors[2].origin.c_str());
- return;
- }
-
- g_set_error(error, 0, 0,
- "%s : %s : %s",
- e.errors[0].reason.c_str(),
- e.errors[0].desc.c_str(),
- e.errors[0].origin.c_str());
- }
-
-}
-
-
-void pylon_camera_new(const char* lib_path, const char* camera_ip, GError** error)
-{
- g_assert(!pGrabber);
- try {
-
- yat::PlugInManager pm;
- std::pair<yat::IPlugInInfo*, yat::IPlugInFactory*> pp =
- pm.load((std::string(lib_path) + "/libbaslerpylon.so").c_str());
-
- yat::IPlugInObject* plugin_obj = 0;
- pp.second->create(plugin_obj);
- pGrabber = static_cast<GrabAPI::IGrabber*>(plugin_obj);
-
- yat::PlugInPropValues values;
- values["CameraIP"] = yat::Any(std::string(camera_ip));
- pGrabber->set_properties(values);
- pGrabber->initialize();
- pGrabber->set_image_handler(GrabAPI::ImageHandlerCallback::instanciate(handle_image));
- pGrabber->open();
- }
- catch (const yat::Exception& e) {
- yat_exception_to_gerror(e, error);
- }
-}
-
-void pylon_camera_set_exposure_time(gdouble exp_time, GError** error)
-{
- g_assert(pGrabber);
- try
- {
- pGrabber->set_exposure_time(yat::Any(exp_time));
- }
- catch (const yat::Exception& e)
- {
- yat_exception_to_gerror(e, error);
- }
-}
-
-void pylon_camera_get_exposure_time(gdouble* exp_time, GError** error)
-{
- g_assert(pGrabber);
- try
- {
- yat::Any exp_time_result;
- pGrabber->get_exposure_time(exp_time_result);
- *exp_time = yat::any_cast<gdouble>(exp_time_result);
- }
- catch (const yat::Exception& e)
- {
- yat_exception_to_gerror(e, error);
- }
-}
-
-
-void pylon_camera_get_sensor_size(guint* width, guint* height, GError** error)
-{
- g_assert(pGrabber);
- try
- {
- yat::Any w, h;
- pGrabber->get_sensor_width(w);
- pGrabber->get_sensor_height(h);
- *width = yat::any_cast<yat_int32_t>(w);
- *height = yat::any_cast<yat_int32_t>(h);
- }
- catch (const yat::Exception& e)
- {
- yat_exception_to_gerror(e, error);
- }
-}
-
-void pylon_camera_get_bit_depth(guint* depth, GError** error)
-{
- g_assert(pGrabber);
- try
- {
- yat::Any bit_depth_result;
- pGrabber->get_bit_depth(bit_depth_result);
- *depth = yat::any_cast<yat_int32_t>(bit_depth_result);
- }
- catch (const yat::Exception& e)
- {
- yat_exception_to_gerror(e, error);
- }
-}
-
-void pylon_camera_get_roi(guint16* roi_x, guint16* roi_y, guint16* roi_width, guint16* roi_height, GError** error)
-{
- g_assert(pGrabber);
- g_assert(roi_x);
- g_assert(roi_y);
- g_assert(roi_width);
- g_assert(roi_height);
- try
- {
- GrabAPI::ROI roi = pGrabber->get_roi();
- *roi_x = roi.x;
- *roi_y = roi.y;
- *roi_width = roi.width;
- *roi_height = roi.height;
- }
- catch (const yat::Exception& e)
- {
- yat_exception_to_gerror(e, error);
- }
-}
-
-void pylon_camera_set_roi(guint16 roi_x, guint16 roi_y, guint16 roi_width, guint16 roi_height, GError** error)
-{
- g_assert(pGrabber);
- try
- {
- GrabAPI::ROI roi(roi_x, roi_y, roi_width, roi_height);
- pGrabber->set_roi(roi);
- }
- catch (const yat::Exception& e)
- {
- yat_exception_to_gerror(e, error);
- }
-}
-
-void pylon_camera_get_gain(gint* gain, GError** error)
-{
- g_assert(pGrabber);
- try
- {
- yat::Any gain_result;
- pGrabber->get_gain(gain_result);
- *gain = yat::any_cast<gint>(gain_result);
- }
- catch (const yat::Exception& e)
- {
- yat_exception_to_gerror(e, error);
- }
-}
-
-void pylon_camera_set_gain(gint gain, GError** error)
-{
- g_assert(pGrabber);
- try
- {
- pGrabber->set_gain(yat::Any(gain));
- }
- catch (const yat::Exception& e)
- {
- yat_exception_to_gerror(e, error);
- }
-}
-
-void pylon_camera_start_acquision(GError** error)
-{
- g_assert(pGrabber);
- guint bit_depth = 0;
- pylon_camera_get_bit_depth(&bit_depth, error);
- bytesPerPixel = 1;
- if (bit_depth > 8) bytesPerPixel = 2;
- if (bit_depth > 16) bytesPerPixel = 3;
- if (bit_depth > 24) bytesPerPixel = 4;
- try
- {
- {
- yat::MutexLock lock(pImageMutex);
- imageCounter = 0;
- currentImage = 0;
- }
- pGrabber->start();
- }
- catch (const yat::Exception& e)
- {
- yat_exception_to_gerror(e, error);
- }
-}
-
-void pylon_camera_stop_acquision(GError** error)
-{
- g_assert(pGrabber);
- try
- {
- pGrabber->stop();
- }
- catch (const yat::Exception& e)
- {
- yat_exception_to_gerror(e, error);
- }
-}
-
-void pylon_camera_grab(gpointer *data, GError** error)
-{
- g_assert(pGrabber);
- try
- {
- yat::MutexLock lock(pImageMutex);
- g_assert(currentImage <= imageCounter);
-
- while (currentImage == imageCounter)
- {
- std::cerr << "wait for next image... " << currentImage << std::endl;
- pImageCondition.wait();
- }
-
- std::cerr << "grab next image " << currentImage << ", " << imageCounter
- << "; width: " << image->width() / bytesPerPixel << ", height: " << image->height() << std::endl;
- g_assert(currentImage < imageCounter);
- currentImage = imageCounter;
- memcpy(*data, image->base(), image->width() * image->height());
-
- }
- catch (const yat::Exception& e)
- {
- yat_exception_to_gerror(e, error);
- }
-}
-
-void pylon_camera_delete()
-{
- if (!pGrabber)
- return;
-
- pGrabber->close();
- pGrabber->uninitialize();
- delete pGrabber;
-}
-
diff --git a/src/cameras/pylon_camera.h b/src/cameras/pylon_camera.h
deleted file mode 100644
index 89b450b..0000000
--- a/src/cameras/pylon_camera.h
+++ /dev/null
@@ -1,32 +0,0 @@
-
-#ifndef _PYLON_CAMERA_H_
-#define _PYLON_CAMERA_H_
-
-#include <glib.h>
-
-G_BEGIN_DECLS
-
-void pylon_camera_new(const gchar* lib_path, const gchar* camera_ip, GError** error);
-
-void pylon_camera_set_exposure_time(gdouble exp_time, GError** error);
-void pylon_camera_get_exposure_time(gdouble* exp_time, GError** error);
-
-void pylon_camera_get_sensor_size(guint* width, guint* height, GError** error);
-void pylon_camera_get_bit_depth(guint* depth, GError** error);
-
-void pylon_camera_get_roi(guint16* roi_x, guint16* roi_y, guint16* roi_width, guint16* roi_height, GError** error);
-void pylon_camera_set_roi(guint16 roi_x, guint16 roi_y, guint16 roi_width, guint16 roi_height, GError** error);
-
-void pylon_camera_get_gain(gint* gain, GError** error);
-void pylon_camera_set_gain(gint gain, GError** error);
-
-void pylon_camera_start_acquision(GError** error);
-void pylon_camera_stop_acquision(GError** error);
-void pylon_camera_grab(gpointer *data, GError** error);
-
-void pylon_camera_delete();
-
-G_END_DECLS
-
-#endif
-
diff --git a/src/cameras/uca-pylon-camera.c b/src/cameras/uca-pylon-camera.c
index 23aa1a3..6fef112 100644
--- a/src/cameras/uca-pylon-camera.c
+++ b/src/cameras/uca-pylon-camera.c
@@ -18,9 +18,9 @@
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
+#include <libpyloncam/pylon_camera.h>
#include "uca-camera.h"
#include "uca-pylon-camera.h"
-#include "pylon_camera.h"
/*#define HANDLE_PYLON_ERROR(err) \
diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt
index 873b85f..36a5fd3 100644
--- a/test/CMakeLists.txt
+++ b/test/CMakeLists.txt
@@ -33,6 +33,20 @@ include_directories(
message("${CMAKE_CURRENT_SOURCE_DIR}")
+if (HAVE_PYLON_CAMERA)
+ set(GENICAM_ROOT $ENV{PYLON_ROOT}/genicam)
+ # check for 32/64 bit
+ if (CMAKE_SIZEOF_VOID_P EQUAL 8)
+ set(PYLON_LIB_DIRS $ENV{PYLON_ROOT}/lib64 $ENV{PYLON_ROOT}/bin ${GENICAM_ROOT}/bin/Linux64_x64
+ ${GENICAM_ROOT}/bin/Linux64_x64/GenApi/Generic)
+ else()
+ set(PYLON_LIB_DIRS $ENV{PYLON_ROOT}/lib64 $ENV{PYLON_ROOT}/bin ${GENICAM_ROOT}/bin/Linux32_i86
+ ${GENICAM_ROOT}/bin/Linux32_i86/GenApi/Generic)
+ endif()
+ message("PYLON LIB DIRS ${PYLON_LIB_DIRS}")
+ link_directories(${PYLON_LIB_DIRS})
+endif()
+
add_executable(grab grab.c)
add_executable(grab-async grab-async.c)