Skip to content

Fix #4363 - wrong hierarchy (RETR_TREE) in findContours#19951

Merged
alalek merged 3 commits intoopencv:3.4from
stal12:3.4
Apr 22, 2021
Merged

Fix #4363 - wrong hierarchy (RETR_TREE) in findContours#19951
alalek merged 3 commits intoopencv:3.4from
stal12:3.4

Conversation

@stal12
Copy link
Copy Markdown
Contributor

@stal12 stal12 commented Apr 20, 2021

This pull requests slightly modifies the behaviour of findContours() when the mode flag is set to RETR_TREE, in order to avoid a subtle bug.

In the uncommon case that the same border pixel belongs to two different contours marked with the same index, it is important to be able to tell which of the two contours is the "last one encountered", in order to reliably find a father for the next contour met during the scan. This pull request address that specific case.

Pull Request Readiness Checklist

See details at https://github.com/opencv/opencv/wiki/How_to_contribute#making-a-good-pull-request

  • I agree to contribute to the project under Apache 2 License.
  • To the best of my knowledge, the proposed patch is not based on a code under GPL or other license that is incompatible with OpenCV
  • The PR is proposed to proper branch
  • There is reference to original bug report and related work
  • There is accuracy test, performance test and test data in opencv_extra repository, if applicable
    Patch to opencv_extra has the same branch name.
  • The feature is well documented and sample code can be built with the project CMake
force_builders=linux,docs

@alalek
Copy link
Copy Markdown
Member

alalek commented Apr 20, 2021

Thank you for the contribution!

Could you please add simple regression test for that case?

Copy link
Copy Markdown
Member

@alalek alalek left a comment

Choose a reason for hiding this comment

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

Thank you for contribution 👍

@alalek alalek merged commit 1b64851 into opencv:3.4 Apr 22, 2021
@stal12 stal12 deleted the 3.4 branch April 23, 2021 10:38
@alalek alalek mentioned this pull request May 1, 2021
danielenricocahall pushed a commit to danielenricocahall/opencv that referenced this pull request May 27, 2021
* Fix opencv#4363 - wrong hierarchy (CV_RETR_TREE) in findContours

* Add regression test for findContours

* use C++11 => C++98 on 3.4 branch
@alalek alalek mentioned this pull request Jun 4, 2021
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.

2 participants