cv::Mat::copyTo() does not fail on wrong sized masks (Bug #3319)
When using using cv::Mat::copyTo() with a mask of the wrong size the function works with bad results.
Here is a code snippet demonstrating this:
cv::Mat src(cv::Size(1024,768), CV_8UC3); src.setTo(255); cv::Mat dst(cv::Mat::zeros(cv::Size(1024,768), CV_8UC3)); cv::Mat msk(cv::Mat::zeros(dst.size()+cv::Size(2,2), CV_8UC1)); // mask is slightly bigger than dst and src. cv::circle(msk, cv::Point(555,333), 100, cv::Scalar(255),-1); src.copyTo(dst,msk); imshow("msk",msk); imshow("dst",dst); waitKey();
That commit introduces problems, as it breaks certain use cases of
OpenCV functions; for example, convertTo of an Nx1 matrix to an
Since vectors can't store separate width and height values, OpenCV
considers them to always be 1xN. So even though the vector is created with
.create(N, 1), the Mat passed to getContinousSize has dimensions 1xN,
and the size comparison fails, even though the operation itself is safe.
This is a use case we probably don't want to break, at the very least
for backwards compatibility. So I'm reverting the commit. This will also
unfix bug #3319; I'll submit a less intrusive solution as a PR to 2.4, which
will also revert 4f9c081 there.
Revert "fixed bug #3319"
See 092f916 for explanation.
This reverts commit 4f9c081dc313f8fdfee3f0a4572779ae13e27e40.