Merge pull request #10294 from alalek:fix_copyToMask_dst_initialization

pull/10307/head
Vadim Pisarevsky 7 years ago
commit d0d2faf551
  1. 19
      modules/core/src/copy.cpp

@ -385,12 +385,21 @@ void Mat::copyTo( OutputArray _dst, InputArray _mask ) const
CV_Assert( size() == mask.size() ); CV_Assert( size() == mask.size() );
} }
uchar* data0 = _dst.getMat().data; Mat dst;
_dst.create( dims, size, type() ); {
Mat dst = _dst.getMat(); Mat dst0 = _dst.getMat();
_dst.create(dims, size, type()); // TODO Prohibit 'dst' re-creation, user should pass it explicitly with correct size/type or empty
dst = _dst.getMat();
if( dst.data != data0 ) // do not leave dst uninitialized if (dst.data != dst0.data) // re-allocation happened
dst = Scalar(0); {
#ifdef OPENCV_FUTURE
CV_Assert(dst0.empty() &&
"copyTo(): dst size/type mismatch (looks like a bug) - use dst.release() before copyTo() call to suppress this message");
#endif
dst = Scalar(0); // do not leave dst uninitialized
}
}
CV_IPP_RUN_FAST(ipp_copyTo(*this, dst, mask)) CV_IPP_RUN_FAST(ipp_copyTo(*this, dst, mask))

Loading…
Cancel
Save