From 451340fd3d2f20fb0f0f62402340bbba27314c75 Mon Sep 17 00:00:00 2001 From: Takuho NAKANO Date: Fri, 14 Sep 2018 04:26:05 +0900 Subject: [PATCH] Merge pull request #12523 from takotakot:12455_rotatedrect_constructor * Fix perpendicular decision of RotatedRect::RotatedRect Error estimation is based on #12455. * Fix abs to std::fabs and atan to std::atan --- modules/core/src/types.cpp | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/modules/core/src/types.cpp b/modules/core/src/types.cpp index 694f371..e0521ce 100644 --- a/modules/core/src/types.cpp +++ b/modules/core/src/types.cpp @@ -150,16 +150,18 @@ RotatedRect::RotatedRect(const Point2f& _point1, const Point2f& _point2, const P Vec2f vecs[2]; vecs[0] = Vec2f(_point1 - _point2); vecs[1] = Vec2f(_point2 - _point3); + double x = std::max(norm(_point1), std::max(norm(_point2), norm(_point3))); + double a = std::min(norm(vecs[0]), norm(vecs[1])); // check that given sides are perpendicular - CV_Assert( abs(vecs[0].dot(vecs[1])) / (norm(vecs[0]) * norm(vecs[1])) <= FLT_EPSILON ); + CV_Assert( std::fabs(vecs[0].ddot(vecs[1])) * a <= FLT_EPSILON * 9 * x * (norm(vecs[0]) * norm(vecs[1])) ); // wd_i stores which vector (0,1) or (1,2) will make the width // One of them will definitely have slope within -1 to 1 int wd_i = 0; - if( abs(vecs[1][1]) < abs(vecs[1][0]) ) wd_i = 1; + if( std::fabs(vecs[1][1]) < std::fabs(vecs[1][0]) ) wd_i = 1; int ht_i = (wd_i + 1) % 2; - float _angle = atan(vecs[wd_i][1] / vecs[wd_i][0]) * 180.0f / (float) CV_PI; + float _angle = std::atan(vecs[wd_i][1] / vecs[wd_i][0]) * 180.0f / (float) CV_PI; float _width = (float) norm(vecs[wd_i]); float _height = (float) norm(vecs[ht_i]); -- 2.7.4