mirror of
https://github.com/opencv/opencv.git
synced 2026-07-21 19:33:03 +04:00
Improve precision of RotatedRect::points
Not by much but enough to get a test to pass.
This commit is contained in:
@@ -176,14 +176,18 @@ void RotatedRect::points(Point2f pt[]) const
|
||||
float b = (float)cos(_angle)*0.5f;
|
||||
float a = (float)sin(_angle)*0.5f;
|
||||
|
||||
pt[0].x = center.x - a*size.height - b*size.width;
|
||||
pt[0].y = center.y + b*size.height - a*size.width;
|
||||
pt[1].x = center.x + a*size.height - b*size.width;
|
||||
pt[1].y = center.y - b*size.height - a*size.width;
|
||||
pt[2].x = 2*center.x - pt[0].x;
|
||||
pt[2].y = 2*center.y - pt[0].y;
|
||||
pt[3].x = 2*center.x - pt[1].x;
|
||||
pt[3].y = 2*center.y - pt[1].y;
|
||||
const float ah = a*size.height;
|
||||
const float aw = a*size.width;
|
||||
const float bh = b*size.height;
|
||||
const float bw = b*size.width;
|
||||
pt[0].x = center.x - ah - bw;
|
||||
pt[0].y = center.y + bh - aw;
|
||||
pt[1].x = center.x + ah - bw;
|
||||
pt[1].y = center.y - bh - aw;
|
||||
pt[2].x = center.x + ah + bw;
|
||||
pt[2].y = center.y - bh + aw;
|
||||
pt[3].x = center.x - ah + bw;
|
||||
pt[3].y = center.y + bh + aw;
|
||||
}
|
||||
|
||||
void RotatedRect::points(std::vector<Point2f>& pts) const {
|
||||
|
||||
@@ -585,6 +585,19 @@ TEST(Imgproc_minAreaRect, reproducer_19769)
|
||||
EXPECT_TRUE(checkMinAreaRect(rr, contour)) << rr.center << " " << rr.size << " " << rr.angle;
|
||||
}
|
||||
|
||||
TEST(Imgproc_minAreaRect, roundtrip_accuracy)
|
||||
{
|
||||
RotatedRect rect(Point2f(12.f, 56.f), Size2f(10.f, 25.f), -45.f);
|
||||
std::vector<Point2f> points;
|
||||
rect.points(points);
|
||||
RotatedRect rect_out = minAreaRect(points);
|
||||
EXPECT_LT(std::abs(rect.center.x - rect_out.center.x), 1e-5);
|
||||
EXPECT_LT(std::abs(rect.center.y - rect_out.center.y), 1e-5);
|
||||
EXPECT_LT(std::abs(rect.size.width - rect_out.size.width), 1e-5);
|
||||
EXPECT_LT(std::abs(rect.size.height - rect_out.size.height), 1e-5);
|
||||
EXPECT_LT(std::abs(rect.angle - rect_out.angle), 1e-5);
|
||||
}
|
||||
|
||||
TEST(Imgproc_minEnclosingTriangle, regression_17585)
|
||||
{
|
||||
const int N = 3;
|
||||
|
||||
Reference in New Issue
Block a user