Question: I have a video file recorded from the front of a moving vehicle. I am going to use OpenCV for object detection and recognition but I'm stuck on one aspect. How can I determine the distance from a recognized object. 

I can know my current speed and real-world GPS position but that is all. I can't make any assumptions about the object I'm tracking. I am planning to use this to track and follow objects without colliding with them. Ideally I would like to use this data to derive the object's real-world position, which I could do if I could determine the distance from the camera to the object.

Answer: 
When you have moving video, you can **use temporal parallax** to determine the relative distance of objects. Parallax: ([definition](http://en.wikipedia.org/wiki/Parallax)).

The effect would be the same we get with our eyes which which can gain depth perception by looking at the same object from slightly different angles. Since you are moving, you can use two successive video frames to get your slightly different angle.

Using parallax calculations, you can determine the *relative* size and distance of objects (relative to one another). But, if you want the *absolute* size and distance, you will need a known point of reference.

You will also need to know the speed and direction being traveled (as well as the video frame rate) in order to do the calculations. You *might* be able to derive the speed of the vehicle using the visual data but that adds another dimension of complexity.

The technology already exists. Satellites determine [topographic prominence](http://en.wikipedia.org/wiki/Topographic_prominence) (height) by comparing multiple images taken over a short period of time. We use parallax to determine the distance of stars by taking photos of night sky at different points in earth's orbit around the sun. I was able to create 3-D images out of an airplane window by taking two photographs within short succession. 

The exact technology and calculations (even if I knew them off the top of my head) are *way* outside the scope of discussing here. If I can find a decent reference, I will post it here.
use stereo disparity maps. lots of implementations are afloat, here are some links:
<http://homepages.inf.ed.ac.uk/rbf/CVonline/LOCAL_COPIES/OWENS/LECT11/node4.html>

<http://www.ece.ucsb.edu/~manj/ece181bS04/L14(morestereo).pdf>

In you case you don't have stereo camera, but depth can be evaluated using video
<http://www.springerlink.com/content/g0n11713444148l2/>

I think the above will be what might help you the most.

research has progressed so far that depth can be evaluated ( though not to a satisfactory extend) from a single monocular image 
<http://www.cs.cornell.edu/~asaxena/learningdepth/>