Merge pull request #27149 from liane-lin:4.x

Fix #25696: Solved the problem in Subdiv2D, empty delaunay triangulation #27149

Detailed description

Expected behaviour:
Given 4 points, where no three points are collinear, the Delaunay Triangulation Algorithm should return 2 triangles.

Actual:
The algorithm returns zero triangles in this particular case.

Fix:
The radius of the circumcircle tends to infinity when the points are closer to form collinear points, so the problem occurs because the super-triangles are not large enough,
which then results in certain edges are not swapped. The proposed solution just increases the super triangle, duplicating the value of constant for example.

### Pull Request Readiness Checklist

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

- [x] I agree to contribute to the project under Apache 2 License.
- [x] To the best of my knowledge, the proposed patch is not based on a code under GPL or another license that is incompatible with OpenCV
- [x] The PR is proposed to the proper branch
- [x] There is a reference to the 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
This commit is contained in:
Liane Lin 2025-05-30 13:20:01 +01:00 committed by GitHub
parent 9f7793cdae
commit 8a0ea789e7
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 15 additions and 1 deletions

View File

@ -493,7 +493,7 @@ void Subdiv2D::initDelaunay( Rect rect )
{
CV_INSTRUMENT_REGION();
float big_coord = 3.f * MAX( rect.width, rect.height );
float big_coord = 6.f * MAX( rect.width, rect.height );
float rx = (float)rect.x;
float ry = (float)rect.y;

View File

@ -50,4 +50,18 @@ TEST(Imgproc_Subdiv2D_getTriangleList, regression_5788)
EXPECT_EQ(trig_cnt, 105);
}
TEST(Imgproc_Subdiv2D, issue_25696) {
std::vector<cv::Point2f> points{
{0, 0}, {40, 40}, {84, 104}, {86, 108}
};
cv::Rect subdivRect{cv::Point{-10, -10}, cv::Point{96, 118}};
cv::Subdiv2D subdiv{subdivRect};
subdiv.insert(points);
std::vector<cv::Vec6f> triangles;
subdiv.getTriangleList(triangles);
ASSERT_EQ(static_cast<size_t>(2), triangles.size());
}
}}