From 7349b8f5cecfc6eb649b224e58da16d137c3c578 Mon Sep 17 00:00:00 2001 From: Maksim Shabunin Date: Tue, 28 Nov 2017 12:53:40 +0300 Subject: [PATCH] Build for embedded systems --- cmake/OpenCVGenConfig.cmake | 2 +- modules/calib3d/src/calibinit.cpp | 12 +++---- modules/core/include/opencv2/core/base.hpp | 16 +++++++++ .../core/include/opencv2/core/hal/interface.h | 6 +++- .../core/include/opencv2/core/softfloat.hpp | 12 +++++++ modules/core/src/command_line_parser.cpp | 24 ++++++------- modules/core/src/glob.cpp | 6 ++-- modules/core/src/lda.cpp | 6 ++-- modules/core/src/matrix.cpp | 10 +++--- modules/core/src/ocl.cpp | 4 +-- modules/core/src/persistence.cpp | 10 +++--- modules/core/src/system.cpp | 2 +- modules/core/src/umatrix.cpp | 8 ++--- modules/imgcodecs/src/bitstrm.cpp | 4 +-- modules/imgcodecs/src/exif.cpp | 21 ++++++----- modules/imgcodecs/src/grfmt_bmp.cpp | 12 +++---- modules/imgcodecs/src/grfmt_pam.cpp | 36 +++++++++---------- modules/imgcodecs/src/grfmt_pxm.cpp | 28 ++++++++------- modules/imgcodecs/src/grfmt_sunras.cpp | 8 ++--- modules/imgcodecs/src/loadsave.cpp | 36 +++++++++---------- modules/imgproc/src/color.cpp | 16 +++++++++ modules/imgproc/src/contours.cpp | 6 ++-- .../objdetect/src/detection_based_tracker.cpp | 12 +++---- modules/objdetect/src/hog.cpp | 14 ++++---- modules/videoio/src/cap.cpp | 8 ++--- 25 files changed, 184 insertions(+), 135 deletions(-) diff --git a/cmake/OpenCVGenConfig.cmake b/cmake/OpenCVGenConfig.cmake index fb62638b4b..57c79f213a 100644 --- a/cmake/OpenCVGenConfig.cmake +++ b/cmake/OpenCVGenConfig.cmake @@ -103,7 +103,7 @@ function(ocv_gen_config TMP_DIR NESTED_PATH ROOT_NAME) endif() endfunction() -if(UNIX AND NOT ANDROID) +if((CMAKE_HOST_SYSTEM_NAME MATCHES "Linux" OR UNIX) AND NOT ANDROID) ocv_gen_config("${CMAKE_BINARY_DIR}/unix-install" "" "") endif() diff --git a/modules/calib3d/src/calibinit.cpp b/modules/calib3d/src/calibinit.cpp index ad08f3ed6d..ff62abcf0d 100644 --- a/modules/calib3d/src/calibinit.cpp +++ b/modules/calib3d/src/calibinit.cpp @@ -431,7 +431,7 @@ int cvFindChessboardCorners( const void* arr, CvSize pattern_size, cv::Ptr storage; - try + CV_TRY { int k = 0; const int min_dilations = 0; @@ -617,11 +617,11 @@ int cvFindChessboardCorners( const void* arr, CvSize pattern_size, cvTermCriteria(CV_TERMCRIT_EPS+CV_TERMCRIT_ITER, 15, 0.1)); } } - catch(...) + CV_CATCH_ALL { cvFree(&quads); cvFree(&corners); - throw; + CV_RETHROW(); } cvFree(&quads); cvFree(&corners); @@ -2151,13 +2151,13 @@ bool cv::findCirclesGrid2( InputArray _image, Size patternSize, void* oldCbkData; ErrorCallback oldCbk = redirectError(quiet_error, 0, &oldCbkData); #endif - try + CV_TRY { isFound = boxFinder.findHoles(); } - catch (const cv::Exception &) + CV_CATCH(Exception, e) { - + CV_UNUSED(e); } #if BE_QUIET redirectError(oldCbk, oldCbkData); diff --git a/modules/core/include/opencv2/core/base.hpp b/modules/core/include/opencv2/core/base.hpp index 113954d1e9..05190927eb 100644 --- a/modules/core/include/opencv2/core/base.hpp +++ b/modules/core/include/opencv2/core/base.hpp @@ -342,7 +342,23 @@ enum BorderTypes { #define CV_SUPPRESS_DEPRECATED_START #define CV_SUPPRESS_DEPRECATED_END #endif + #define CV_UNUSED(name) (void)name + +#if defined __GNUC__ && !defined __EXCEPTIONS +#define CV_TRY +#define CV_CATCH(A, B) for (A B; false; ) +#define CV_CATCH_ALL if (false) +#define CV_THROW(A) abort() +#define CV_RETHROW() abort() +#else +#define CV_TRY try +#define CV_CATCH(A, B) catch(const A & B) +#define CV_CATCH_ALL catch(...) +#define CV_THROW(A) throw A +#define CV_RETHROW() throw +#endif + //! @endcond /*! @brief Signals an error and raises the exception. diff --git a/modules/core/include/opencv2/core/hal/interface.h b/modules/core/include/opencv2/core/hal/interface.h index 4a97e659e5..8f640254c3 100644 --- a/modules/core/include/opencv2/core/hal/interface.h +++ b/modules/core/include/opencv2/core/hal/interface.h @@ -32,7 +32,11 @@ #if !defined _MSC_VER && !defined __BORLANDC__ # if defined __cplusplus && __cplusplus >= 201103L && !defined __APPLE__ # include - typedef std::uint32_t uint; +# ifdef __NEWLIB__ + typedef unsigned int uint; +# else + typedef std::uint32_t uint; +# endif # else # include typedef uint32_t uint; diff --git a/modules/core/include/opencv2/core/softfloat.hpp b/modules/core/include/opencv2/core/softfloat.hpp index d5c77f9886..b98965f6a7 100644 --- a/modules/core/include/opencv2/core/softfloat.hpp +++ b/modules/core/include/opencv2/core/softfloat.hpp @@ -122,6 +122,12 @@ public: explicit softfloat( const uint64_t ); explicit softfloat( const int32_t ); explicit softfloat( const int64_t ); + +#ifdef CV_INT32_T_IS_LONG_INT + // for platforms with int32_t = long int + explicit softfloat( const int a ) { *this = softfloat(static_cast(a)); } +#endif + /** @brief Construct from float */ explicit softfloat( const float a ) { Cv32suf s; s.f = a; v = s.u; } @@ -253,6 +259,12 @@ public: explicit softdouble( const uint64_t ); explicit softdouble( const int32_t ); explicit softdouble( const int64_t ); + +#ifdef CV_INT32_T_IS_LONG_INT + // for platforms with int32_t = long int + explicit softdouble( const int a ) { *this = softdouble(static_cast(a)); } +#endif + /** @brief Construct from double */ explicit softdouble( const double a ) { Cv64suf s; s.f = a; v = s.u; } diff --git a/modules/core/src/command_line_parser.cpp b/modules/core/src/command_line_parser.cpp index a75b924758..6529bfd704 100644 --- a/modules/core/src/command_line_parser.cpp +++ b/modules/core/src/command_line_parser.cpp @@ -115,7 +115,7 @@ static void from_str(const String& str, int type, void* dst) void CommandLineParser::getByName(const String& name, bool space_delete, int type, void* dst) const { - try + CV_TRY { for (size_t i = 0; i < impl->data.size(); i++) { @@ -140,20 +140,19 @@ void CommandLineParser::getByName(const String& name, bool space_delete, int typ } } } - catch (Exception& e) + CV_CATCH (Exception, e) { impl->error = true; impl->error_message = impl->error_message + "Parameter '"+ name + "': " + e.err + "\n"; return; } - CV_Error_(Error::StsBadArg, ("undeclared key '%s' requested", name.c_str())); } void CommandLineParser::getByIndex(int index, bool space_delete, int type, void* dst) const { - try + CV_TRY { for (size_t i = 0; i < impl->data.size(); i++) { @@ -173,13 +172,12 @@ void CommandLineParser::getByIndex(int index, bool space_delete, int type, void* } } } - catch(Exception& e) + CV_CATCH(Exception, e) { impl->error = true; impl->error_message = impl->error_message + format("Parameter #%d: ", index) + e.err + "\n"; return; } - CV_Error_(Error::StsBadArg, ("undeclared position %d requested", index)); } @@ -454,14 +452,13 @@ std::vector CommandLineParser::Impl::split_range_string(const String& _s std::vector vec; String word = ""; bool begin = false; - while (!str.empty()) { if (str[0] == fs) { if (begin == true) { - throw cv::Exception(CV_StsParseError, + CV_THROW (cv::Exception(CV_StsParseError, String("error in split_range_string(") + str + String(", ") @@ -470,7 +467,7 @@ std::vector CommandLineParser::Impl::split_range_string(const String& _s + String(1, ss) + String(")"), "", __FILE__, __LINE__ - ); + )); } begin = true; word = ""; @@ -481,7 +478,7 @@ std::vector CommandLineParser::Impl::split_range_string(const String& _s { if (begin == false) { - throw cv::Exception(CV_StsParseError, + CV_THROW (cv::Exception(CV_StsParseError, String("error in split_range_string(") + str + String(", ") @@ -490,7 +487,7 @@ std::vector CommandLineParser::Impl::split_range_string(const String& _s + String(1, ss) + String(")"), "", __FILE__, __LINE__ - ); + )); } begin = false; vec.push_back(word); @@ -505,7 +502,7 @@ std::vector CommandLineParser::Impl::split_range_string(const String& _s if (begin == true) { - throw cv::Exception(CV_StsParseError, + CV_THROW (cv::Exception(CV_StsParseError, String("error in split_range_string(") + str + String(", ") @@ -514,9 +511,8 @@ std::vector CommandLineParser::Impl::split_range_string(const String& _s + String(1, ss) + String(")"), "", __FILE__, __LINE__ - ); + )); } - return vec; } diff --git a/modules/core/src/glob.cpp b/modules/core/src/glob.cpp index e468129ddd..3383bf8fa1 100644 --- a/modules/core/src/glob.cpp +++ b/modules/core/src/glob.cpp @@ -231,7 +231,7 @@ static void glob_rec(const cv::String& directory, const cv::String& wildchart, s if ((dir = opendir (directory.c_str())) != 0) { /* find all the files and directories within directory */ - try + CV_TRY { struct dirent *ent; while ((ent = readdir (dir)) != 0) @@ -255,10 +255,10 @@ static void glob_rec(const cv::String& directory, const cv::String& wildchart, s result.push_back(entry); } } - catch (...) + CV_CATCH_ALL { closedir(dir); - throw; + CV_RETHROW(); } closedir(dir); } diff --git a/modules/core/src/lda.cpp b/modules/core/src/lda.cpp index 0686fde142..48b7391805 100644 --- a/modules/core/src/lda.cpp +++ b/modules/core/src/lda.cpp @@ -863,7 +863,7 @@ private: d = alloc_1d (n); e = alloc_1d (n); ort = alloc_1d (n); - try { + CV_TRY { // Reduce to Hessenberg form. orthes(); // Reduce Hessenberg to real Schur form. @@ -881,10 +881,10 @@ private: // Deallocate the memory by releasing all internal working data. release(); } - catch (...) + CV_CATCH_ALL { release(); - throw; + CV_RETHROW(); } } diff --git a/modules/core/src/matrix.cpp b/modules/core/src/matrix.cpp index a85effc4c8..4b74c94cf9 100644 --- a/modules/core/src/matrix.cpp +++ b/modules/core/src/matrix.cpp @@ -424,12 +424,12 @@ void Mat::create(int d, const int* _sizes, int _type) #endif if(!a) a = a0; - try + CV_TRY { u = a->allocate(dims, size, _type, 0, step.p, 0, USAGE_DEFAULT); CV_Assert(u != 0); } - catch(...) + CV_CATCH_ALL { if(a != a0) u = a0->allocate(dims, size, _type, 0, step.p, 0, USAGE_DEFAULT); @@ -484,7 +484,7 @@ Mat::Mat(const Mat& m, const Range& _rowRange, const Range& _colRange) } *this = m; - try + CV_TRY { if( _rowRange != Range::all() && _rowRange != Range(0,rows) ) { @@ -505,10 +505,10 @@ Mat::Mat(const Mat& m, const Range& _rowRange, const Range& _colRange) flags |= SUBMATRIX_FLAG; } } - catch(...) + CV_CATCH_ALL { release(); - throw; + CV_RETHROW(); } if( rows == 1 ) diff --git a/modules/core/src/ocl.cpp b/modules/core/src/ocl.cpp index eac630e3be..0a71bf9ae6 100644 --- a/modules/core/src/ocl.cpp +++ b/modules/core/src/ocl.cpp @@ -827,11 +827,11 @@ bool useOpenCL() CoreTLSData* data = getCoreTlsData().get(); if( data->useOpenCL < 0 ) { - try + CV_TRY { data->useOpenCL = (int)(haveOpenCL() && Device::getDefault().ptr() && Device::getDefault().available()) ? 1 : 0; } - catch (...) + CV_CATCH_ALL { data->useOpenCL = 0; } diff --git a/modules/core/src/persistence.cpp b/modules/core/src/persistence.cpp index f428063d70..fc11d8da28 100644 --- a/modules/core/src/persistence.cpp +++ b/modules/core/src/persistence.cpp @@ -4513,7 +4513,7 @@ cvOpenFileStorage( const char* query, CvMemStorage* dststorage, int flags, const //mode = cvGetErrMode(); //cvSetErrMode( CV_ErrModeSilent ); - try + CV_TRY { switch (fs->fmt) { @@ -4523,11 +4523,11 @@ cvOpenFileStorage( const char* query, CvMemStorage* dststorage, int flags, const default: break; } } - catch (...) + CV_CATCH_ALL { fs->is_opened = true; cvReleaseFileStorage( &fs ); - throw; + CV_RETHROW(); } //cvSetErrMode( mode ); @@ -5986,11 +5986,11 @@ icvReadSeq( CvFileStorage* fs, CvFileNode* node ) flags |= CV_SEQ_FLAG_HOLE; if( !strstr(flags_str, "untyped") ) { - try + CV_TRY { flags |= icvDecodeSimpleFormat(dt); } - catch(...) + CV_CATCH_ALL { } } diff --git a/modules/core/src/system.cpp b/modules/core/src/system.cpp index 5894dfb7be..b8b65b6b42 100644 --- a/modules/core/src/system.cpp +++ b/modules/core/src/system.cpp @@ -961,7 +961,7 @@ void error( const Exception& exc ) *p = 0; } - throw exc; + CV_THROW(exc); } void error(int _code, const String& _err, const char* _func, const char* _file, int _line) diff --git a/modules/core/src/umatrix.cpp b/modules/core/src/umatrix.cpp index 6e4cd349d0..14b12585e7 100644 --- a/modules/core/src/umatrix.cpp +++ b/modules/core/src/umatrix.cpp @@ -295,11 +295,11 @@ UMat Mat::getUMat(int accessFlags, UMatUsageFlags usageFlags) const new_u = a->allocate(dims, size.p, type(), data, step.p, accessFlags, usageFlags); } bool allocated = false; - try + CV_TRY { allocated = UMat::getStdAllocator()->allocate(new_u, accessFlags, usageFlags); } - catch (const cv::Exception& e) + CV_CATCH(cv::Exception, e) { fprintf(stderr, "Exception: %s\n", e.what()); } @@ -371,12 +371,12 @@ void UMat::create(int d, const int* _sizes, int _type, UMatUsageFlags _usageFlag a = a0; a0 = Mat::getDefaultAllocator(); } - try + CV_TRY { u = a->allocate(dims, size, _type, 0, step.p, 0, usageFlags); CV_Assert(u != 0); } - catch(...) + CV_CATCH_ALL { if(a != a0) u = a0->allocate(dims, size, _type, 0, step.p, 0, usageFlags); diff --git a/modules/imgcodecs/src/bitstrm.cpp b/modules/imgcodecs/src/bitstrm.cpp index 0a8941aecf..80bb26c097 100644 --- a/modules/imgcodecs/src/bitstrm.cpp +++ b/modules/imgcodecs/src/bitstrm.cpp @@ -98,7 +98,7 @@ void RBaseStream::readBlock() { if( m_block_pos == 0 && m_current < m_end ) return; - throw RBS_THROW_EOS; + CV_THROW (RBS_THROW_EOS); } fseek( m_file, m_block_pos, SEEK_SET ); @@ -107,7 +107,7 @@ void RBaseStream::readBlock() m_current = m_start; if( readed == 0 || m_current >= m_end ) - throw RBS_THROW_EOS; + CV_THROW (RBS_THROW_EOS); } diff --git a/modules/imgcodecs/src/exif.cpp b/modules/imgcodecs/src/exif.cpp index e057f8ce53..ade6cef3fc 100644 --- a/modules/imgcodecs/src/exif.cpp +++ b/modules/imgcodecs/src/exif.cpp @@ -41,6 +41,8 @@ //M*/ #include "exif.hpp" +#include "opencv2/core/cvdef.h" +#include "opencv2/core/base.hpp" namespace { @@ -79,14 +81,15 @@ ExifReader::~ExifReader() */ bool ExifReader::parse() { - try { + CV_TRY { m_exif = getExif(); if( !m_exif.empty() ) { return true; } return false; - } catch (ExifParsingError&) { + } CV_CATCH (ExifParsingError, e) { + CV_UNUSED(e); return false; } } @@ -150,11 +153,11 @@ std::map ExifReader::getExif() case COM: bytesToSkip = getFieldSize(); if (bytesToSkip < markerSize) { - throw ExifParsingError(); + CV_THROW (ExifParsingError()); } m_stream.seekg( static_cast( bytesToSkip - markerSize ), m_stream.cur ); if ( m_stream.fail() ) { - throw ExifParsingError(); + CV_THROW (ExifParsingError()); } break; @@ -165,12 +168,12 @@ std::map ExifReader::getExif() case APP1: //actual Exif Marker exifSize = getFieldSize(); if (exifSize <= offsetToTiffHeader) { - throw ExifParsingError(); + CV_THROW (ExifParsingError()); } m_data.resize( exifSize - offsetToTiffHeader ); m_stream.seekg( static_cast( offsetToTiffHeader ), m_stream.cur ); if ( m_stream.fail() ) { - throw ExifParsingError(); + CV_THROW (ExifParsingError()); } m_stream.read( reinterpret_cast(&m_data[0]), exifSize - offsetToTiffHeader ); count = m_stream.gcount(); @@ -415,7 +418,7 @@ std::string ExifReader::getString(const size_t offset) const dataOffset = getU32( offset + 8 ); } if (dataOffset > m_data.size() || dataOffset + size > m_data.size()) { - throw ExifParsingError(); + CV_THROW (ExifParsingError()); } std::vector::const_iterator it = m_data.begin() + dataOffset; std::string result( it, it + size ); //copy vector content into result @@ -432,7 +435,7 @@ std::string ExifReader::getString(const size_t offset) const uint16_t ExifReader::getU16(const size_t offset) const { if (offset + 1 >= m_data.size()) - throw ExifParsingError(); + CV_THROW (ExifParsingError()); if( m_format == INTEL ) { @@ -450,7 +453,7 @@ uint16_t ExifReader::getU16(const size_t offset) const uint32_t ExifReader::getU32(const size_t offset) const { if (offset + 3 >= m_data.size()) - throw ExifParsingError(); + CV_THROW (ExifParsingError()); if( m_format == INTEL ) { diff --git a/modules/imgcodecs/src/grfmt_bmp.cpp b/modules/imgcodecs/src/grfmt_bmp.cpp index d20503fdae..ab46219aa0 100644 --- a/modules/imgcodecs/src/grfmt_bmp.cpp +++ b/modules/imgcodecs/src/grfmt_bmp.cpp @@ -89,7 +89,7 @@ bool BmpDecoder::readHeader() else if( !m_strm.open( m_filename )) return false; - try + CV_TRY { m_strm.skip( 10 ); m_offset = m_strm.getDWord(); @@ -172,9 +172,9 @@ bool BmpDecoder::readHeader() } } } - catch(...) + CV_CATCH_ALL { - throw; + CV_RETHROW(); } // in 32 bit case alpha channel is used - so require CV_8UC4 type m_type = iscolor ? (m_bpp == 32 ? CV_8UC4 : CV_8UC3 ) : CV_8UC1; @@ -224,7 +224,7 @@ bool BmpDecoder::readData( Mat& img ) } uchar *src = _src, *bgr = _bgr; - try + CV_TRY { m_strm.setPos( m_offset ); @@ -492,9 +492,9 @@ decode_rle8_bad: ; CV_ErrorNoReturn(cv::Error::StsError, "Invalid/unsupported mode"); } } - catch(...) + CV_CATCH_ALL { - throw; + CV_RETHROW(); } return result; diff --git a/modules/imgcodecs/src/grfmt_pam.cpp b/modules/imgcodecs/src/grfmt_pam.cpp index 8eb9e01230..d3d2f90ef0 100644 --- a/modules/imgcodecs/src/grfmt_pam.cpp +++ b/modules/imgcodecs/src/grfmt_pam.cpp @@ -374,25 +374,25 @@ bool PAMDecoder::readHeader() } else if( !m_strm.open( m_filename )) return false; - try + CV_TRY { byte = m_strm.getByte(); if( byte != 'P' ) - throw RBS_BAD_HEADER; + CV_THROW( RBS_BAD_HEADER ); byte = m_strm.getByte(); if (byte != '7') - throw RBS_BAD_HEADER; + CV_THROW( RBS_BAD_HEADER ); byte = m_strm.getByte(); if (byte != '\n' && byte != '\r') - throw RBS_BAD_HEADER; + CV_THROW( RBS_BAD_HEADER ); uint i; memset (&flds, 0x00, sizeof (struct parsed_fields)); do { if (!ReadPAMHeaderLine(m_strm, fieldtype, value)) - throw RBS_BAD_HEADER; + CV_THROW( RBS_BAD_HEADER ); switch (fieldtype) { case PAM_HEADER_NONE: case PAM_HEADER_COMMENT: @@ -402,32 +402,32 @@ bool PAMDecoder::readHeader() break; case PAM_HEADER_HEIGHT: if (flds.height) - throw RBS_BAD_HEADER; + CV_THROW( RBS_BAD_HEADER ); if (!ParseNumber (value, &m_height)) - throw RBS_BAD_HEADER; + CV_THROW( RBS_BAD_HEADER ); flds.height = true; break; case PAM_HEADER_WIDTH: if (flds.width) - throw RBS_BAD_HEADER; + CV_THROW( RBS_BAD_HEADER ); if (!ParseNumber (value, &m_width)) - throw RBS_BAD_HEADER; + CV_THROW( RBS_BAD_HEADER ); flds.width = true; break; case PAM_HEADER_DEPTH: if (flds.depth) - throw RBS_BAD_HEADER; + CV_THROW( RBS_BAD_HEADER ); if (!ParseNumber (value, &m_channels)) - throw RBS_BAD_HEADER; + CV_THROW( RBS_BAD_HEADER ); flds.depth = true; break; case PAM_HEADER_MAXVAL: if (flds.maxval) - throw RBS_BAD_HEADER; + CV_THROW( RBS_BAD_HEADER ); if (!ParseNumber (value, &m_maxval)) - throw RBS_BAD_HEADER; + CV_THROW( RBS_BAD_HEADER ); if ( m_maxval > 65535 ) - throw RBS_BAD_HEADER; + CV_THROW( RBS_BAD_HEADER ); if ( m_maxval > 255 ) { m_sampledepth = CV_16U; } @@ -446,7 +446,7 @@ bool PAMDecoder::readHeader() } break; default: - throw RBS_BAD_HEADER; + CV_THROW( RBS_BAD_HEADER ); } } while (fieldtype != PAM_HEADER_ENDHDR); @@ -464,7 +464,7 @@ bool PAMDecoder::readHeader() return true; } - } catch(...) + } CV_CATCH_ALL { } @@ -511,7 +511,7 @@ bool PAMDecoder::readData( Mat& img ) layout.graychan = 0; } - try + CV_TRY { m_strm.setPos( m_offset ); @@ -612,7 +612,7 @@ bool PAMDecoder::readData( Mat& img ) } res = true; - } catch(...) + } CV_CATCH_ALL { } diff --git a/modules/imgcodecs/src/grfmt_pxm.cpp b/modules/imgcodecs/src/grfmt_pxm.cpp index 68bd8fd93f..b8301489b7 100644 --- a/modules/imgcodecs/src/grfmt_pxm.cpp +++ b/modules/imgcodecs/src/grfmt_pxm.cpp @@ -148,11 +148,11 @@ bool PxMDecoder::readHeader() else if( !m_strm.open( m_filename )) return false; - try + CV_TRY { int code = m_strm.getByte(); if( code != 'P' ) - throw RBS_BAD_HEADER; + CV_THROW (RBS_BAD_HEADER); code = m_strm.getByte(); switch( code ) @@ -160,7 +160,7 @@ bool PxMDecoder::readHeader() case '1': case '4': m_bpp = 1; break; case '2': case '5': m_bpp = 8; break; case '3': case '6': m_bpp = 24; break; - default: throw RBS_BAD_HEADER; + default: CV_THROW (RBS_BAD_HEADER); } m_binary = code >= '4'; @@ -171,7 +171,7 @@ bool PxMDecoder::readHeader() m_maxval = m_bpp == 1 ? 1 : ReadNumber(m_strm); if( m_maxval > 65535 ) - throw RBS_BAD_HEADER; + CV_THROW (RBS_BAD_HEADER); //if( m_maxval > 255 ) m_binary = false; nonsense if( m_maxval > 255 ) @@ -183,14 +183,15 @@ bool PxMDecoder::readHeader() result = true; } } - catch (const cv::Exception&) + CV_CATCH (cv::Exception, e) { - throw; + CV_UNUSED(e); + CV_RETHROW(); } - catch (...) + CV_CATCH_ALL { std::cerr << "PXM::readHeader(): unknown C++ exception" << std::endl << std::flush; - throw; + CV_RETHROW(); } if( !result ) @@ -230,7 +231,7 @@ bool PxMDecoder::readData( Mat& img ) FillGrayPalette( palette, m_bpp==1 ? 1 : 8 , m_bpp == 1 ); } - try + CV_TRY { m_strm.setPos( m_offset ); @@ -356,14 +357,15 @@ bool PxMDecoder::readData( Mat& img ) CV_ErrorNoReturn(Error::StsError, "m_bpp is not supported"); } } - catch (const cv::Exception&) + CV_CATCH (cv::Exception, e) { - throw; + CV_UNUSED(e); + CV_RETHROW(); } - catch (...) + CV_CATCH_ALL { std::cerr << "PXM::readData(): unknown exception" << std::endl << std::flush; - throw; + CV_RETHROW(); } return result; diff --git a/modules/imgcodecs/src/grfmt_sunras.cpp b/modules/imgcodecs/src/grfmt_sunras.cpp index 6d448f94ed..77efc4b1bf 100644 --- a/modules/imgcodecs/src/grfmt_sunras.cpp +++ b/modules/imgcodecs/src/grfmt_sunras.cpp @@ -82,7 +82,7 @@ bool SunRasterDecoder::readHeader() if( !m_strm.open( m_filename )) return false; - try + CV_TRY { m_strm.skip( 4 ); m_width = m_strm.getDWord(); @@ -142,7 +142,7 @@ bool SunRasterDecoder::readHeader() } } } - catch(...) + CV_CATCH_ALL { } @@ -179,7 +179,7 @@ bool SunRasterDecoder::readData( Mat& img ) if( !color && m_maptype == RMT_EQUAL_RGB ) CvtPaletteToGray( m_palette, gray_palette, 1 << m_bpp ); - try + CV_TRY { m_strm.setPos( m_offset ); @@ -374,7 +374,7 @@ bad_decoding_end: assert(0); } } - catch( ... ) + CV_CATCH_ALL { } diff --git a/modules/imgcodecs/src/loadsave.cpp b/modules/imgcodecs/src/loadsave.cpp index efbd52efc5..9bb9d74105 100644 --- a/modules/imgcodecs/src/loadsave.cpp +++ b/modules/imgcodecs/src/loadsave.cpp @@ -426,18 +426,18 @@ imread_( const String& filename, int flags, int hdrtype, Mat* mat=0 ) /// set the filename in the driver decoder->setSource( filename ); - try + CV_TRY { // read the header to make sure it succeeds if( !decoder->readHeader() ) return 0; } - catch (const cv::Exception& e) + CV_CATCH (cv::Exception, e) { std::cerr << "imread_('" << filename << "'): can't read header: " << e.what() << std::endl << std::flush; return 0; } - catch (...) + CV_CATCH_ALL { std::cerr << "imread_('" << filename << "'): can't read header: unknown exception" << std::endl << std::flush; return 0; @@ -482,16 +482,16 @@ imread_( const String& filename, int flags, int hdrtype, Mat* mat=0 ) // read the image data bool success = false; - try + CV_TRY { if (decoder->readData(*data)) success = true; } - catch (const cv::Exception& e) + CV_CATCH (cv::Exception, e) { std::cerr << "imread_('" << filename << "'): can't read data: " << e.what() << std::endl << std::flush; } - catch (...) + CV_CATCH_ALL { std::cerr << "imread_('" << filename << "'): can't read data: unknown exception" << std::endl << std::flush; } @@ -548,18 +548,18 @@ imreadmulti_(const String& filename, int flags, std::vector& mats) decoder->setSource(filename); // read the header to make sure it succeeds - try + CV_TRY { // read the header to make sure it succeeds if( !decoder->readHeader() ) return 0; } - catch (const cv::Exception& e) + CV_CATCH (cv::Exception, e) { std::cerr << "imreadmulti_('" << filename << "'): can't read header: " << e.what() << std::endl << std::flush; return 0; } - catch (...) + CV_CATCH_ALL { std::cerr << "imreadmulti_('" << filename << "'): can't read header: unknown exception" << std::endl << std::flush; return 0; @@ -587,16 +587,16 @@ imreadmulti_(const String& filename, int flags, std::vector& mats) // read the image data Mat mat(size.height, size.width, type); bool success = false; - try + CV_TRY { if (decoder->readData(mat)) success = true; } - catch (const cv::Exception& e) + CV_CATCH (cv::Exception, e) { std::cerr << "imreadmulti_('" << filename << "'): can't read data: " << e.what() << std::endl << std::flush; } - catch (...) + CV_CATCH_ALL { std::cerr << "imreadmulti_('" << filename << "'): can't read data: unknown exception" << std::endl << std::flush; } @@ -738,16 +738,16 @@ imdecode_( const Mat& buf, int flags, int hdrtype, Mat* mat=0 ) } bool success = false; - try + CV_TRY { if (decoder->readHeader()) success = true; } - catch (const cv::Exception& e) + CV_CATCH (cv::Exception, e) { std::cerr << "imdecode_('" << filename << "'): can't read header: " << e.what() << std::endl << std::flush; } - catch (...) + CV_CATCH_ALL { std::cerr << "imdecode_('" << filename << "'): can't read header: unknown exception" << std::endl << std::flush; } @@ -800,16 +800,16 @@ imdecode_( const Mat& buf, int flags, int hdrtype, Mat* mat=0 ) } success = false; - try + CV_TRY { if (decoder->readData(*data)) success = true; } - catch (const cv::Exception& e) + CV_CATCH (cv::Exception, e) { std::cerr << "imdecode_('" << filename << "'): can't read data: " << e.what() << std::endl << std::flush; } - catch (...) + CV_CATCH_ALL { std::cerr << "imdecode_('" << filename << "'): can't read data: unknown exception" << std::endl << std::flush; } diff --git a/modules/imgproc/src/color.cpp b/modules/imgproc/src/color.cpp index e8912ba616..b46de3ce68 100644 --- a/modules/imgproc/src/color.cpp +++ b/modules/imgproc/src/color.cpp @@ -6251,6 +6251,7 @@ static inline void trilinearInterpolate(int cx, int cy, int cz, const int16_t* L c = CV_DESCALE(c, trilinear_shift*3); } +#if CV_SIMD128 // 8 inValues are in [0; LAB_BASE] static inline void trilinearPackedInterpolate(const v_uint16x8& inX, const v_uint16x8& inY, const v_uint16x8& inZ, @@ -6339,6 +6340,8 @@ static inline void trilinearPackedInterpolate(const v_uint16x8& inX, const v_uin #undef DOT_SHIFT_PACK } +#endif // CV_SIMD128 + struct RGB2Lab_b { @@ -6465,6 +6468,8 @@ struct RGB2Lab_f i = 0; if(useInterpolation) { + +#if CV_SIMD128 if(enablePackedLab) { static const int nPixels = 4*2; @@ -6548,6 +6553,7 @@ struct RGB2Lab_f v_store_interleave(dst + i + 3*4, l_vec1, a_vec1, b_vec1); } } +#endif // CV_SIMD128 for(; i < n; i += 3, src += scn) { @@ -7036,6 +7042,8 @@ struct Lab2RGBinteger float alpha = ColorChannel::max(); int i = 0; + +#if CV_SIMD128 if(enablePackedLab) { v_float32x4 vldiv = v_setall_f32(256.f/100.0f); @@ -7122,6 +7130,7 @@ struct Lab2RGBinteger } } } +#endif for(; i < n*3; i += 3, dst += dcn) { @@ -7142,6 +7151,7 @@ struct Lab2RGBinteger uchar alpha = ColorChannel::max(); i = 0; +#if CV_SIMD128 if(enablePackedLab) { static const int nPixels = 8*2; @@ -7213,6 +7223,7 @@ struct Lab2RGBinteger } } } +#endif for (; i < n*3; i += 3, dst += dcn) { @@ -8097,6 +8108,8 @@ struct RGB2Luvinterpolate int i, scn = srccn, bIdx = blueIdx; i = 0; n *= 3; + +#if CV_SIMD128 if(enablePackedRGB2Luv) { static const int nPixels = 8*2; @@ -8154,6 +8167,7 @@ struct RGB2Luvinterpolate v_store_interleave(dst + i, l16, u16, v16); } } +#endif // CV_SIMD128 for(; i < n; i += 3, src += scn) { @@ -8514,6 +8528,7 @@ struct Luv2RGBinteger uchar alpha = ColorChannel::max(); i = 0; +#if CV_SIMD128 if(enablePackedLuv2RGB) { static const int nPixels = 16; @@ -8586,6 +8601,7 @@ struct Luv2RGBinteger } } } +#endif for (; i < n*3; i += 3, dst += dcn) { diff --git a/modules/imgproc/src/contours.cpp b/modules/imgproc/src/contours.cpp index ea56051c2b..464a9ad3c9 100644 --- a/modules/imgproc/src/contours.cpp +++ b/modules/imgproc/src/contours.cpp @@ -1828,7 +1828,7 @@ cvFindContours_Impl( void* img, CvMemStorage* storage, } else { - try + CV_TRY { scanner = cvStartFindContours_Impl( img, storage, cntHeaderSize, mode, method, offset, needFillBorder); @@ -1840,11 +1840,11 @@ cvFindContours_Impl( void* img, CvMemStorage* storage, } while( contour != 0 ); } - catch(...) + CV_CATCH_ALL { if( scanner ) cvEndFindContours(&scanner); - throw; + CV_RETHROW(); } *firstContour = cvEndFindContours( &scanner ); diff --git a/modules/objdetect/src/detection_based_tracker.cpp b/modules/objdetect/src/detection_based_tracker.cpp index 0097a4f830..0cdcafacee 100644 --- a/modules/objdetect/src/detection_based_tracker.cpp +++ b/modules/objdetect/src/detection_based_tracker.cpp @@ -284,23 +284,23 @@ bool cv::DetectionBasedTracker::SeparateDetectionWork::run() } #define CATCH_ALL_AND_LOG(_block) \ - try { \ + CV_TRY { \ _block; \ } \ - catch(cv::Exception& e) { \ + CV_CATCH(cv::Exception, e) { \ LOGE0("\n %s: ERROR: OpenCV Exception caught: \n'%s'\n\n", CV_Func, e.what()); \ - } catch(std::exception& e) { \ + } CV_CATCH(std::exception, e) { \ LOGE0("\n %s: ERROR: Exception caught: \n'%s'\n\n", CV_Func, e.what()); \ - } catch(...) { \ + } CV_CATCH_ALL { \ LOGE0("\n %s: ERROR: UNKNOWN Exception caught\n\n", CV_Func); \ } void* cv::workcycleObjectDetectorFunction(void* p) { CATCH_ALL_AND_LOG({ ((cv::DetectionBasedTracker::SeparateDetectionWork*)p)->workcycleObjectDetector(); }); - try{ + CV_TRY{ ((cv::DetectionBasedTracker::SeparateDetectionWork*)p)->init(); - } catch(...) { + } CV_CATCH_ALL { LOGE0("DetectionBasedTracker: workcycleObjectDetectorFunction: ERROR concerning pointer, received as the function parameter"); } return NULL; diff --git a/modules/objdetect/src/hog.cpp b/modules/objdetect/src/hog.cpp index 80f8ef2db0..8b030b7bdd 100644 --- a/modules/objdetect/src/hog.cpp +++ b/modules/objdetect/src/hog.cpp @@ -3686,7 +3686,7 @@ void HOGDescriptor::readALTModel(String modelfile) String eerr("file not exist"); String efile(__FILE__); String efunc(__FUNCTION__); - throw Exception(Error::StsError, eerr, efile, efunc, __LINE__); + CV_THROW (Exception(Error::StsError, eerr, efile, efunc, __LINE__)); } char version_buffer[10]; if (!fread (&version_buffer,sizeof(char),10,modelfl)) @@ -3696,7 +3696,7 @@ void HOGDescriptor::readALTModel(String modelfile) String efunc(__FUNCTION__); fclose(modelfl); - throw Exception(Error::StsError, eerr, efile, efunc, __LINE__); + CV_THROW (Exception(Error::StsError, eerr, efile, efunc, __LINE__)); } if(strcmp(version_buffer,"V6.01")) { String eerr("version doesnot match"); @@ -3704,14 +3704,14 @@ void HOGDescriptor::readALTModel(String modelfile) String efunc(__FUNCTION__); fclose(modelfl); - throw Exception(Error::StsError, eerr, efile, efunc, __LINE__); + CV_THROW (Exception(Error::StsError, eerr, efile, efunc, __LINE__)); } /* read version number */ int version = 0; if (!fread (&version,sizeof(int),1,modelfl)) { fclose(modelfl); - throw Exception(); + CV_THROW (Exception()); } if (version < 200) { @@ -3719,7 +3719,7 @@ void HOGDescriptor::readALTModel(String modelfile) String efile(__FILE__); String efunc(__FUNCTION__); fclose(modelfl); - throw Exception(); + CV_THROW (Exception()); } int kernel_type; size_t nread; @@ -3765,7 +3765,7 @@ void HOGDescriptor::readALTModel(String modelfile) if(nread != static_cast(length) + 1) { delete [] linearwt; fclose(modelfl); - throw Exception(); + CV_THROW (Exception()); } for(int i = 0; i < length; i++) @@ -3776,7 +3776,7 @@ void HOGDescriptor::readALTModel(String modelfile) delete [] linearwt; } else { fclose(modelfl); - throw Exception(); + CV_THROW (Exception()); } fclose(modelfl); } diff --git a/modules/videoio/src/cap.cpp b/modules/videoio/src/cap.cpp index 93251e679b..2daff96477 100644 --- a/modules/videoio/src/cap.cpp +++ b/modules/videoio/src/cap.cpp @@ -141,15 +141,15 @@ static bool get_capture_debug_flag() #define TRY_OPEN(capture, backend_func) \ { \ if (!capture) \ - try { \ + CV_TRY { \ if (get_capture_debug_flag()) fprintf(stderr, "VIDEOIO(%s): trying ...\n", #backend_func); \ capture = backend_func; \ if (get_capture_debug_flag()) fprintf(stderr, "VIDEOIO(%s): result=%p ...\n", #backend_func, capture); \ - } catch (const cv::Exception& e) { \ + } CV_CATCH (cv::Exception, e) { \ fprintf(stderr, "VIDEOIO(%s): raised OpenCV exception:\n\n%s\n", #backend_func, e.what()); \ - } catch (const std::exception& e) { \ + } CV_CATCH (std::exception, e) { \ fprintf(stderr, "VIDEOIO(%s): raised C++ exception:\n\n%s\n", #backend_func, e.what()); \ - } catch (...) { \ + } CV_CATCH_ALL { \ fprintf(stderr, "VIDEOIO(%s): raised unknown C++ exception!\n\n", #backend_func); \ } \ }