Skip to content

MinAreaRect fix rotating calipers#20533

Merged
opencv-pushbot merged 2 commits intoopencv:3.4from
AleksandrPanov:minAreaRect_fix_rotatingCalipers
Aug 11, 2021
Merged

MinAreaRect fix rotating calipers#20533
opencv-pushbot merged 2 commits intoopencv:3.4from
AleksandrPanov:minAreaRect_fix_rotatingCalipers

Conversation

@AleksandrPanov
Copy link
Copy Markdown
Contributor

@AleksandrPanov AleksandrPanov commented Aug 11, 2021

resolves #19769

To fix for #19769 (also all samples from #11915 work).

  1. Error in function static void rotatingCalipers( const Point2f* points, int n, int mode, float* out ).
  2. Calculating the minimum angle between calipers side and polygon edge using the cosine results in an incorrect angle due to limited arithmetic accuracy.
  3. Replaced vector sorting by angle cosine with sorting with custom comparator. The comparator determins vector order by dot product sign to fix floating point accuracy issue with colinear and close to colinear vectors.
  4. Added tests "reproducer_19769" and "reproducer_19769_lightweight".

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
allow_multiple_commits=1

@AleksandrPanov
Copy link
Copy Markdown
Contributor Author

Also created a reproducer_19769_lightweight test from defect_contour.txt (#19769). This test contains only 23 points and reproduces the problem.
convexHull22

The new angle calculation algorithm solves the problem.
convexHull22

Also the algorithm correctly finds the minimum area rectangle.
convexHull9

@AleksandrPanov AleksandrPanov force-pushed the minAreaRect_fix_rotatingCalipers branch from dc24930 to 8e16126 Compare August 11, 2021 09:42
@AleksandrPanov AleksandrPanov force-pushed the minAreaRect_fix_rotatingCalipers branch from 8e16126 to 8199967 Compare August 11, 2021 16:09
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.

Well done 👍

@opencv-pushbot opencv-pushbot merged commit 266a868 into opencv:3.4 Aug 11, 2021
@alalek alalek mentioned this pull request Aug 14, 2021
@alalek alalek mentioned this pull request Oct 15, 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.

5 participants