Nouman Bhatti
Nouman Bhatti

Reputation: 1837

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?enter image description here

Upvotes: 1

Views: 1161

Answers (1)

Haris
Haris

Reputation: 14053

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.

Upvotes: 0

Related Questions