From 75191e8f2fc11fc2ebb570cbad82f0b1c8647c63 Mon Sep 17 00:00:00 2001 From: Alexander Smorkalov Date: Fri, 1 Feb 2013 16:40:02 +0400 Subject: [PATCH] Smartek Giganetix Cameras support (Patch #2192) integrated to master. --- CMakeLists.txt | 5 + cmake/OpenCVFindLibsVideo.cmake | 13 + modules/highgui/CMakeLists.txt | 8 + .../highgui/include/opencv2/highgui/highgui_c.h | 13 +- modules/highgui/src/cap.cpp | 13 + modules/highgui/src/cap_giganetix.cpp | 763 +++++++++++++++++++++ modules/highgui/src/precomp.hpp | 1 + modules/highgui/test/test_precomp.hpp | 1 + 8 files changed, 816 insertions(+), 1 deletion(-) create mode 100644 modules/highgui/src/cap_giganetix.cpp diff --git a/CMakeLists.txt b/CMakeLists.txt index 45bc8f2..60baf26 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -129,6 +129,7 @@ OCV_OPTION(WITH_OPENGL "Include OpenGL support" OFF OCV_OPTION(WITH_OPENNI "Include OpenNI support" OFF IF (NOT ANDROID AND NOT IOS) ) OCV_OPTION(WITH_PNG "Include PNG support" ON IF (NOT IOS) ) OCV_OPTION(WITH_PVAPI "Include Prosilica GigE support" ON IF (NOT ANDROID AND NOT IOS) ) +OCV_OPTION(WITH_GIGEAPI "Include Smartek GigE support" ON IF (NOT ANDROID AND NOT IOS) ) OCV_OPTION(WITH_QT "Build with Qt Backend support" OFF IF (NOT ANDROID AND NOT IOS) ) OCV_OPTION(WITH_QUICKTIME "Use QuickTime for Video I/O insted of QTKit" OFF IF APPLE ) OCV_OPTION(WITH_TBB "Include Intel TBB support" OFF IF (NOT IOS) ) @@ -705,6 +706,10 @@ if(DEFINED WITH_PVAPI) status(" PvAPI:" HAVE_PVAPI THEN YES ELSE NO) endif(DEFINED WITH_PVAPI) +if(DEFINED WITH_GIGEAPI) + status(" GigEVisionSDK:" HAVE_GIGE_API THEN YES ELSE NO) +endif(DEFINED WITH_GIGEAPI) + if(DEFINED WITH_QUICKTIME) status(" QuickTime:" WITH_QUICKTIME THEN YES ELSE NO) status(" QTKit:" WITH_QUICKTIME THEN NO ELSE YES) diff --git a/cmake/OpenCVFindLibsVideo.cmake b/cmake/OpenCVFindLibsVideo.cmake index 6827fa9..4149185 100644 --- a/cmake/OpenCVFindLibsVideo.cmake +++ b/cmake/OpenCVFindLibsVideo.cmake @@ -56,6 +56,19 @@ if(WITH_PVAPI) endif(PVAPI_INCLUDE_PATH) endif(WITH_PVAPI) +# --- GigEVisionSDK --- +ocv_clear_vars(HAVE_GIGE_API) +if(WITH_GIGEAPI) + find_path(GIGEAPI_INCLUDE_PATH "GigEVisionSDK.h" + PATHS /usr/local /var /opt /usr ENV ProgramFiles ENV ProgramW6432 + PATH_SUFFIXES include "Smartek Vision Technologies/GigEVisionSDK/gige_cpp" "GigEVisionSDK/gige_cpp" "GigEVisionSDK/gige_c" + DOC "The path to Smartek GigEVisionSDK header") + FIND_LIBRARY(GIGEAPI_LIBRARIES NAMES GigEVisionSDK) + if(GIGEAPI_LIBRARIES AND GIGEAPI_INCLUDE_PATH) + set(HAVE_GIGE_API TRUE) + endif() +endif(WITH_GIGEAPI) + # --- Dc1394 --- ocv_clear_vars(HAVE_DC1394 HAVE_DC1394_2) if(WITH_1394) diff --git a/modules/highgui/CMakeLists.txt b/modules/highgui/CMakeLists.txt index 6e1c53c..f893490 100644 --- a/modules/highgui/CMakeLists.txt +++ b/modules/highgui/CMakeLists.txt @@ -171,6 +171,14 @@ if(HAVE_PVAPI) list(APPEND HIGHGUI_LIBRARIES ${PVAPI_LIBRARY}) endif() +if(HAVE_GIGE_API) + add_definitions(-DHAVE_GIGE_API) + ocv_include_directories(${GIGEAPI_INCLUDE_PATH}) + set(highgui_srcs src/cap_giganetix.cpp ${highgui_srcs}) + list(APPEND HIGHGUI_LIBRARIES ${GIGEAPI_LIBRARIES}) + list(APPEND highgui_srcs src/cap_giganetix.cpp) +endif(HAVE_GIGE_API) + if(WITH_AVFOUNDATION) add_definitions(-DHAVE_AVFOUNDATION=1) list(APPEND highgui_srcs src/cap_avfoundation.mm) diff --git a/modules/highgui/include/opencv2/highgui/highgui_c.h b/modules/highgui/include/opencv2/highgui/highgui_c.h index deeae42..9c7166f 100644 --- a/modules/highgui/include/opencv2/highgui/highgui_c.h +++ b/modules/highgui/include/opencv2/highgui/highgui_c.h @@ -307,7 +307,9 @@ enum CV_CAP_XIAPI =1100, // XIMEA Camera API - CV_CAP_AVFOUNDATION = 1200 // AVFoundation framework for iOS (OS X Lion will have the same API) + CV_CAP_AVFOUNDATION = 1200, // AVFoundation framework for iOS (OS X Lion will have the same API) + + CV_CAP_GIGANETIX = 1300 // Smartek Giganetix GigEVisionSDK }; /* start capturing frames from camera: index = camera_index + domain_offset (CV_CAP_*) */ @@ -454,6 +456,15 @@ enum CV_CAP_PROP_IOS_DEVICE_FLASH = 9003, CV_CAP_PROP_IOS_DEVICE_WHITEBALANCE = 9004, CV_CAP_PROP_IOS_DEVICE_TORCH = 9005 + + // Properties of cameras available through Smartek Giganetix Ethernet Vision interface + /* --- Vladimir Litvinenko (litvinenko.vladimir@gmail.com) --- */ + ,CV_CAP_PROP_GIGA_FRAME_OFFSET_X = 10001, + CV_CAP_PROP_GIGA_FRAME_OFFSET_Y = 10002, + CV_CAP_PROP_GIGA_FRAME_WIDTH_MAX = 10003, + CV_CAP_PROP_GIGA_FRAME_HEIGH_MAX = 10004, + CV_CAP_PROP_GIGA_FRAME_SENS_WIDTH = 10005, + CV_CAP_PROP_GIGA_FRAME_SENS_HEIGH = 10006 }; enum diff --git a/modules/highgui/src/cap.cpp b/modules/highgui/src/cap.cpp index 57a2156..03c819f 100644 --- a/modules/highgui/src/cap.cpp +++ b/modules/highgui/src/cap.cpp @@ -150,6 +150,9 @@ CV_IMPL CvCapture * cvCreateCameraCapture (int index) #ifdef HAVE_AVFOUNDATION CV_CAP_AVFOUNDATION, #endif +#ifdef HAVE_GIGE_API + CV_CAP_GIGANETIX, +#endif -1 }; @@ -184,6 +187,7 @@ CV_IMPL CvCapture * cvCreateCameraCapture (int index) defined(HAVE_XIMEA) || \ defined(HAVE_AVFOUNDATION) || \ defined(HAVE_ANDROID_NATIVE_CAMERA) || \ + defined(HAVE_GIGE_API) || \ (0) // local variable to memorize the captured device CvCapture *capture; @@ -320,6 +324,15 @@ CV_IMPL CvCapture * cvCreateCameraCapture (int index) return capture; break; #endif + +#ifdef HAVE_GIGE_API + case CV_CAP_GIGANETIX: + capture = cvCreateCameraCapture_Giganetix (index); + if (capture) + return capture; + break; // CV_CAP_GIGANETIX +#endif + } } diff --git a/modules/highgui/src/cap_giganetix.cpp b/modules/highgui/src/cap_giganetix.cpp new file mode 100644 index 0000000..ccbe702 --- /dev/null +++ b/modules/highgui/src/cap_giganetix.cpp @@ -0,0 +1,763 @@ +//////////////////////////////////////////////////////////////////////////////////////// +// +// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING. +// +// By downloading, copying, installing or using the software you agree to this license. +// If you do not agree to this license, do not download, install, +// copy or use the software. +// +// +// Intel License Agreement +// For Open Source Computer Vision Library +// +// Copyright (C) 2000, Intel Corporation, all rights reserved. +// Third party copyrights are property of their respective owners. +// +// Redistribution and use in source and binary forms, with or without modification, +// are permitted provided that the following conditions are met: +// +// * Redistribution's of source code must retain the above copyright notice, +// this list of conditions and the following disclaimer. +// +// * Redistribution's in binary form must reproduce the above copyright notice, +// this list of conditions and the following disclaimer in the documentation +// and/or other materials provided with the distribution. +// +// * The name of Intel Corporation may not be used to endorse or promote products +// derived from this software without specific prior written permission. +// +// This software is provided by the copyright holders and contributors "as is" and +// any express or implied warranties, including, but not limited to, the implied +// warranties of merchantability and fitness for a particular purpose are disclaimed. +// In no event shall the Intel Corporation or contributors be liable for any direct, +// indirect, incidental, special, exemplary, or consequential damages +// (including, but not limited to, procurement of substitute goods or services; +// loss of use, data, or profits; or business interruption) however caused +// and on any theory of liability, whether in contract, strict liability, +// or tort (including negligence or otherwise) arising in any way out of +// the use of this software, even if advised of the possibility of such damage. +// +// + +// +// The code has been contributed by Vladimir N. Litvinenko on 2012 Jul +// mailto:vladimir.litvinenko@codepaint.ru +// + +#include "precomp.hpp" +#include +#include + +#ifdef WIN32 +#include +#else +#include +#endif + +#ifdef NDEBUG +#define CV_WARN(message) +#else +#define CV_WARN(message) fprintf(stderr, "warning: %s (%s:%d)\n", message, __FILE__, __LINE__) +#endif + +#define QTGIG_HEARTBEAT_TIME (12000.0) +#define QTGIG_MAX_WAIT_TIME (2.0) +#define QTGIG_IMG_WAIT_TIME (3.0) + +/*----------------------------------------------------------------------------*/ +/** + \internal + \fn bool wrprInitGigEVisionAPI(); + \brief Wrapper to GigEVisionAPI function gige::InitGigEVisionAPI () + \return true -- success + See \a wrprExitGigEVisionAPI + +*/ +bool +wrprInitGigEVisionAPI() +{ + CV_FUNCNAME("wrprInitGigEVisionAPI"); + __BEGIN__; + + try { + gige::InitGigEVisionAPI (); + } catch(...) { + CV_ERROR(CV_StsError, "GigEVisionAPI: initialization (InitGigEVisionAPI()) failed.\n"); + } + __END__; + return true; +} + +/*----------------------------------------------------------------------------*/ +/** + \internal + \fn void wrprExitGigEVisionAPI() + \brief Wrapper to GigEVisionAPI function gige::ExitGigEVisionAPI () + \return true -- success + See \a wrprInitGigEVisionAPI + +*/ +bool +wrprExitGigEVisionAPI() +{ + CV_FUNCNAME("wrprExitGigEVisionAPI"); + __BEGIN__; + + try { + gige::ExitGigEVisionAPI (); + } catch(...) { + CV_ERROR(CV_StsError, "GigEVisionAPI: finalization (ExitGigEVisionAPI()) failed.\n"); + return false; + } + __END__; + return true; +} + + +/*----------------------------------------------------------------------------*/ +/** + \internal + \fn gige::IGigEVisionAPI wrprGetGigEVisionAPI() + \brief Wrapper to GigEVisionAPI function gige::GetGigEVisionAPI () + \return item of gige::IGigEVisionAPI type + See \a wrprInitGigEVisionAPI, \a gige::IGigEVisionAPI +*/ +gige::IGigEVisionAPI +wrprGetGigEVisionAPI() +{ + + gige::IGigEVisionAPI b_ret = 0; + + CV_FUNCNAME("wrprGetGigEVisionAPI"); + __BEGIN__; + + try { + b_ret = gige::GetGigEVisionAPI (); + } catch(...) { + CV_ERROR(CV_StsError, "GigEVisionAPI: API instance (from GetGigEVisionAPI()) failed.\n"); + } + + __END__; + + return b_ret; +} + + +/*----------------------------------------------------------------------------*/ +/** + \internal + \fn bool wrprUnregisterCallback( const gige::IGigEVisionAPI* api, gige::ICallbackEvent* eventHandler) + \brief Wrapper to GigEVisionAPI function + \param api + \param eventHandler + \return true - succsess, else - false + See \a wrprInitGigEVisionAPI, \a gige::IGigEVisionAPI + +*/ +bool +wrprUnregisterCallback( const gige::IGigEVisionAPI* api, gige::ICallbackEvent* eventHandler) +{ + bool b_ret = api != NULL; + + if(b_ret) b_ret = api->IsValid (); + + CV_FUNCNAME("wrprUnregisterCallback"); + __BEGIN__; + + if(b_ret) + { + if(eventHandler != NULL) + { + try { + b_ret = ((gige::IGigEVisionAPIInterface*)api)->UnregisterCallback (eventHandler); + } catch(...) { + CV_ERROR(CV_StsError, "GigEVisionAPI: API unregister callback function (from UnregisterCallback()) failed.\n"); + b_ret = false; + } + } + } + __END__; + + return (b_ret); +} + + +/*----------------------------------------------------------------------------*/ +/** + \internal + \fn bool wrprDeviceIsConnect( gige::IDevice& device ) + \brief Wrapper to GigEVisionAPI function IDevice::IsConnected() + \param device - selected device + \return true - device connected +*/ +bool +wrprDeviceIsConnect( gige::IDevice& device ) +{ + bool b_ret = device != NULL; + + CV_FUNCNAME("wrprDeviceIsConnect"); + __BEGIN__; + + if(b_ret) + { + try { + b_ret = device->IsConnected (); + } catch (...) { + CV_ERROR(CV_StsError, "GigEVisionAPI: API device connection state (from IsConnected()) failed.\n"); + b_ret = false; + } + } + __END__; + + return (b_ret); +} + + +/*----------------------------------------------------------------------------*/ +/** + \internal + \fn bool wrprDeviceIsValid( gige::IDevice& device ) + \brief Wrapper to GigEVisionAPI function IDevice::Connect() + \param device - selected device + \return true - device valid + +*/ +bool +wrprDeviceIsValid( gige::IDevice& device ) +{ + bool b_ret = device != NULL; + + CV_FUNCNAME("wrprDeviceIsConnect"); + __BEGIN__; + + if(b_ret) + { + try { + b_ret = device.IsValid (); + } catch (...) { + CV_ERROR(CV_StsError, "GigEVisionAPI: API device validation state (from IsValid()) failed.\n"); + b_ret = false; + } + } + __END__; + + return (b_ret); +} + + +/*----------------------------------------------------------------------------*/ +/** + \internal + \fn bool wrprDeviceDisconnect ( gige::IDevice& device ) + \brief Wrapper to GigEVisionAPI function IDevice::Disconnect() + \param device - selected device + \return true - device valid + +*/ +bool +wrprDeviceDisconnect ( gige::IDevice& device ) +{ + bool b_ret = device != NULL; + + CV_FUNCNAME("wrprDeviceDisconnect"); + __BEGIN__; + + if(b_ret) + { + try { + device->Disconnect (); + } catch (...) { + CV_ERROR(CV_StsError, "GigEVisionAPI: API device disconnect (from Disconnect()) failed.\n"); + b_ret = false; + } + } + + __END__; + + return (b_ret); +} + + +/*----------------------------------------------------------------------------*/ +/*----------------------------------------------------------------------------*/ +/** + \internal + \class CvCaptureCAM_Giganetix + \brief Capturing video from camera via Smartec Giganetix (use GigEVisualSDK library). +*/ + +class CvCaptureCAM_Giganetix : public CvCapture +{ + public: + CvCaptureCAM_Giganetix(); + virtual ~CvCaptureCAM_Giganetix(); + + virtual bool open( int index ); + virtual void close(); + virtual double getProperty(int); + virtual bool setProperty(int, double); + virtual bool grabFrame(); + virtual IplImage* retrieveFrame(int); + virtual int getCaptureDomain() + { + return CV_CAP_GIGANETIX; + } + + bool start (); + bool stop (); + + protected: + + void init (); + void grabImage (); + + gige::IGigEVisionAPI m_api; + bool m_api_on; + gige::IDevice m_device; + bool m_active; + + IplImage* m_raw_image; + UINT32 m_rawImagePixelType; + bool m_monocrome; + +}; +/*----------------------------------------------------------------------------*/ +/*----------------------------------------------------------------------------*/ +void +CvCaptureCAM_Giganetix::init () +{ + m_monocrome = m_active = m_api_on = false; + m_api = 0; + m_device = 0; + m_raw_image = 0; + m_rawImagePixelType = 0; +} + +/*----------------------------------------------------------------------------*/ +CvCaptureCAM_Giganetix::CvCaptureCAM_Giganetix() +{ + init (); + + m_api_on = wrprInitGigEVisionAPI (); + + if(m_api_on) + { + if((m_api = wrprGetGigEVisionAPI ()) != NULL) + { + m_api->SetHeartbeatTime (QTGIG_HEARTBEAT_TIME); + } + } +} + +/*----------------------------------------------------------------------------*/ +CvCaptureCAM_Giganetix::~CvCaptureCAM_Giganetix() +{ + close(); +} +/*----------------------------------------------------------------------------*/ +void +CvCaptureCAM_Giganetix::close() +{ + stop (); + + (void)wrprDeviceDisconnect(m_device); + + (void)wrprExitGigEVisionAPI (); + + if(m_raw_image) cvReleaseImageHeader(&m_raw_image); + + init (); +} + +/*----------------------------------------------------------------------------*/ +bool +CvCaptureCAM_Giganetix::open( int index ) +{ + bool b_ret = m_api_on; + + CV_FUNCNAME("CvCaptureCAM_Giganetix::open"); + __BEGIN__; + + if(b_ret) + b_ret = m_api.IsValid (); + + if(b_ret ) + { + m_api->FindAllDevices (QTGIG_MAX_WAIT_TIME); + + //TODO - serch device as DevicesList member + gige::DevicesList DevicesList = m_api->GetAllDevices (); + + m_device = 0; + b_ret = false; + + for (int i = 0; i < (int) DevicesList.size() && !b_ret; i++) + { + if((b_ret = i == index)) + { + m_device = DevicesList[i]; + b_ret = m_device->Connect (); + + if(b_ret) + { + b_ret = + m_device->SetStringNodeValue("AcquisitionStatusSelector", "AcquisitionActive") + && + m_device->SetStringNodeValue ("TriggerMode", "Off") + && + m_device->SetStringNodeValue ("AcquisitionMode", "Continuous") + && + m_device->SetIntegerNodeValue ("AcquisitionFrameCount", 20) + ; + } + } + } // for + } + + if(!b_ret) + { + CV_ERROR(CV_StsError, "Giganetix: Error cannot find camera\n"); + close (); + } else { + start (); + } + + __END__; + + return b_ret; +} + +/*----------------------------------------------------------------------------*/ +void +CvCaptureCAM_Giganetix::grabImage () +{ + CV_FUNCNAME("CvCaptureCAM_Giganetix::grabImage"); + __BEGIN__; + + if(wrprDeviceIsValid(m_device) && wrprDeviceIsConnect(m_device)) + { + if(!m_device->IsBufferEmpty ()) + { + gige::IImageInfo imageInfo; + m_device->GetImageInfo (&imageInfo); + assert(imageInfo.IsValid()); + + if (m_device->GetPendingImagesCount() == 1) + { + UINT32 newPixelType; + UINT32 newWidth, newHeight; + + imageInfo->GetPixelType(newPixelType); + imageInfo->GetSize(newWidth, newHeight); + + //TODO - validation of image exists + bool b_validation = m_raw_image != NULL; + if(b_validation) + { + b_validation = + m_raw_image->imageSize == (int)(imageInfo->GetRawDataSize ()) + && + m_rawImagePixelType == newPixelType; + } else { + if(m_raw_image) cvReleaseImageHeader(&m_raw_image); + } + + m_rawImagePixelType = newPixelType; + m_monocrome = GvspGetBitsPerPixel((GVSP_PIXEL_TYPES)newPixelType) == IPL_DEPTH_8U; + + try { + if (m_monocrome) + { + //TODO - For Mono & Color BayerRGB raw pixel types + if (!b_validation) + { + m_raw_image = cvCreateImageHeader (cvSize((int)newWidth, (int)newHeight),IPL_DEPTH_8U,1); + m_raw_image->origin = IPL_ORIGIN_TL; + m_raw_image->dataOrder = IPL_DATA_ORDER_PIXEL; + m_raw_image->widthStep = newWidth; + } + // Copy image. + // ::memcpy(m_raw_image->imageData, imageInfo->GetRawData (), imageInfo->GetRawDataSize ()); + + //TODO - Set pointer to image ! + m_raw_image->imageData = (char*)(imageInfo->GetRawData ()); + } + + if (!m_monocrome && newPixelType == GVSP_PIX_RGB8_PACKED) + { + //TODO - 24 bit RGB color image. + if (!b_validation) + { + m_raw_image = cvCreateImageHeader (cvSize((int)newWidth, (int)newHeight), IPL_DEPTH_32F, 3); + m_raw_image->origin = IPL_ORIGIN_TL; + m_raw_image->dataOrder = IPL_DATA_ORDER_PIXEL; + m_raw_image->widthStep = newWidth * 3; + } + m_raw_image->imageData = (char*)(imageInfo->GetRawData ()); + } + } catch (...) { + CV_ERROR(CV_StsError, "Giganetix: failed to queue a buffer on device\n"); + close (); + } + } else { + //TODO - all other pixel types + m_raw_image = 0; + CV_WARN("Giganetix: Undefined image pixel type\n"); + } + m_device->PopImage (imageInfo); + m_device->ClearImageBuffer (); + } + } + + __END__; +} + +/*----------------------------------------------------------------------------*/ +bool +CvCaptureCAM_Giganetix::start () +{ + CV_FUNCNAME("CvCaptureCAM_Giganetix::start"); + __BEGIN__; + + m_active = wrprDeviceIsValid(m_device) && wrprDeviceIsConnect(m_device); + + if(m_active) + { + (void)m_device->SetIntegerNodeValue("TLParamsLocked", 1); + (void)m_device->CommandNodeExecute("AcquisitionStart"); + m_active = m_device->GetBooleanNodeValue("AcquisitionStatus", m_active); + } + + if(!m_active) + { + CV_ERROR(CV_StsError, "Giganetix: Cannot open camera\n"); + close (); + } + + __END__; + + return m_active; +} + +/*----------------------------------------------------------------------------*/ +bool +CvCaptureCAM_Giganetix::stop () +{ + if (!m_active) return true; + + CV_FUNCNAME("CvCaptureCAM_Giganetix::stop"); + __BEGIN__; + + if(wrprDeviceIsValid(m_device) && wrprDeviceIsConnect(m_device)) + { + (void)m_device->GetBooleanNodeValue("AcquisitionStatus", m_active); + + if(m_active) + { + (void)m_device->CommandNodeExecute("AcquisitionStop"); + (void)m_device->SetIntegerNodeValue("TLParamsLocked", 0); + m_device->ClearImageBuffer (); + (void)m_device->GetBooleanNodeValue("AcquisitionStatus", m_active); + } + } + + if(m_active) + { + CV_ERROR(CV_StsError, "Giganetix: Improper closure of the camera\n"); + close (); + } + __END__; + + return !m_active; +} + +/*----------------------------------------------------------------------------*/ +bool +CvCaptureCAM_Giganetix::grabFrame() +{ + bool b_ret = + wrprDeviceIsValid(m_device) + && + wrprDeviceIsConnect(m_device); + + if(b_ret) grabImage (); + + return b_ret; +} + + +/*----------------------------------------------------------------------------*/ +IplImage* +CvCaptureCAM_Giganetix::retrieveFrame(int) +{ + return ( + wrprDeviceIsValid(m_device) && wrprDeviceIsConnect(m_device) ? + m_raw_image : + NULL + ); +} + +/*----------------------------------------------------------------------------*/ +double +CvCaptureCAM_Giganetix::getProperty( int property_id ) +{ + double d_ret = -1.0; + INT64 i; + + if(wrprDeviceIsConnect(m_device)) + { + switch ( property_id ) + { + case CV_CAP_PROP_FRAME_WIDTH: + m_device->GetIntegerNodeValue ("Width", i); + d_ret = i; + break; + case CV_CAP_PROP_FRAME_HEIGHT: + m_device->GetIntegerNodeValue ("Height", i); + d_ret = i; + break; + case CV_CAP_PROP_GIGA_FRAME_OFFSET_X: + m_device->GetIntegerNodeValue ("OffsetX", i); + d_ret = i; + break; + case CV_CAP_PROP_GIGA_FRAME_OFFSET_Y: + m_device->GetIntegerNodeValue ("OffsetY", i); + d_ret = i; + break; + case CV_CAP_PROP_GIGA_FRAME_WIDTH_MAX: + m_device->GetIntegerNodeValue ("WidthMax", i); + d_ret = i; + break; + case CV_CAP_PROP_GIGA_FRAME_HEIGH_MAX: + m_device->GetIntegerNodeValue ("HeightMax", i); + d_ret = i; + break; + case CV_CAP_PROP_GIGA_FRAME_SENS_WIDTH: + m_device->GetIntegerNodeValue ("SensorWidth", i); + d_ret = i; + break; + case CV_CAP_PROP_GIGA_FRAME_SENS_HEIGH: + m_device->GetIntegerNodeValue ("SensorHeight", i); + d_ret = i; + break; + case CV_CAP_PROP_FRAME_COUNT: + m_device->GetIntegerNodeValue ("AcquisitionFrameCount", i); + d_ret = i; + break; + case CV_CAP_PROP_EXPOSURE: + m_device->GetFloatNodeValue ("ExposureTime",d_ret); + break; + case CV_CAP_PROP_GAIN : + m_device->GetFloatNodeValue ("Gain",d_ret); + break; + case CV_CAP_PROP_TRIGGER : + bool b; + m_device->GetBooleanNodeValue ("TriggerMode",b); + d_ret = (double)b; + break; + case CV_CAP_PROP_TRIGGER_DELAY : + m_device->GetFloatNodeValue ("TriggerDelay",d_ret); + break; + default : ; + } + } + + return d_ret; +} + +/*----------------------------------------------------------------------------*/ +bool +CvCaptureCAM_Giganetix::setProperty( int property_id, double value ) +{ + bool b_ret = wrprDeviceIsConnect(m_device); + + if(b_ret) + { + bool b_val = m_active; + + switch ( property_id ) + { + case CV_CAP_PROP_FRAME_WIDTH: + stop (); + b_ret = m_device->SetIntegerNodeValue ("Width", (INT64)value); + if(b_val) start (); + break; + case CV_CAP_PROP_GIGA_FRAME_WIDTH_MAX: + stop (); + b_ret = m_device->SetIntegerNodeValue ("WidthMax", (INT64)value); + if(b_val) start (); + break; + case CV_CAP_PROP_GIGA_FRAME_SENS_WIDTH: + stop (); + b_ret = m_device->SetIntegerNodeValue ("SensorWidth", (INT64)value); + if(b_val) start (); + break; + case CV_CAP_PROP_FRAME_HEIGHT: + stop (); + b_ret = m_device->SetIntegerNodeValue ("Height", (INT64)value); + if(b_val) start (); + break; + case CV_CAP_PROP_GIGA_FRAME_HEIGH_MAX: + stop (); + b_ret = m_device->SetIntegerNodeValue ("HeightMax", (INT64)value); + if(b_val) start (); + break; + case CV_CAP_PROP_GIGA_FRAME_SENS_HEIGH: + stop (); + b_ret = m_device->SetIntegerNodeValue ("SensorHeight", (INT64)value); + if(b_val) start (); + break; + case CV_CAP_PROP_GIGA_FRAME_OFFSET_X: { + INT64 w, wmax, val = (INT64)value; + if((b_ret = m_device->GetIntegerNodeValue ("Width", w))) + if((b_ret = m_device->GetIntegerNodeValue ("WidthMax", wmax))) + b_ret = m_device->SetIntegerNodeValue ("OffsetX", val w > wmax ? wmax - w : val); + } break; + case CV_CAP_PROP_GIGA_FRAME_OFFSET_Y: { + INT64 h, hmax, val = (INT64)value; + if((b_ret = m_device->GetIntegerNodeValue ("Height", h))) + if((b_ret = m_device->GetIntegerNodeValue ("HeightMax", hmax))) + b_ret = m_device->SetIntegerNodeValue ("OffsetY", val h > hmax ? hmax - h : val); + b_ret = m_device->SetIntegerNodeValue ("OffsetY", (INT64)value); + } + break; + case CV_CAP_PROP_EXPOSURE: + b_ret = m_device->SetFloatNodeValue ("ExposureTime",value); + break; + case CV_CAP_PROP_GAIN : + b_ret = m_device->SetFloatNodeValue ("Gain",value); + break; + case CV_CAP_PROP_TRIGGER : + b_ret = m_device->SetBooleanNodeValue ("TriggerMode",(bool)value); + break; + case CV_CAP_PROP_TRIGGER_DELAY : + stop (); + b_ret = m_device->SetFloatNodeValue ("TriggerDelay",value); + if(b_val) start (); + break; + default: + b_ret = false; + } + } + + return b_ret; +} + + +/*----------------------------------------------------------------------------*/ +/*----------------------------------------------------------------------------*/ +CvCapture* +cvCreateCameraCapture_Giganetix( int index ) +{ + CvCaptureCAM_Giganetix* capture = new CvCaptureCAM_Giganetix; + + if (!(capture->open( index ))) + { + delete capture; + capture = NULL; + } + + return ((CvCapture*)capture); +} + +/*----------------------------------------------------------------------------*/ diff --git a/modules/highgui/src/precomp.hpp b/modules/highgui/src/precomp.hpp index b683fd6..9572e30 100644 --- a/modules/highgui/src/precomp.hpp +++ b/modules/highgui/src/precomp.hpp @@ -115,6 +115,7 @@ CvCapture * cvCreateCameraCapture_V4L( int index ); CvCapture * cvCreateCameraCapture_DC1394( int index ); CvCapture * cvCreateCameraCapture_DC1394_2( int index ); CvCapture* cvCreateCameraCapture_MIL( int index ); +CvCapture* cvCreateCameraCapture_Giganetix( int index ); CvCapture * cvCreateCameraCapture_CMU( int index ); CV_IMPL CvCapture * cvCreateCameraCapture_TYZX( int index ); CvCapture* cvCreateFileCapture_Win32( const char* filename ); diff --git a/modules/highgui/test/test_precomp.hpp b/modules/highgui/test/test_precomp.hpp index 133d95d..3286c0f 100644 --- a/modules/highgui/test/test_precomp.hpp +++ b/modules/highgui/test/test_precomp.hpp @@ -34,6 +34,7 @@ defined(HAVE_OPENNI) || \ defined(HAVE_XIMEA) || \ defined(HAVE_AVFOUNDATION) || \ + defined(HAVE_GIGE_API) || \ (0) //defined(HAVE_ANDROID_NATIVE_CAMERA) || - enable after #1193 # define BUILD_WITH_CAMERA_SUPPORT 1 -- 2.7.4