diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 9b713f7ca7e736dc5a17d3d953eb1148cbecabbd..fb4f99d200a90980f640a031e24129f40f60a46b 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -20,19 +20,19 @@ SET( CMAKE_BUILD_TYPE Release) INCLUDE (${PROJECT_SOURCE_DIR}/FindmvIMPACT.cmake) #find the cv support and set HAVE_OPENCV_H for the conditional compilation -FIND_PACKAGE(OpenCV 3.1) +FIND_PACKAGE(OpenCV 2.4) if (OpenCV_FOUND) - if (${OpenCV_VERSION_MAJOR} GREATER 2) + if (${OpenCV_VERSION_MAJOR} GREATER 1) message("-- [INFO] Found OpenCV support") ADD_DEFINITIONS(-DHAVE_OPENCV_H) SET(USE_CV true) - else(${OpenCV_VERSION_MAJOR} GREATER 2) - message("[WARN] OpenCV support not installed. Minimum 3.0 version required. In case of using ROS, consider intalling OpenCV3 within ROS framework.") + else(${OpenCV_VERSION_MAJOR} GREATER 1) + message("[WARN] OpenCV support not installed. Minimum 2.4 version required.") message("[WARN] Current version ${OpenCV_VERSION_MAJOR}") - endif(${OpenCV_VERSION_MAJOR} GREATER 2) + endif(${OpenCV_VERSION_MAJOR} GREATER 1) else(OpenCV_FOUND) - message("[WARN] OpenCV support not installed. Minimum 3.0 version required. In case of using ROS, consider intalling OpenCV3 within ROS framework.") + message("[WARN] OpenCV support not installed. Minimum 2.4 version required.") endif(OpenCV_FOUND) # add the necessary include directories diff --git a/src/examples/CMakeLists.txt b/src/examples/CMakeLists.txt index 6b7ae2f2a0d006b670bc7a73e06a8da2e9f9713f..54d61bac2912aaa67d69b1afc0ff211678dd286d 100644 --- a/src/examples/CMakeLists.txt +++ b/src/examples/CMakeLists.txt @@ -1,8 +1,8 @@ -# add the necessary include directories -INCLUDE_DIRECTORIES(.) - if (USE_CV) + # add the necessary include directories + INCLUDE_DIRECTORIES(. ${mvIMPACT_INCLUDE_DIR}) + # create an example application ADD_EXECUTABLE(mvbluefox3_test mvbluefox3_test.cpp) diff --git a/src/examples/mvbluefox3_test.cpp b/src/examples/mvbluefox3_test.cpp index 6a9fdb3bab4ea0d0cc76a8c03372b54bb09c985a..19db02255606d9915bd26ff6a19258b6eedd04f9 100644 --- a/src/examples/mvbluefox3_test.cpp +++ b/src/examples/mvbluefox3_test.cpp @@ -3,11 +3,17 @@ #include <unistd.h> #ifdef HAVE_OPENCV_H +#include <opencv2/core/version.hpp> +#if CV_MAJOR_VERSION == 3 #include <opencv2/opencv.hpp> #endif +#endif #define WINDOW_NAME "mvBlueFOX3 TEST" +mvIMPACT::acquire::DeviceManager devMgr_; // Device Manager. + + std::string GetSerialFromUser(void) { mvIMPACT::acquire::DeviceManager devMgr; // Device Manager. @@ -20,36 +26,36 @@ int main(int argc, char *argv[]) try { // cam_ptr = new CMvbluefox3::CMvbluefox3(GetSerialFromUser()); - cam_ptr = new CMvbluefox3::CMvbluefox3("F0300141"); + cam_ptr = new CMvbluefox3::CMvbluefox3("F0300141",devMgr_); CMvbluefox3::CParams params; //default parameters. cam_ptr->SetConfig(params); -#ifdef HAVE_OPENCV_H +#if defined(HAVE_OPENCV_H) && CV_MAJOR_VERSION == 3 std::cout << "[Camera test]: Acquiring images." << std::endl; cv::namedWindow( WINDOW_NAME, cv::WINDOW_NORMAL ); -boost::timer t; -double duration; + boost::timer t; + double duration; while (true) { -t.restart(); + t.restart(); cv::Mat image; cam_ptr->GetImageCV(image); cv::imshow( WINDOW_NAME, image ); if(cv::waitKey(30) >= 0) break; -// std::cout << '\r' << "fps:" << 1.0/t.elapsed() << std::flush; + std::cout << '\r' << "fps:" << 1.0/t.elapsed() << std::flush; } -std::cout << std::endl; + std::cout << std::endl; cv::destroyAllWindows(); #else char *image=NULL; cam_ptr->GetImage(&image); std::cout << "[Camera test]: Frame acquired successfully." - << "As no opencv is installed, visualization is avoided." << std::endl; + << "OpenCV 3 is required and not installed, thus visualization is avoided." << std::endl; delete [] image; #endif std::cout << "[Camera test]: Finished successfully." << std::endl; diff --git a/src/mvbluefox3.cpp b/src/mvbluefox3.cpp index 86cc00073385be49b956488b06fb3f911b9e8b82..2fcb41e37b2acd7ce35ed1acfdb375af97331224 100644 --- a/src/mvbluefox3.cpp +++ b/src/mvbluefox3.cpp @@ -13,22 +13,26 @@ // uncomment this line to get more output into the console window //#define VERBOSE_OUTPUT +// mvIMPACT::acquire::DeviceManager devMgr_; // Device Manager. + namespace CMvbluefox3 { -CMvbluefox3::CMvbluefox3(const std::string &serial) +CMvbluefox3::CMvbluefox3(const std::string &serial, const mvIMPACT::acquire::DeviceManager &dMan): devMgr_(dMan) { if( !serial.empty() ) { std::cout << "[mvBlueFOX3]: Trying to open device with serial: " << serial << std::endl; - if (this->devMgr_.getDeviceBySerial(serial) == 0) + // if (this->devMgr_.getDeviceBySerial(serial) == 0) + if (devMgr_.getDeviceBySerial(serial) == 0) { throw CmvBlueFOX3Exception(_HERE_, "No device found! Unable to continue. " + AvailableDevices()); } else { // create an interface to the found device - this->device_ = this->devMgr_[0]; + // this->device_ = this->devMgr_[0]; + this->device_ = devMgr_[0]; // Initialize other vars this->timeout_ms_ = -1; @@ -69,7 +73,8 @@ std::string CMvbluefox3::AvailableDevices(SUPPORTED_DEVICE_CHECK pSupportedDevic { std::ostringstream devices; devices << "Available device(s): "; - const unsigned int devCnt = this->devMgr_.deviceCount(); + // const unsigned int devCnt = this->devMgr_.deviceCount(); + const unsigned int devCnt = devMgr_.deviceCount(); if (devCnt == 0) { devices << "0."; @@ -78,7 +83,8 @@ std::string CMvbluefox3::AvailableDevices(SUPPORTED_DEVICE_CHECK pSupportedDevic { for( unsigned int i = 0; i < devCnt; i++ ) { - Device* pDev = this->devMgr_[i]; + // Device* pDev = this->devMgr_[i]; + Device* pDev = devMgr_[i]; if( pDev ) { if( !pSupportedDeviceCheckFn || pSupportedDeviceCheckFn( pDev ) ) @@ -221,7 +227,6 @@ void CMvbluefox3::GetImageCV(cv::Mat &image) int type = CV_8UC1; switch (this->depth_*this->bytes_per_pixel_) - switch (this->linepitch_) { case 8: type = CV_8UC1; break; case 16: type = CV_8UC2; break; @@ -233,7 +238,7 @@ void CMvbluefox3::GetImageCV(cv::Mat &image) image = cv::Mat(this->params_.height,this->params_.width,type,image_raw); - delete [] image_raw; + DelPtr(image_raw); } #endif diff --git a/src/mvbluefox3.h b/src/mvbluefox3.h index 3f86e7f9c0ff8ea56c6db042fb885b8e6152a933..62daedb94ba978c675a6137464d60ec622203c29 100644 --- a/src/mvbluefox3.h +++ b/src/mvbluefox3.h @@ -366,7 +366,7 @@ class CMvbluefox3 * * Class constructor. */ - CMvbluefox3(const std::string &serial); + CMvbluefox3(const std::string &serial, const mvIMPACT::acquire::DeviceManager &dMan); /** * \brief Class destructor