Skip to content

Update seamless_cloning.cpp#12512

Merged
opencv-pushbot merged 1 commit intoopencv:3.4from
sturkmen72:patch-1
Sep 14, 2018
Merged

Update seamless_cloning.cpp#12512
opencv-pushbot merged 1 commit intoopencv:3.4from
sturkmen72:patch-1

Conversation

@sturkmen72
Copy link
Copy Markdown
Contributor

@sturkmen72 sturkmen72 commented Sep 12, 2018

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.

mask.copyTo(gray);
}

rectangle(gray, Rect(0, 0, gray.cols, gray.rows), Scalar(0), 1);
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

@alalek
Copy link
Copy Markdown
Member

alalek commented Sep 14, 2018

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:

  • change "base" branch of this PR: master => 3.4 (use "Edit" button near PR title)
  • rebase your commits from master onto 3.4 branch. For example:
    git rebase -i --onto upstream/3.4 upstream/master
    (check list of your commits, save and quit (Esc + "wq" + Enter)
    where upstream is configured by following this GitHub guide and fetched (git fetch upstream).
  • push rebased commits into source branch of your fork (with --force option)

Note: no needs to re-open PR, apply changes "inplace".

@sturkmen72 sturkmen72 changed the base branch from master to 3.4 September 14, 2018 16:41
@opencv-pushbot opencv-pushbot merged commit 6d5f7b7 into opencv:3.4 Sep 14, 2018
@alalek alalek mentioned this pull request Sep 14, 2018
@Kepnu4 Kepnu4 mentioned this pull request Aug 13, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants