TITLE: Calculating the distance between a camera and a target using camera output
QUESTION [5 upvotes]: I have a 640x480 camera that recognizes a rectangle that is 1ftx2ft. Is it possible to calculate the distance between the camera and the rectangle?
Edit: 
The horizontal angle of view is 54°.

REPLY [3 votes]: $$D=\frac{Lw}{2x\tan\frac\alpha2}$$ where $D$ = Distance from Camera, $L$ = length of object (2ft), $w$=width of screen in pixels (640), $x$=width of object on camera in pixels, and $\alpha$ = camera field of view.