Processing cv :: RotatedRect width and height

I need to determine a rotating rectangle from its 4 corners. A rotating rectangle is defined by a center point, size (width, height) and angle.

How is it determined which size is height and which is width?

Width is not the length of the horizontal edge itself, is it? For instance. if the angle is greater than 90 °, does it swap places?

+4
source share
2 answers

heightshould be the largest side, width- the other, and angle- the rotation angle (in degrees) clockwise.

Otherwise, you can get an equivalent rectangle with heightand widthwith a replacement rotated 90 degrees.


minAreaRect RotatedRect:

vector<Point> pts = {pt1, pt2, pt3, pt4}

RotatedRect box = minAreaRect(pts);

// Be sure that largest side is the height
if (box.size.width > box.size.height)
{
    swap(box.size.width, box.size.height);
    box.angle += 90.f;
}
+1

, Miki, ...

, ( , )... !

y , . (y ) . , , ++ <math.h> include atan2(y,x) ( , ).

, , ( ), , atan2 y x. - :

 Point pt1, pt2, pt3, pt4;
 RotatedRect rect;

 rect.center = (pt1 + pt2 + pt3 + pt4)/4;

 // assuming the points are already sorted
 rect.size.width = distance(pt1, pt2); // sqrt(...)
 rect.size.height = distance(pt2, pt3);

 rect.angle = atan2(pt2.y-pt1.y, pt2.x-pt1.x);

, width dist(pt1,pt2) dist(pt3,pt4), . height.

angle atan (pt1, pt2) atan (pt3, pt4).

0

Source: https://habr.com/ru/post/1668021/


All Articles