opencv实现对象跟踪
介绍 (Introduction)
Tracking the distance and angle of an object has many practical uses, especially in robotics. This tutorial explains how to get an accurate distance and angle measurement, even when the target is at a strong angle from the camera.
跟踪物体的距离和角度有许多实际用途,尤其是在机器人技术中。 本教程说明了即使目标物与相机成强角时也如何获得准确的距离和角度测量。
开始之前 (Before we start)
Download the demo here!
在此处下载演示!
如何准确跟踪任意角度的距离 (How to accurately track distance at any angle)
Building off this article, we know that we can approximate the distance as long as we have the width of the target in pixels and cm/inches at a known distance.
建立关此文章中,我们知道,我们可以近似的距离,只要我们有目标的像素和英寸/厘米宽度的已知距离。
focal length = (known pixel Width * knownDistance) / known width
焦距 =(已知像素宽度*已知距离)/已知宽度
Distance (cm/inches/etc.) =( known Width * focal length) / pixel Width
距离(厘米/英寸/等) =(已知宽度*焦距)/像素宽度
When using width to approximate distance, the width gets smaller at an angle, decreasing the accuracy.
当使用宽度近似距离时,宽度会成一定角度变小,从而降低精度。
Instead, fitted height should be used to calculate distance, because the fitted height will always stay the same, no matter what angle.
相反,应该使用拟合高度来计算距离,因为无论高度如何,拟合高度都将始终保持不变。
Therefore, to calculate distance using fitted height, use these equations:
因此,要使用适合的高度计算距离,请使用以下公式:
focal length = (known pixel Height * knownDistance) / known height
焦距 =(已知像素高度*已知距离)/已知高度
Distance (cm/inches/etc.) = (known height * focal length) / pixel height
距离(厘米/英寸/等) =(已知高度*焦距)/像素高度
This approximation works as long as the height of the target stays the same. Also remember to use fitted height instead of bounding height because fitted height tilts with the object and bounding height does not.
只要目标的高度保持不变,这种近似就起作用。 还要记住使用拟合高度而不是边界高度,因为拟合高度会随对象倾斜而边界高度不会倾斜。
如何近似目标相对于相机的角度 (How to approximate angle of a target relative to the camera)
Angle can be approximated as long as the ratio between the target’s width and height is known.
只要知道目标的宽度和高度之比,就可以近似角度。
When there is no change in the width, the angle is 0°. When the width is barely visible, the angle is approaching 90°.
宽度不变时,角度为0°。 当几乎看不到宽度时,角度接近90°。
As long as the target’s height remains the same, we can use the height and ratio to approximate the width at 0°. Therefore, we have the theoretical width, at 0°, and the actual width at x°. The actual width should always be less than the theoretical width because the width is greatest at 0°. Dividing the actual width by the theoretical width will yield a number between 0 and 1, representing the percent change in angle. Now we want to scale a number between 0 and 1 to a number between 0 and 90 to represent degrees.
只要目标的高度保持不变,我们就可以使用高度和比率近似于0°处的宽度。 因此,我们的理论宽度为0°,实际宽度为x°。 实际宽度应始终小于理论宽度,因为该宽度在0°处最大。 将实际宽度除以理论宽度将得到一个介于0和1之间的数字,代表角度的百分比变化。 现在我们要缩放0到1之间的数字到0到90之间的数字以表示度。
Because 1 represents zero change in width and 90° represents that there is no width, we subtract 1 by the ratio between actual width and theoretical width to get the opposite angle.
由于1表示宽度的零变化,而90°表示没有宽度,因此我们将实际宽度与理论宽度之比减去1以获得相反的角度。
Then, multiply that number by 90 to get an angle estimate between 0 and 90.
然后,将该数字乘以90,即可获得介于0到90之间的角度估计。
Simplified angle estimation equations:
简化的角度估算公式:
Angle = 1 — (actual width / ratio between width and height of target) * 90
角度 = 1-(实际宽度/目标宽度与高度的比率)* 90
Angle = (1 — (actual width * target height) / target width) * 90
角度 =(1-(实际宽度*目标高度)/目标宽度)* 90
That’s it! Now you can estimate the angle of a target relative to the camera.
而已! 现在,您可以估计目标相对于摄像机的角度。
Side note: This only works when the target’s height does not change, and when the target has distinct edges.
旁注:仅当目标的高度不变且目标具有明显的边缘时,此方法才有效。
试试演示! (Try the demo!)
Download the demo here!
在此处下载演示!
Using the demo, you can set a target color and enter the variables to get the distance and angle of the target object.
使用演示,您可以设置目标颜色并输入变量以获取目标对象的距离和角度。
回顾变量 (Recap of the variables)
Known Width: width of the object in any physical unit (Ex: cm, inches)
已知宽度:对象的宽度,以任何物理单位表示(例如:厘米,英寸)
Known Height: height of the object in any physical unit (Ex: cm, inches)
已知高度:物体在任何物理单位中的高度(例如:厘米,英寸)
Known distance from object: any distance from the camera to the object in the chosen unit above.
距物体的已知距离:从摄像机到上方所选单位的物体之间的任何距离。
Pixel height at above distance from camera: pixel height of the object when the distance is the same as the known distance from object.
距相机的距离以上的像素高度:当距离与已知的距对象的距离相同时,对象的像素高度。
翻译自: https://medium.com/analytics-vidhya/how-to-track-distance-and-angle-of-an-object-using-opencv-1f1966d418b4
opencv实现对象跟踪
本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/389649.shtml
如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!