There are a couple of ways to calculate distance with a camera. The ones I can think of off the top of my head are:
- Figure out what part of the visual field the object occupies, and assume that higher=farther
- Use relative size--based on the law of perspective, the farther an object is, the fewer pixels it will occupy
- If the object isn't moving, you can use the laws of parallax to calculate the distance based on apparent movement at a given robot speed.