From 523f081923c48fbb316c795aab04edf324aa404a Mon Sep 17 00:00:00 2001 From: Alexander Alekhin Date: Sat, 28 Dec 2019 13:18:12 +0000 Subject: [PATCH] core(check): add Size_ --- modules/calib3d/src/calibration.cpp | 6 ++-- modules/core/include/opencv2/core/check.hpp | 2 ++ modules/core/src/check.cpp | 8 +++++ modules/core/test/test_misc.cpp | 37 +++++++++++++++++++-- 4 files changed, 49 insertions(+), 4 deletions(-) diff --git a/modules/calib3d/src/calibration.cpp b/modules/calib3d/src/calibration.cpp index bf199c2d3c..052bce1170 100644 --- a/modules/calib3d/src/calibration.cpp +++ b/modules/calib3d/src/calibration.cpp @@ -3221,8 +3221,10 @@ void cv::Rodrigues(InputArray _src, OutputArray _dst, OutputArray _jacobian) CV_INSTRUMENT_REGION(); Mat src = _src.getMat(); - CV_Check(src.rows, (src.rows == 1 && src.cols == 3) || (src.rows == 3 && src.cols == 1) || - (src.rows == 1 && src.cols == 1 && src.channels() == 3) || (src.rows == 3 && src.cols == 3), + const Size srcSz = src.size(); + CV_Check(srcSz, srcSz == Size(3, 1) || srcSz == Size(1, 3) || + (srcSz == Size(1, 1) && src.channels() == 3) || + srcSz == Size(3, 3), "Input matrix must be 1x3 or 3x1 for a rotation vector, or 3x3 for a rotation matrix"); bool v2m = src.cols == 1 || src.rows == 1; diff --git a/modules/core/include/opencv2/core/check.hpp b/modules/core/include/opencv2/core/check.hpp index bf441383e8..604447e8d7 100644 --- a/modules/core/include/opencv2/core/check.hpp +++ b/modules/core/include/opencv2/core/check.hpp @@ -69,6 +69,7 @@ CV_EXPORTS void CV_NORETURN check_failed_auto(const int v1, const int v2, const CV_EXPORTS void CV_NORETURN check_failed_auto(const size_t v1, const size_t v2, const CheckContext& ctx); CV_EXPORTS void CV_NORETURN check_failed_auto(const float v1, const float v2, const CheckContext& ctx); CV_EXPORTS void CV_NORETURN check_failed_auto(const double v1, const double v2, const CheckContext& ctx); +CV_EXPORTS void CV_NORETURN check_failed_auto(const Size_ v1, const Size_ v2, const CheckContext& ctx); CV_EXPORTS void CV_NORETURN check_failed_MatDepth(const int v1, const int v2, const CheckContext& ctx); CV_EXPORTS void CV_NORETURN check_failed_MatType(const int v1, const int v2, const CheckContext& ctx); CV_EXPORTS void CV_NORETURN check_failed_MatChannels(const int v1, const int v2, const CheckContext& ctx); @@ -77,6 +78,7 @@ CV_EXPORTS void CV_NORETURN check_failed_auto(const int v, const CheckContext& c CV_EXPORTS void CV_NORETURN check_failed_auto(const size_t v, const CheckContext& ctx); CV_EXPORTS void CV_NORETURN check_failed_auto(const float v, const CheckContext& ctx); CV_EXPORTS void CV_NORETURN check_failed_auto(const double v, const CheckContext& ctx); +CV_EXPORTS void CV_NORETURN check_failed_auto(const Size_ v, const CheckContext& ctx); CV_EXPORTS void CV_NORETURN check_failed_MatDepth(const int v, const CheckContext& ctx); CV_EXPORTS void CV_NORETURN check_failed_MatType(const int v, const CheckContext& ctx); CV_EXPORTS void CV_NORETURN check_failed_MatChannels(const int v, const CheckContext& ctx); diff --git a/modules/core/src/check.cpp b/modules/core/src/check.cpp index fca982656e..59c2bbe5de 100644 --- a/modules/core/src/check.cpp +++ b/modules/core/src/check.cpp @@ -113,6 +113,10 @@ void check_failed_auto(const double v1, const double v2, const CheckContext& ctx { check_failed_auto_(v1, v2, ctx); } +void check_failed_auto(const Size_ v1, const Size_ v2, const CheckContext& ctx) +{ + check_failed_auto_< Size_ >(v1, v2, ctx); +} template static CV_NORETURN @@ -163,6 +167,10 @@ void check_failed_auto(const double v, const CheckContext& ctx) { check_failed_auto_(v, ctx); } +void check_failed_auto(const Size_ v, const CheckContext& ctx) +{ + check_failed_auto_< Size_ >(v, ctx); +} }} // namespace diff --git a/modules/core/test/test_misc.cpp b/modules/core/test/test_misc.cpp index 46f10b694c..3934ceb716 100644 --- a/modules/core/test/test_misc.cpp +++ b/modules/core/test/test_misc.cpp @@ -671,7 +671,8 @@ TEST(Core_Check, testMatType_fail_2) EXPECT_STREQ(e.err.c_str(), "> Unsupported src:\n" "> 'src_type == CV_32FC1 || src_type == CV_32FC3'\n" -"> where\n> 'src_type' is 0 (CV_8UC1)\n" +"> where\n" +"> 'src_type' is 0 (CV_8UC1)\n" ); } catch (const std::exception& e) @@ -737,7 +738,39 @@ TEST(Core_Check, testMatDepth_fail_2) EXPECT_STREQ(e.err.c_str(), "> Unsupported src:\n" "> 'src_depth == CV_32F || src_depth == CV_64F'\n" -"> where\n> 'src_depth' is 0 (CV_8U)\n" +"> where\n" +"> 'src_depth' is 0 (CV_8U)\n" +); + } + catch (const std::exception& e) + { + FAIL() << "Unexpected C++ exception: " << e.what(); + } + catch (...) + { + FAIL() << "Unexpected unknown exception"; + } +} + + +void test_check_Size_1(const Size& srcSz) +{ + CV_Check(srcSz, srcSz == Size(4, 3), "Unsupported src size"); +} +TEST(Core_Check, testSize_1) +{ + try + { + test_check_Size_1(Size(2, 1)); + FAIL() << "Unreachable code called"; + } + catch (const cv::Exception& e) + { + EXPECT_STREQ(e.err.c_str(), +"> Unsupported src size:\n" +"> 'srcSz == Size(4, 3)'\n" +"> where\n" +"> 'srcSz' is [2 x 1]\n" ); } catch (const std::exception& e)