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?
Asked
Active
Viewed 1,093 times
1

Nouman Bhatti
- 1,777
- 4
- 28
- 55
-
For clarification, you have h, w and theta(as shown in image) of the blue rectangle. And you want to calculate area of blue rectangle? I must be missing something because it is not a question in itself :P – Pervez Alam Jun 18 '14 at 07:09
-
@PervezAlam I have outer rectangle width, height, now i want to have inner rotated image size. – Nouman Bhatti Jun 18 '14 at 07:27
-
h x sin(θ) + w x cos(θ) = bh; h x cos(θ) + w x sin(θ) = bw; You can solve above two equations for 2 variables h, w, as you said θ is known. – Pervez Alam Jun 18 '14 at 08:04
-
We can get size of outer rectangle but cant get size of rotated image. – Nouman Bhatti Jun 18 '14 at 08:08
-
if you solve the above equations for h, w; it will give you dimension of inner rectangle also. If you see any difficulty, please lemme know. – Pervez Alam Jun 18 '14 at 08:10
-
Inner rotated image size must be smaller than outer rectangle if we use these formulas? – Nouman Bhatti Jun 18 '14 at 09:27
-
Your given formula are giving negative values for width, height. – Nouman Bhatti Jun 18 '14 at 09:32
-
Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/55832/discussion-between-pervez-alam-and-nouman-bhatti). – Pervez Alam Jun 18 '14 at 10:44
-
@NoumanBhatti Have you seen the answer here http://stackoverflow.com/questions/9971230/calculate-rotated-rectangle-size-from-known-bounding-box-coordinates – Haris Jun 19 '14 at 16:11
-
Yes, I tried with this , i'm not getting smaller values(width, height) than outer bounds. Only for few angles it is working. – Nouman Bhatti Jun 20 '14 at 04:38
1 Answers
0
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.

Haris
- 13,645
- 12
- 90
- 121
-
I have outer rectangle width, height, now i want to have inner rotated image size. – Nouman Bhatti Jun 18 '14 at 05:25
-
Ok, I misunderstand your question, I thought all the data is of rotated rect and you need to find the bounding rect. – Haris Jun 18 '14 at 05:45
-
I'm always getting width, height of rotated image greater than outer rectangle. If i'm not wrong my rotated image width, height must be less than outer rectangle. – Nouman Bhatti Jun 19 '14 at 05:21
-
1I'm now using this formula to get width height after getting all point using you formula. So using this link i'm getting the same width, height i have of outer rectangle. [10:51:47 AM] Farrakh Javed: http://www.mathopenref.com/coordrectangle.html – Nouman Bhatti Jun 19 '14 at 05:53