1
0
mirror of https://github.com/opencv/opencv.git synced 2026-07-31 00:03:03 +04:00

Merge pull request #23690 from chacha21:rotatedRectangleIntersection_precision

better accuracy for _rotatedRectangleIntersection() (proposal for #23546) #23690

_rotatedRectangleIntersection() can be (statically) customized to use double instead of float for better accuracy
this is a proposal for experimentation around #23546

for better accuracy, _rotatedRectangleIntersection() could use double. It will still return cv::Point2f list for backward compatibility, but the inner computations are controlled by a typedef

- [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
- [x] There is accuracy test, performance test and test data in opencv_extra repository, if applicable
      Patch to opencv_extra has the same branch name.
- [x] The feature is well documented and sample code can be built with the project CMake
This commit is contained in:
Pierre Chatelier
2023-05-30 16:46:39 +02:00
committed by GitHub
parent c55aee1e79
commit 93d490213f
2 changed files with 45 additions and 35 deletions
@@ -486,4 +486,23 @@ TEST(Imgproc_RotatedRectangleIntersection, regression_19824)
EXPECT_LE(intersections.size(), (size_t)7);
}
TEST(Imgproc_RotatedRectangleIntersection, accuracy_23546)
{
RotatedRect r1(
Point2f(824.6421183672817f, 280.28737007069833f),
Size2f(565.0f, 140.0f),
-177.80506896972656f);
RotatedRect r2(
Point2f(567.3310438828003f, 270.42527355719545f),
Size2f(275.0f, 50.0f),
92.19493103027344f);
std::vector<Point2f> intersection;
double intersectionArea = 0;
int interType = cv::rotatedRectangleIntersection(r1, r2, intersection);
intersectionArea = (intersection.size() <= 2) ? 0. : cv::contourArea(intersection);
EXPECT_EQ(INTERSECT_PARTIAL, interType);
EXPECT_EQ(intersection.size(), (size_t)4);
ASSERT_LE(std::abs(intersectionArea-7000), 1e-1);
}
}} // namespace