1 | initial version |
The x and y variables are the location of the top left corner in the image. Width and Height are just that. So a rectangle from (100,120) to (200,250) would be x = 100, y = 120, width = 100, height = 130.
To get the distance, you have to know the relationship between number of pixels and distance. Fortunately, this is easy to get. Take a picture of something with a known dimension, at a known distance. Use the known object size and the known distance to calculate the field of view of the camera. The important number is actually instantaneous field of view, which is FOV/number of pixels. You probably have two FOVs, one for vertical, and one for horizontal. The IFOV is probably the same for both directions though.
Once you have the IFOV and the known object sizes, you can use them to get the object distance.