简体   繁体   中英

Android Opencv calculate size of rotated image inside rectangle

I want to calculate rotated image size, Image is inside rectangle. I have rectangle width, height and angle of rotated image. Any one tell me how to calculate rotated image size? 在此处输入图片说明

So you have width, height and angle means you already got RotatedRect .

Now using the method

Rect RotatedRect::boundingRect();

you can easly calculate the bounding box for rotated rect.

for more info see RotatedRect .

Edit:

As per your comment below is the way how to find the width and height of rotated rect.

So you know the four corners of rectangle, lets say (x1,y1),(x2,y2),(x3,y3),(x4,y4), now you need to find the transformed point after rotation by the given angle, let it be (xT1,yT1),(xT2,yT2),etc...

where

xT = x0+(x-x0)*cos(theta)+(y-y0)*sin(theta)
yT = y0-(x-x0)*sin(theta)+(y-y0)*cos(theta)

here (x0,y0) is the center around which you are rotating. and theta = angle * CV_PI / 180.0

Using above calculate four transformed points, finally calculate the height and width by finding the distance between transformed points.

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