OpenCV的RotatedRect角度无法提供足够的信息 [英] OpenCV's RotatedRect angle does not provide enough information
问题描述
根据我的实验,RotatedRect的angle变量返回的角度从-90到0度,这不足以确定对象是向左倾斜还是向右倾斜.
From my experiments, the angle returned by RotatedRect's angle variable goes from -90 to 0 degrees, which is not sufficient to determine if the object is leaned to the left or right.
例如,如果角度为-45度,则无法确定是否需要旋转+45或-45度以使其倾斜.
For example, if the angle is -45 degrees, we cannot say if we need to rotate +45 or -45 degrees to deskew it.
我正在使用的代码的摘录:
An excerpt of the code I'm using:
RotatedRect rotated_rect = minAreaRect(contour);
float blob_angle_deg = rotated_rect.angle;
Mat mapMatrix = getRotationMatrix2D(center, blob_angle_deg, 1.0);
将物体向一个方向倾斜,角度为0到-90度,而向另一个方向倾斜,角度则为-90到0度.
Leaning the object in one direction I get angles from 0 to -90 degrees, while leaning the object to the other direction I get angles from -90 to 0 degrees.
如何找到旋转图像以使其倾斜的角度?
How can I find the angle by which I should rotate my image to deskew it?
推荐答案
从塞巴斯蒂安·施密茨(Sebastian Schmitz)和 Michael Burdinov 回答了这是我解决的方法:
After learning from Sebastian Schmitz and Michael Burdinov answers this is how I solved it:
RotatedRect rotated_rect = minAreaRect(contour);
float blob_angle_deg = rotated_rect.angle;
if (rotated_rect.size.width < rotated_rect.size.height) {
blob_angle_deg = 90 + blob_angle_deg;
}
Mat mapMatrix = getRotationMatrix2D(center, blob_angle_deg, 1.0);
因此,实际上,RotatedRect的角度不能提供足够的信息来了解对象的角度,因此还必须使用RotatedRect的size.width
和size.height
.
So, in fact, RotatedRect's angle does not provide enough information for knowing an object's angle, you must also use RotatedRect's size.width
and size.height
.
这篇关于OpenCV的RotatedRect角度无法提供足够的信息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!