Update seamless_cloning.cpp#12512
Conversation
| mask.copyTo(gray); | ||
| } | ||
|
|
||
| rectangle(gray, Rect(0, 0, gray.cols, gray.rows), Scalar(0), 1); |
There was a problem hiding this comment.
Looks like this line clears whole "gray" to zero, so result from lines above is lost.
It is better to avoid using drawing functions (they are not optimized):
gray(Rect(0, 0, gray.cols, gray.rows)).setTo(Scalar(0));
There was a problem hiding this comment.
"Looks like this line clears whole "gray" to zero" No, only 1 pixel border set to zero.
alternative to drawing function maybe like
gray.col(0).setTo(Scalar(0));
gray.col(gray.cols - 1).setTo(Scalar(0));
gray.row(0).setTo(Scalar(0));
gray.row(gray.rows - 1).setTo(Scalar(0));
There was a problem hiding this comment.
rectangle is faster according the code below
1.9021sec
0.855161sec
Mat gray = Mat(1000, 1000, CV_8UC1, Scalar(255));
TickMeter tm;
tm.start();
for (int i = 0; i < 100000; i++)
{
gray.col(0).setTo(Scalar(0));
gray.col(gray.cols - 1).setTo(Scalar(0));
gray.row(0).setTo(Scalar(0));
gray.row(gray.rows - 1).setTo(Scalar(0));
}
tm.stop();
cout << tm << endl;
tm.reset();
tm.start();
for (int i = 0; i < 100000; i++)
{
rectangle(gray, Rect(0, 0, gray.cols, gray.rows), Scalar(0), 1);
}
tm.stop();
cout << tm << endl;
There was a problem hiding this comment.
Right, my bad.
4 setTo() calls are good here.
Alternative way (but probably slower):
Mat gray_inner = gray(Rect(1, 1, gray.cols - 2, gray.rows - 2));
copyMakeBorder(gray_inner, gray, 1, 1, 1, 1, BORDER_ISOLATED | BORDER_CONSTANT, Scalar::all(0));
|
Well done! As a bugfix this patch should go into 3.4 branch. We will merge changes from 3.4 into master regularly (weekly/bi-weekly). So, please:
Note: no needs to re-open PR, apply changes "inplace". |
This pullrequest changes
resolves #12496
proposed solution guarantees that mask will have at least one pixel black border. This seems solving the actual problem.
P.S. : actual code is broken without error message when the mask is empty. So i will edit other cloning types later if the proposed patch is acceptable.