diff --git a/src/examples/mvbluefox3_test.cpp b/src/examples/mvbluefox3_test.cpp index 9f8317d5e3a098cdda61da5af07d3edc97c83efe..09ebd8417d6c8c53cb8298ee3a5101bd357c025b 100644 --- a/src/examples/mvbluefox3_test.cpp +++ b/src/examples/mvbluefox3_test.cpp @@ -82,36 +82,32 @@ int main(int argc, char *argv[]) window_name[0] = serial[0]; #endif - mvIMPACT::acquire::DeviceManager devMgr_; // Device Manager. + mvIMPACT::acquire::DeviceManager devMgr_; // Device Manager. + std::vector<CMvbluefox3::CMvbluefox3*> cam_ptr; // Device. - 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() ) + try { + + cam_ptr.resize(num_cams); + for (int ii = 0; ii < num_cams; ++ii) { - std::cout << "Trying to open device with serial: " << serial[ii] << std::endl; + cam_ptr[ii] = NULL; - if (devMgr_.getDeviceBySerial(serial[ii]) == 0) + if( !serial[ii].empty() ) { - std::cout << "No device found! Unable to continue. " << std::endl; - } + std::cout << "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]),paramspath); } + else + std::cout << "Device cannot be found because serial number is not specified." << std::endl; } - else - std::cout << "Device cannot be found because serial number is not specified." << std::endl; - } - try { - #if defined(HAVE_OPENCV_H) && CV_MAJOR_VERSION == 3 - std::cout << "Acquiring images. WARNING: depending on OpenCV compilation flags, visualization might experience hard delays (e.g. if \"init done\" appears in the following line)" << std::endl; + + std::cout << "Acquiring images." << std::endl << ">WARNING: depending on OpenCV compilation flags, visualization might experience hard delays (e.g. if \"init done\" appears in the following line)" << std::endl; for (int ii = 0; ii < num_cams; ++ii) cv::namedWindow( window_name[ii], cv::WINDOW_NORMAL ); @@ -128,6 +124,7 @@ int main(int argc, char *argv[]) } cv::destroyAllWindows(); + #else for (int ii = 0; ii < num_cams; ++ii) diff --git a/src/mvbluefox3.cpp b/src/mvbluefox3.cpp index 467a92a6e0cff58c8ded47bd81ef2b8f25b1d7a1..a3f48ebd78caf50310d1211c749d7c31e05c6217 100644 --- a/src/mvbluefox3.cpp +++ b/src/mvbluefox3.cpp @@ -92,9 +92,19 @@ void CMvbluefox3::CloseDevice(void) void CMvbluefox3::LoadSettings(const std::string &path) { - std::cout << "[mvBlueFOX3]: Loading stored settings for " << this->device_->product.readS() << " " << this->device_->serial.readS() << " from path: " << path << "." << std::endl; - this->fi_->loadSetting(path,TStorageFlag(sfFile)); - // this->fi_->loadSetting(path,TStorageFlag(sfFile|sfIgnoreBasicData)); + if (FileExist(path)) + { + std::cout << "[mvBlueFOX3]: Loading stored settings for " << this->device_->product.readS() << " " << this->device_->serial.readS() << " from path: " << path << "." << std::endl; + this->fi_->loadSetting(path,TStorageFlag(sfFile)); + } + else + throw CmvBlueFOX3Exception(_HERE_,"Parameters cannot be loaded because parameters file (XML) does not exist. Check XML file path;" + path); +} + +bool CMvbluefox3::FileExist(const std::string& name) +{ + struct stat buffer; + return (stat (name.c_str(), &buffer) == 0); } std::string CMvbluefox3::GetProduct(void) @@ -164,13 +174,13 @@ void CMvbluefox3::GetImage(char **image) // Lock image access this->image_access_.enter(); + // Get image format + GetImageReqFormat(this->request_); + // Get the image from the buffer. *image = new char[this->request_->imageSize.read()]; memcpy( *image, this->request_->imageData.read(), this->request_->imageSize.read() ); - - // Get image format - GetImageReqFormat(this->request_); - + // Unlock image access this->image_access_.exit(); @@ -227,6 +237,11 @@ void CMvbluefox3::GetImageReqFormat(mvIMPACT::acquire::Request *request) // Line pitch ReadProperty(this->request_->imageLinePitch,this->linepitch_); + // Color filter + int pcolfilter; + ReadProperty(this->img_ctrl_->pixelColorFilter,pcolfilter); + this->bayer_filter_ = MVFormatToColorFilter(pcolfilter); + // Bayer parity of this image if this buffer is part of a larger image TBayerMosaicParity bayer_mosaic_parity; ReadProperty(request_->imageBayerMosaicParity,bayer_mosaic_parity); @@ -239,7 +254,7 @@ void CMvbluefox3::GetImageReqFormat(mvIMPACT::acquire::Request *request) else // Bayer pattern { this->params_.pixel_format = BayerPatternToEncoding(bayer_mosaic_parity, - this->bytes_per_pixel_); + this->bytes_per_pixel_); } } @@ -258,6 +273,11 @@ int CMvbluefox3::GetImgLinePitch(void) return this->linepitch_; } +bayer_filter_t CMvbluefox3::GetBayerColorFilter(void) +{ + return this->bayer_filter_; +} + int CMvbluefox3::ReqExposeUs(void) { if (this->request_ == NULL || !this->request_->isOK()) diff --git a/src/mvbluefox3.h b/src/mvbluefox3.h index 4f28534206d76c809b602bcd0f57627653ab63b0..17e85958e62d7af96c0ab7f80f5bf0cc9c486648 100644 --- a/src/mvbluefox3.h +++ b/src/mvbluefox3.h @@ -8,6 +8,8 @@ #include <mvIMPACT_CPP/mvIMPACT_acquire.h> #include <mvIMPACT_CPP/mvIMPACT_acquire_GenICam.h> +#include <sys/stat.h> + // Forward delcaration namespace cv { class Mat; } @@ -146,6 +148,7 @@ class CMvbluefox3 int linepitch_; // Line pitch. int depth_; // Bits per image channel. int bytes_per_pixel_; // Bytes per pixel. + bayer_filter_t bayer_filter_; // Pixel Color filter. /** * \brief Mutex object to handle the access to the image @@ -350,6 +353,13 @@ class CMvbluefox3 */ void ColorTwistFilter(bool &ct_enbl); + /** + * \brief Check if File exist. + * + * Check if File exist. + */ + bool FileExist(const std::string& name); + public: /** @@ -447,6 +457,12 @@ class CMvbluefox3 */ int GetImgLinePitch(void); + /** + * \brief Get bayer color filter format + * + * Get bayer color filter format. + */ + bayer_filter_t GetBayerColorFilter(void); }; } // End of CMvbluefox3 namespace diff --git a/src/mvbluefox3_settings.cpp b/src/mvbluefox3_settings.cpp index 35041cf3e60a53fcde3ffd8f20c822c4e2af4f65..fe337ce8769467e5bb86de669eaacdaa22941039 100644 --- a/src/mvbluefox3_settings.cpp +++ b/src/mvbluefox3_settings.cpp @@ -111,6 +111,20 @@ codings_t BayerPatternToEncoding(const TBayerMosaicParity& bayer_pattern, return coding; } +bayer_filter_t MVFormatToColorFilter(const int &pcf) +{ + bayer_filter_t bf; + switch (pcf) + { + case 0: bf = none; break; + case 1: bf = bayer_rg; break; + case 2: bf = bayer_gb; break; + case 3: bf = bayer_gr; break; + case 4: bf = bayer_bg; break; + } + return bf; +} + binnings_t MVBinningToBinning(const TCameraBinningMode& idbm) { binnings_t bin; diff --git a/src/mvbluefox3_settings.h b/src/mvbluefox3_settings.h index 83cb881fec915220b6b71dcb27adfa41ef6d81b1..4840330cb9b2bf3cab368d49b398c4cbc85e5478 100644 --- a/src/mvbluefox3_settings.h +++ b/src/mvbluefox3_settings.h @@ -59,7 +59,7 @@ namespace CMvbluefox3 { #define GENERATE_STRING_ENC(STRING) #STRING, enum codings_t { FOREACH_ENCODING(GENERATE_ENUM_ENC) }; static const char *codings_str[] = { FOREACH_ENCODING(GENERATE_STRING_ENC) }; -inline void empty_funcc(void){(void)codings_str;} +inline void empty_funca(void){(void)codings_str;} /** * \brief Identifiers of the binning codings @@ -94,12 +94,17 @@ enum binnings_t { FOREACH_BINNING(GENERATE_ENUM_BIN) }; static const char *binnings_str[] = { FOREACH_BINNING(GENERATE_STRING_BIN) }; inline void empty_funcb(void){(void)binnings_str;} -enum mirror_t -{ - Off, - TopDown, - LeftRight -}; +#define FOREACH_BAYERFILTER(COLORFILTER) \ + COLORFILTER(none) \ + COLORFILTER(bayer_rg) \ + COLORFILTER(bayer_gb) \ + COLORFILTER(bayer_gr) \ + COLORFILTER(bayer_bg) +#define GENERATE_ENUM_BF(ENUM) ENUM, +#define GENERATE_STRING_BF(STRING) #STRING, +enum bayer_filter_t { FOREACH_BAYERFILTER(GENERATE_ENUM_BF) }; +static const char *bayer_filter_str[] = { FOREACH_BAYERFILTER(GENERATE_STRING_BF) }; +inline void empty_funcc(void){(void)bayer_filter_str;} /** * \brief Matrix Vision Pixel format to Encoding @@ -123,6 +128,14 @@ TImageDestinationPixelFormat EncodingToMVFormat(const codings_t& coding); codings_t BayerPatternToEncoding(const TBayerMosaicParity& bayer_pattern, int bytes_per_pixel); +/** + * \brief Matrix Vision Pixel Color Format to bayer_filter_t + * + * Matrix Vision Pixel Color Format to bayer_filter_t. + */ + +bayer_filter_t MVFormatToColorFilter(const int &pcf); + /** * \brief Matrix Vision TCameraBinningMode to binning_t *