OpenCV 的 RotatedRect 角度没有提供足够的信息 [英] OpenCV's RotatedRect angle does not provide enough information
问题描述
根据我的实验,RotatedRect 的角度变量返回的角度从 -90 到 0 度,这不足以确定对象是向左倾斜还是向右倾斜.
例如,如果角度是 -45 度,我们不能说是需要旋转 +45 度还是 -45 度来进行歪斜.
我正在使用的代码摘录:
RotatedRect rotate_rect = minAreaRect(contour);浮动 blob_angle_deg = 旋转矩形角;Mat mapMatrix = getRotationMatrix2D(center, blob_angle_deg, 1.0);
将物体向一个方向倾斜,我得到的角度从 0 到 -90 度,而将物体向另一个方向倾斜,我得到的角度从 -90 到 0 度.
我怎样才能找到我应该旋转我的图像以歪斜它的角度?
借鉴Sebastian Schmitz和Michael Burdinov 回答我是这样解决的:
RotatedRect rotate_rect = minAreaRect(contour);浮动 blob_angle_deg = 旋转矩形角;如果 (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
.p>
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.
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);
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?
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);
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屋!