cv::Mat::copyTo() does not fail on wrong sized masks (Bug #3319)


Added by Adi Shavit over 3 years ago. Updated about 3 years ago.


Status:Done Start date:2013-10-14
Priority:Normal Due date:
Assignee:Ilya Lavrenov % Done:

0%

Category:core
Target version:Next Hackathon
Affected version:2.4.8 (latest release) Operating System:Windows
Difficulty: HW Platform:x64
Pull request:

Description

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();


Associated revisions

Revision 092f916d
Added by Roman Donchenko about 3 years ago

Revert 4f9c081

That commit introduces problems, as it breaks certain use cases of
OpenCV functions; for example, convertTo of an Nx1 matrix to an
std::vector.

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.

Revision f0220484
Added by Roman Donchenko about 3 years ago

Revert "fixed bug #3319"

See 092f916 for explanation.

This reverts commit 4f9c081dc313f8fdfee3f0a4572779ae13e27e40.

Revision ee97a5e7
Added by Roman Donchenko about 3 years ago

Re-fix bug #3319 with less side effects.

Revision 5e986f33
Added by Ilya Lavrenov about 3 years ago

fixed bug #3319
(cherry picked from commit 4f9c081dc313f8fdfee3f0a4572779ae13e27e40)

History

Updated by Kirill Kornyakov over 3 years ago

  • Target version set to Next Hackathon
  • Status changed from New to Open

Updated by Daniil Osokin about 3 years ago

  • Affected version changed from 2.4.0 - 2.4.5 to 2.4.0 - 2.4.7
  • Assignee changed from Vadim Pisarevsky to Ilya Lavrenov
  • Status changed from Open to Done

Updated by Daniil Osokin about 3 years ago

  • Affected version changed from 2.4.0 - 2.4.7 to 2.4.8 (latest release)

Also available in: Atom PDF