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.
Download the demo here!
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.
#object-detection #opencv #computer-vision #python #computer-science