Skip to content
Snippets Groups Projects
Commit 928e639d authored by Angel Santamaria-Navarro's avatar Angel Santamaria-Navarro
Browse files

prepared to work with external device manager to have several cameras

parent b016a5e7
No related branches found
No related tags found
No related merge requests found
#include "mvbluefox3.h" #include "mvbluefox3.h"
#include <boost/timer.hpp>
#include <unistd.h> #include <unistd.h>
#include <sstream>
#ifdef HAVE_OPENCV_H #ifdef HAVE_OPENCV_H
#include <opencv2/core/version.hpp> #include <opencv2/core/version.hpp>
#if CV_MAJOR_VERSION == 3 #if CV_MAJOR_VERSION == 3
...@@ -9,7 +10,7 @@ ...@@ -9,7 +10,7 @@
#endif #endif
#endif #endif
#define WINDOW_NAME "mvBlueFOX3 TEST" typedef bool( *SUPPORTED_DEVICE_CHECK )( const mvIMPACT::acquire::Device* const );
mvIMPACT::acquire::DeviceManager devMgr_; // Device Manager. mvIMPACT::acquire::DeviceManager devMgr_; // Device Manager.
...@@ -20,52 +21,122 @@ std::string GetSerialFromUser(void) ...@@ -20,52 +21,122 @@ std::string GetSerialFromUser(void)
return getDeviceFromUserInput(devMgr)->serial.read(); return getDeviceFromUserInput(devMgr)->serial.read();
} }
std::string AvailableDevices(SUPPORTED_DEVICE_CHECK pSupportedDeviceCheckFn)
{
mvIMPACT::acquire::DeviceManager devMgr; // Device Manager.
std::ostringstream devices;
devices << "Available device(s): ";
const unsigned int devCnt = devMgr.deviceCount();
if (devCnt == 0)
{
devices << "0.";
}
else
{
for( unsigned int i = 0; i < devCnt; i++ )
{
Device* pDev = devMgr_[i];
if( pDev )
{
if( !pSupportedDeviceCheckFn || pSupportedDeviceCheckFn( pDev ) )
{
devices << " \n - " << pDev->product.read() << ": " << pDev->serial.read();
}
}
}
}
return devices.str();
}
int main(int argc, char *argv[]) int main(int argc, char *argv[])
{ {
CMvbluefox3::CMvbluefox3* cam_ptr = NULL; int num_cams = 2;
std::vector<std::string> serial;
serial.resize(num_cams);
serial[0] = "F0300141";
serial[1] = "F0300123";
#if defined(HAVE_OPENCV_H) && CV_MAJOR_VERSION == 3
std::vector<std::string> window_name;
window_name.resize(num_cams);
window_name[0] = serial[0];
window_name[1] = serial[1];
#endif
std::vector<CMvbluefox3::CMvbluefox3*> cam_ptr;
cam_ptr.resize(num_cams);
for (int ii = 0; ii < num_cams; ++ii)
{
cam_ptr[ii] = NULL;
if( !serial[ii].empty() )
{
std::cout << "[mvBlueFOX3]: Trying to open device with serial: " << serial[ii] << std::endl;
if (devMgr_.getDeviceBySerial(serial[ii]) == 0)
{
std::cout << "No device found! Unable to continue. " << std::endl;
}
else
{
// create an interface to the found device
cam_ptr[ii] = new CMvbluefox3::CMvbluefox3(devMgr_.getDeviceBySerial(serial[ii]));
}
}
else
std::cout << "Device cannot be found because serial number is not specified." << std::endl;
}
try { try {
// cam_ptr = new CMvbluefox3::CMvbluefox3(GetSerialFromUser());
cam_ptr = new CMvbluefox3::CMvbluefox3("F0300141",devMgr_);
CMvbluefox3::CParams params; //default parameters. for (int ii = 0; ii < num_cams; ++ii)
cam_ptr->SetConfig(params); {
CMvbluefox3::CParams params; //default parameters.
cam_ptr[ii]->SetConfig(params);
}
#if defined(HAVE_OPENCV_H) && CV_MAJOR_VERSION == 3 #if defined(HAVE_OPENCV_H) && CV_MAJOR_VERSION == 3
std::cout << "[Camera test]: Acquiring images." << std::endl; std::cout << "[Camera test]: Acquiring images." << std::endl;
cv::namedWindow( WINDOW_NAME, cv::WINDOW_NORMAL ); for (int ii = 0; ii < num_cams; ++ii)
cv::namedWindow( window_name[ii], cv::WINDOW_NORMAL );
boost::timer t;
double duration;
while (true) while (true)
{ {
t.restart(); for (int ii = 0; ii < num_cams; ++ii)
cv::Mat image; {
cam_ptr->GetImageCV(image); cv::Mat image;
cv::imshow( WINDOW_NAME, image ); cam_ptr[ii]->GetImageCV(image);
cv::imshow( window_name[ii], image );
}
if(cv::waitKey(30) >= 0) break; if(cv::waitKey(30) >= 0) break;
std::cout << '\r' << "fps:" << 1.0/t.elapsed() << std::flush;
} }
std::cout << std::endl;
cv::destroyAllWindows(); cv::destroyAllWindows();
#else #else
char *image=NULL;
cam_ptr->GetImage(&image); for (int ii = 0; ii < num_cams; ++ii)
std::cout << "[Camera test]: Frame acquired successfully." {
<< "OpenCV 3 is required and not installed, thus visualization is avoided." << std::endl; char *image=NULL;
delete [] image; cam_ptr[ii]->GetImage(&image);
std::cout << "[Camera test]: CAM: " << serial[ii] << ". Frame acquired successfully." << "OpenCV 3 is required and not installed, thus visualization is avoided." << std::endl;
delete [] image;
}
#endif #endif
std::cout << "[Camera test]: Finished successfully." << std::endl; std::cout << "[Camera test]: Finished successfully." << std::endl;
}catch (CMvbluefox3::CmvBlueFOX3Exception& e) { }catch (CMvbluefox3::CmvBlueFOX3Exception& e) {
std::cout << e.what() << std::endl; std::cout << e.what() << std::endl;
} }
if (cam_ptr != NULL) for (int ii = 0; ii < num_cams; ++ii)
{ {
cam_ptr = NULL; if (cam_ptr[ii] != NULL)
delete [] cam_ptr; {
cam_ptr[ii] = NULL;
delete [] cam_ptr[ii];
}
} }
} }
...@@ -17,40 +17,18 @@ ...@@ -17,40 +17,18 @@
namespace CMvbluefox3 { namespace CMvbluefox3 {
CMvbluefox3::CMvbluefox3(const std::string &serial, const mvIMPACT::acquire::DeviceManager &dMan): devMgr_(dMan) CMvbluefox3::CMvbluefox3(const mvIMPACT::acquire::Device *device)
{ {
if( !serial.empty() ) // Initialize vars
{ this->device_ = new mvIMPACT::acquire::Device(*device);
std::cout << "[mvBlueFOX3]: Trying to open device with serial: " << serial << std::endl; this->timeout_ms_ = -1;
this->linepitch_ = 8;
// if (this->devMgr_.getDeviceBySerial(serial) == 0) this->depth_ = 8;
if (devMgr_.getDeviceBySerial(serial) == 0) this->bytes_per_pixel_ = 1;
{
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_ = devMgr_[0];
// Initialize other vars
this->timeout_ms_ = -1;
this->linepitch_ = 8;
this->depth_ = 8;
this->bytes_per_pixel_ = 1;
// displayPropertyData(this->device_->defaultRequestCount); OpenDevice();
// WriteProperty(this->device_->defaultRequestCount,1);
// open device
OpenDevice(serial);
}
}
else
throw CmvBlueFOX3Exception(_HERE_, "Device cannot be found because serial number is not specified.");
} }
CMvbluefox3::~CMvbluefox3() CMvbluefox3::~CMvbluefox3()
{ {
// Close device if necessary. // Close device if necessary.
...@@ -69,35 +47,7 @@ CMvbluefox3::~CMvbluefox3() ...@@ -69,35 +47,7 @@ CMvbluefox3::~CMvbluefox3()
DelPtr(this->stats_); DelPtr(this->stats_);
} }
std::string CMvbluefox3::AvailableDevices(SUPPORTED_DEVICE_CHECK pSupportedDeviceCheckFn) const void CMvbluefox3::OpenDevice(void)
{
std::ostringstream devices;
devices << "Available device(s): ";
// const unsigned int devCnt = this->devMgr_.deviceCount();
const unsigned int devCnt = devMgr_.deviceCount();
if (devCnt == 0)
{
devices << "0.";
}
else
{
for( unsigned int i = 0; i < devCnt; i++ )
{
// Device* pDev = this->devMgr_[i];
Device* pDev = devMgr_[i];
if( pDev )
{
if( !pSupportedDeviceCheckFn || pSupportedDeviceCheckFn( pDev ) )
{
devices << " \n - " << pDev->product.read() << ": " << pDev->serial.read();
}
}
}
}
return devices.str();
}
void CMvbluefox3::OpenDevice(const std::string &serial)
{ {
// Open the device // Open the device
try { this->device_->open(); } try { this->device_->open(); }
......
...@@ -13,8 +13,6 @@ namespace cv { class Mat; } ...@@ -13,8 +13,6 @@ namespace cv { class Mat; }
namespace CMvbluefox3 { namespace CMvbluefox3 {
typedef bool( *SUPPORTED_DEVICE_CHECK )( const mvIMPACT::acquire::Device* const );
/** /**
* \brief Camera parameters * \brief Camera parameters
* *
...@@ -173,19 +171,12 @@ class CMvbluefox3 ...@@ -173,19 +171,12 @@ class CMvbluefox3
} }
} }
/**
* \brief Available Device
*
* Returns a string with currently available devices.
*/
std::string AvailableDevices(SUPPORTED_DEVICE_CHECK pSupportedDeviceCheckFn = 0) const;
/** /**
* \brief Open device * \brief Open device
* *
* Open device. * Open device.
*/ */
void OpenDevice(const std::string &serial); void OpenDevice(void);
/** /**
* \brief Get image request format * \brief Get image request format
...@@ -366,7 +357,7 @@ class CMvbluefox3 ...@@ -366,7 +357,7 @@ class CMvbluefox3
* *
* Class constructor. * Class constructor.
*/ */
CMvbluefox3(const std::string &serial, const mvIMPACT::acquire::DeviceManager &dMan); CMvbluefox3(const mvIMPACT::acquire::Device *device);
/** /**
* \brief Class destructor * \brief Class destructor
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment