简体   繁体   English

在OpenCV中测量角度的参考点是什么?

[英]What is the reference point for measuring angles in OpenCV?

I'm trying to infer an object's direction of movement using dense optical flow in OpenCV. 我试图在OpenCV中使用密集光流来推断物体的运动方向。 I'm using calcOpticalFlowFarneback() to get flow coordinates and cartToPolar() to acquire vector angles which would indicate direction. 我正在使用calcOpticalFlowFarneback()获取流量坐标,使用cartToPolar()来获取指示方向的矢量角度。

To interpret the results I need to know the reference point for measuring the angle. 为了解释结果,我需要知道测量角度的参考点。 I have found this blog post indicating that the range of angles is 360°. 我发现这篇博文表明角度范围是360°。 That tells me that the angle measurement would go along the lines of the unit circle. 这告诉我角度测量将沿着单位圆的线。 I couldn't make out much more than that. 我无法理解这一点。

The documentation for cartToPolar() doesn't cover this and my attempts at testing it have failed. cartToPolar()的文档没有涵盖这一点,我测试它的尝试失败了。

It seems that the angle produced by cartToPolar() is in reference to the unit circle rotated clockwise by 90° centered on the image coordinate starting point in the top left corner. 似乎cartToPolar()产生的角度是指在左上角的图像坐标起点上以顺时针方向旋转90°的单位圆。 It would look like this. 它看起来像这样。

I came to this conclusion by using the dense optical flow example provided by OpenCV. 我通过使用OpenCV提供的密集光流示例得出了这个结论。 I replaced the line hsv[...,0] = ang*180/np.pi/2 with hsv[...,0] = ang*180/np.pi to get correct angle conversion from radians. 我取代了线hsv[...,0] = ang*180/np.pi/2hsv[...,0] = ang*180/np.pi以获得从弧度正确的角度转换。 Then I tested a video with people moving from top right to bottom left and vice versa. 然后我测试了一个视频,人们从右上角移动到左下角,反之亦然。 I sampled the dominant color with GIMP and got RGB values which I converted to HSV values. 我用GIMP对主色进行采样并得到RGB值,我将其转换为HSV值。 Hue value corresponds to the angle in degrees. 色调值对应于以度为单位的角度。

People moving from top right to bottom left produced an angle of about 300° and people moving the other way round produced an angle of about 120°. 从右上角向左下方移动的人产生大约300°的角度,而相反移动的人产生大约120°的角度。 This hinted at the way the unit circle is positioned. 这暗示了单位圆的定位方式。

Looking at the code , fastAtan32f is used to compute the angles. 查看代码fastAtan32f用于计算角度。 and that seems to be a atan2 implementation. 这似乎是一个atan2实现。

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

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