diff --git a/modules/core/src/arithm.cpp b/modules/core/src/arithm.cpp index 5ea596ffc6..e3ded859b6 100644 --- a/modules/core/src/arithm.cpp +++ b/modules/core/src/arithm.cpp @@ -1233,7 +1233,7 @@ 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()) + if(_src1.empty() || _src2.empty()) { _dst.release(); return; diff --git a/modules/core/src/copy.cpp b/modules/core/src/copy.cpp index b8a52f2f5a..8775bff4aa 100644 --- a/modules/core/src/copy.cpp +++ b/modules/core/src/copy.cpp @@ -411,6 +411,8 @@ Mat& Mat::operator = (const Scalar& s) { CV_INSTRUMENT_REGION() + if (empty()) return *this; + const Mat* arrays[] = { this }; uchar* dptr; NAryMatIterator it(arrays, &dptr, 1); diff --git a/modules/core/src/rand.cpp b/modules/core/src/rand.cpp index 7b7f8ed9b6..a456c72633 100644 --- a/modules/core/src/rand.cpp +++ b/modules/core/src/rand.cpp @@ -511,6 +511,8 @@ static RandnScaleFunc randnScaleTab[] = void RNG::fill( InputOutputArray _mat, int disttype, InputArray _param1arg, InputArray _param2arg, bool saturateRange ) { + if (_mat.empty()) + return; Mat mat = _mat.getMat(), _param1 = _param1arg.getMat(), _param2 = _param2arg.getMat(); int depth = mat.depth(), cn = mat.channels(); AutoBuffer _parambuf; diff --git a/modules/core/test/test_rand.cpp b/modules/core/test/test_rand.cpp index 82bb6104a9..8677aa0c31 100644 --- a/modules/core/test/test_rand.cpp +++ b/modules/core/test/test_rand.cpp @@ -168,11 +168,12 @@ void Core_RandTest::run( int ) { tested_rng = saved_rng; int sz = 0, dsz = 0, slice; - for( slice = 0; slice < maxSlice; slice++, sz += dsz ) + for( slice = 0; slice < maxSlice && sz < SZ; slice++, sz += dsz ) { - dsz = slice+1 < maxSlice ? (int)(cvtest::randInt(rng) % (SZ - sz + 1)) : SZ - sz; + dsz = slice+1 < maxSlice ? (int)(cvtest::randInt(rng) % (SZ - sz) + 1) : SZ - sz; Mat aslice = arr[k].colRange(sz, sz + dsz); tested_rng.fill(aslice, dist_type, A, B); + printf("%d - %d\n", sz, sz + dsz); } } diff --git a/modules/imgproc/test/test_grabcut.cpp b/modules/imgproc/test/test_grabcut.cpp index eae8b3e482..7bf6555a0c 100644 --- a/modules/imgproc/test/test_grabcut.cpp +++ b/modules/imgproc/test/test_grabcut.cpp @@ -89,7 +89,6 @@ void CV_GrabcutTest::run( int /* start_from */) Mat exp_bgdModel, exp_fgdModel; Mat mask; - mask = Scalar(0); Mat bgdModel, fgdModel; grabCut( img, mask, rect, bgdModel, fgdModel, 0, GC_INIT_WITH_RECT ); bgdModel.copyTo(exp_bgdModel);