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.pswp.cn/news/389649.shtml 繁體地址,請注明出處:http://hk.pswp.cn/news/389649.shtml 英文地址,請注明出處:http://en.pswp.cn/news/389649.shtml
如若內容造成侵權/違法違規/事實不符,請聯系多彩編程網進行投訴反饋email:809451989@qq.com,一經查實,立即刪除!