Skip to content

Commit 17faee5

Browse files
committed
imgproc: add rotatedRectangleIntersection empty input handling
1 parent ef27c11 commit 17faee5

File tree

2 files changed

+31
-0
lines changed

2 files changed

+31
-0
lines changed

modules/imgproc/src/intersection.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,12 @@ int rotatedRectangleIntersection( const RotatedRect& rect1, const RotatedRect& r
5454
// L2 metric
5555
const float samePointEps = std::max(1e-16f, 1e-6f * (float)std::max(rect1.size.area(), rect2.size.area()));
5656

57+
if (rect1.size.empty() || rect2.size.empty())
58+
{
59+
intersectingRegion.release();
60+
return INTERSECT_NONE;
61+
}
62+
5763
Point2f vec1[4], vec2[4];
5864
Point2f pts1[4], pts2[4];
5965

modules/imgproc/test/test_intersection.cpp

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -366,4 +366,29 @@ TEST(Imgproc_RotatedRectangleIntersection, regression_12221_2)
366366
EXPECT_LE(intersections.size(), (size_t)8);
367367
}
368368

369+
TEST(Imgproc_RotatedRectangleIntersection, regression_18520)
370+
{
371+
RotatedRect rr_empty(
372+
Point2f(2, 2),
373+
Size2f(0, 0), // empty
374+
0);
375+
RotatedRect rr(
376+
Point2f(50, 50),
377+
Size2f(4, 4),
378+
0);
379+
380+
{
381+
std::vector<Point2f> intersections;
382+
int interType = cv::rotatedRectangleIntersection(rr_empty, rr, intersections);
383+
EXPECT_EQ(INTERSECT_NONE, interType) << "rr_empty, rr";
384+
EXPECT_EQ((size_t)0, intersections.size()) << "rr_empty, rr";
385+
}
386+
{
387+
std::vector<Point2f> intersections;
388+
int interType = cv::rotatedRectangleIntersection(rr, rr_empty, intersections);
389+
EXPECT_EQ(INTERSECT_NONE, interType) << "rr, rr_empty";
390+
EXPECT_EQ((size_t)0, intersections.size()) << "rr, rr_empty";
391+
}
392+
}
393+
369394
}} // namespace

0 commit comments

Comments
 (0)