简体   繁体   中英

How to create cv::RotatedRect from two cv::Point2f?

I have two cv::Point2f points, representing the top left and bottom right corners of a rectangle.

Is there a simple way in OpenCV to create cv::RotatedRect from them ?

There is no RotatedRect constructor from two corner points (as in cv::Rect) precisely because we need to know the rotation angle.

If we assume this is a 'straight' rectangle we can do something like:

Point a(0,0);   // corner point A
Point b(10,10); // corner point B
float angle = 0.f;


RotatedRect rr(0.5*(a+b), // center 
               Size2f((float)fabs(a.x-b.x),fabs(a.y-b.y)), // size
               angle);

As you see this is not as "simple" as in the cv::Rect case though.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM