简体   繁体   English

Android Opencv计算矩形内旋转图像的大小

[英]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 . 因此,您具有宽度,高度和角度意味着您已经有了RotatedRect

Now using the method 现在使用方法

Rect RotatedRect::boundingRect();

you can easly calculate the bounding box for rotated rect. 您可以轻松计算旋转矩形的边界框。

for more info see RotatedRect . 有关更多信息,请参见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... 因此,您知道矩形的四个角,假设(x1,y1),(x2,y2),(x3,y3),(x4,y4),现在您需要旋转给定角度后找到变换后的点,设为(xT1,yT1),(xT2,yT2)等

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. 这里(x0,y0)是旋转的中心。 and theta = angle * CV_PI / 180.0 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. 使用上面的方法计算四个变换点,最后通过找到变换点之间的距离来计算高度和宽度。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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