diff --git a/modules/calib3d/test/test_stereomatching.cpp b/modules/calib3d/test/test_stereomatching.cpp index 601e0cb93b..c79f013ea5 100644 --- a/modules/calib3d/test/test_stereomatching.cpp +++ b/modules/calib3d/test/test_stereomatching.cpp @@ -556,7 +556,7 @@ int CV_StereoMatchingTest::processStereoMatchingResults( FileStorage& fs, int ca assert( fs.isOpened() ); assert( trueLeftDisp.type() == CV_32FC1 ); assert( trueRightDisp.empty() || trueRightDisp.type() == CV_32FC1 ); - assert( leftDisp.type() == CV_32FC1 && rightDisp.type() == CV_32FC1 ); + assert( leftDisp.type() == CV_32FC1 && (rightDisp.empty() || rightDisp.type() == CV_32FC1) ); // get masks for unknown ground truth disparity values Mat leftUnknMask, rightUnknMask; diff --git a/modules/core/include/opencv2/core/mat.inl.hpp b/modules/core/include/opencv2/core/mat.inl.hpp index a0c43f1534..98346f1bc0 100644 --- a/modules/core/include/opencv2/core/mat.inl.hpp +++ b/modules/core/include/opencv2/core/mat.inl.hpp @@ -1673,7 +1673,7 @@ Mat_<_Tp>& Mat_<_Tp>::operator = (const Mat& m) { return (*this = m.reshape(DataType<_Tp>::channels, m.dims, 0)); } - CV_DbgAssert(DataType<_Tp>::channels == m.channels()); + CV_Assert(DataType<_Tp>::channels == m.channels() || m.empty()); m.convertTo(*this, type()); return *this; } diff --git a/modules/core/src/arithm.cpp b/modules/core/src/arithm.cpp index 10f739c0c1..dbbe6895ed 100644 --- a/modules/core/src/arithm.cpp +++ b/modules/core/src/arithm.cpp @@ -1233,6 +1233,12 @@ void cv::compare(InputArray _src1, InputArray _src2, OutputArray _dst, int op) CV_Assert( op == CMP_LT || op == CMP_LE || op == CMP_EQ || op == CMP_NE || op == CMP_GE || op == CMP_GT ); + if(_src1.empty() && _src2.empty()) + { + _dst.release(); + return; + } + bool haveScalar = false; if ((_src1.isMatx() + _src2.isMatx()) == 1 diff --git a/modules/core/src/convert.cpp b/modules/core/src/convert.cpp index 0fb1199987..481b86b4f1 100644 --- a/modules/core/src/convert.cpp +++ b/modules/core/src/convert.cpp @@ -1304,6 +1304,12 @@ void cv::Mat::convertTo(OutputArray _dst, int _type, double alpha, double beta) { CV_INSTRUMENT_REGION() + if( empty() ) + { + _dst.release(); + return; + } + bool noScale = fabs(alpha-1) < DBL_EPSILON && fabs(beta) < DBL_EPSILON; if( _type < 0 ) diff --git a/modules/core/src/copy.cpp b/modules/core/src/copy.cpp index f4f18cb740..5e7f4a879a 100644 --- a/modules/core/src/copy.cpp +++ b/modules/core/src/copy.cpp @@ -246,13 +246,14 @@ void Mat::copyTo( OutputArray _dst ) const return; } + if( empty() ) + { + _dst.release(); + return; + } + if( _dst.isUMat() ) { - if( empty() ) - { - _dst.release(); - return; - } _dst.create( dims, size.p, type() ); UMat dst = _dst.getUMat(); CV_Assert(dst.u != NULL); diff --git a/modules/features2d/src/agast.cpp b/modules/features2d/src/agast.cpp index ab01b67805..8b63234b29 100644 --- a/modules/features2d/src/agast.cpp +++ b/modules/features2d/src/agast.cpp @@ -7952,6 +7952,12 @@ public: { CV_INSTRUMENT_REGION() + if(_image.empty()) + { + keypoints.clear(); + return; + } + Mat mask = _mask.getMat(), grayImage; UMat ugrayImage; _InputArray gray = _image; diff --git a/modules/features2d/src/fast.cpp b/modules/features2d/src/fast.cpp index 106e5802cd..e34fa8f9d0 100644 --- a/modules/features2d/src/fast.cpp +++ b/modules/features2d/src/fast.cpp @@ -526,6 +526,12 @@ public: { CV_INSTRUMENT_REGION() + if(_image.empty()) + { + keypoints.clear(); + return; + } + Mat mask = _mask.getMat(), grayImage; UMat ugrayImage; _InputArray gray = _image; diff --git a/modules/features2d/src/gftt.cpp b/modules/features2d/src/gftt.cpp index 1b8010625b..e4a594a5c6 100644 --- a/modules/features2d/src/gftt.cpp +++ b/modules/features2d/src/gftt.cpp @@ -80,6 +80,12 @@ public: { CV_INSTRUMENT_REGION() + if(_image.empty()) + { + keypoints.clear(); + return; + } + std::vector corners; if (_image.isUMat()) diff --git a/modules/imgproc/src/hough.cpp b/modules/imgproc/src/hough.cpp index ec05edf888..1f61146193 100644 --- a/modules/imgproc/src/hough.cpp +++ b/modules/imgproc/src/hough.cpp @@ -803,7 +803,7 @@ static bool ocl_HoughLines(InputArray _src, OutputArray _lines, double rho, doub int total_points = counters.getMat(ACCESS_READ).at(0, 0); if (total_points <= 0) { - _lines.assign(UMat(0,0,CV_32FC2)); + _lines.release(); return true; } @@ -831,7 +831,7 @@ static bool ocl_HoughLines(InputArray _src, OutputArray _lines, double rho, doub if (total_lines > 0) _lines.assign(lines.rowRange(Range(0, total_lines))); else - _lines.assign(UMat(0,0,CV_32FC2)); + _lines.release(); return true; } @@ -857,7 +857,7 @@ static bool ocl_HoughLinesP(InputArray _src, OutputArray _lines, double rho, dou int total_points = counters.getMat(ACCESS_READ).at(0, 0); if (total_points <= 0) { - _lines.assign(UMat(0,0,CV_32SC4)); + _lines.release(); return true; } @@ -885,7 +885,7 @@ static bool ocl_HoughLinesP(InputArray _src, OutputArray _lines, double rho, dou if (total_lines > 0) _lines.assign(lines.rowRange(Range(0, total_lines))); else - _lines.assign(UMat(0,0,CV_32SC4)); + _lines.release(); return true; }