mirror of
https://github.com/opencv/opencv.git
synced 2025-01-18 06:03:15 +08:00
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
This commit is contained in:
parent
e51d7cb3d8
commit
451340fd3d
@ -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]);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user