Parchuri Poojith Kumar 296cb2053f imgproc: do not put a bogus vertex into the result of approxPolyN (#31068)
* imgproc: do not put a bogus vertex into the result of approxPolyN

A vertex can only be contracted if the lines of the two edges next to the removed edge meet beyond it. For parallel edges, as in a rectangle, the code marked the vertex with the area FLT_MAX and the point (-1, -1), but still contracted it when nothing else was left, so the point (-1, -1) ended in the result. Nearly parallel edges, like in a regular octagon, gave a vertex billions of units away, because the check for parallel edges used a fixed threshold. Test for parallel edges relative to the edge lengths, treat edges that diverge the same way, and stop when no vertex can be contracted, as the documentation already allows for the epsilon limit. The result for any polygon that could be contracted is unchanged. Add tests and a note to the documentation.

* imgproc: add tests with nearly parallel sides for approxPolyN

The tests with a rectangle and an octagon with integer coordinates only have exactly parallel sides, which the old check for 1e-8 rejected as well. Add a test with a square whose top side is tilted by about 2e-7 radians, which gave a vertex 4e8 units away, and a test with regular octagons computed with float cos and sin for 16 rotations, which gave vertices billions of units away for some of them.
2026-11-24 17:52:26 +05:30
2026-09-17 12:00:11 +03:00
2020-02-26 15:12:45 +03:00
2018-10-11 17:57:51 +00:00
2025-08-01 09:50:10 +03:00

OpenCV: Open Source Computer Vision Library

Resources

Contributing

Please read the contribution guidelines before starting work on a pull request.

Summary of the guidelines:

  • One pull request per issue;
  • Choose the right base branch;
  • Include tests and documentation;
  • Clean up "oops" commits before submitting;
  • Follow the coding style guide.

Additional Resources

Description
Languages
C++ 87.7%
C 3.1%
Python 2.9%
CMake 2%
Java 1.5%
Other 2.6%