12

This is maybe not a 100% on topic photography, but I couldn't find a better stackexchange site to post this on and maybe you guys can help me out.

I have a camera that takes pictures of a production process. The objects are all pretty close by, so nothing should be in hyperfocal distance. We have an autofocus that focuses on the object. Is it possible to calculate the distance from the camera by looking at the focus position. How precise would that be. It's a passive focus. I couldn't really find any material on this. Is this done at all? Does anybody know of some references for that problem? Is this a good or bad idea?

mattdm
  • 143,140
  • 52
  • 417
  • 741
Lucas
  • 221
  • 2
  • 4
  • 2
    Interesting question - could you fill in a bit more detail please - e.g. specific camera, lens, etc. –  Dec 07 '11 at 14:48
  • Right now we use an OV5642 image sensor from OmniVision. But that is not important, we would buy whatever works the best. As you can tell I am not an expert on cameras. I just program the image processing software backend. It was just an idea I had. We use lasers for triangulation, but often have problems with reflective surfaces. So we need some sort of passive way to estimate the distance. The other alternative is of course with two cameras. But I am interested if there are ways with just one by adjusting the focus. – Lucas Dec 07 '11 at 14:54
  • 2
    Are you trying to distinguish between 10 inches away from an object 11 inches away, or an object 2 feet away and an object 10 feet away? – Paul Cezanne Dec 07 '11 at 17:40
  • Lucas, the thrust of @Paul's question is that you can indeed get fairly precise distance measurements at close distances, with dramatic reductions in precision as the distance increases. For instance, you get about +-5 mm precision at 1 m with an f/2.8 100 mm macro lens, dropping to +-550 mm precision at 10 m. Depth of field calculations can give you a sense of what a particular lens at a particular distance might be able to achieve when well calibrated and operating in good light. – whuber Dec 07 '11 at 18:15
  • Are you solely interested in determining the distance to the subject? You might have better luck with a rangefinder than with a camera. I am not sure about close distances, but I know optical rangefinders are pretty accurate at larger distances. I think there are also laser rangefinders these days as well that are extremely accurate. – jrista Dec 07 '11 at 19:13
  • @PaulCezanne: We are looking at objects that are about 20-30cm (~8-12inches) away from the camera. I would be interested in what would be feasible at those distances. How precise could I measure the distance by just playing with the focus. – Lucas Dec 07 '11 at 19:41
  • @jrista: No, there is a camera already in place for monitoring reasons. We are just trying to get more out of it. – Lucas Dec 07 '11 at 19:49
  • I just did some tests: Put down a ruler 30 cm from the lens. Using Auto Focus with a Canon EF-S 17-85 IS lens on a Canon 7D. Started subject on the ruler at 5 cm and increased the distance at 5 cm increments. The corresponding Subject Distance was as follows: 35 cm = 0.5 m | 40 cm = 0.6 m | 45 cm = 0.6 m | 50 cm = 0.7 m | 55 cm = 0.7 m | 60 cm = 0.8 m. That's off by consistent 20 cm which is suspicious, I'll try later with another lens. So it seems the EXIF is rounds to the nearest decimeter and was accurate to in movement distance, just not total distance. – Vian Esterhuizen Dec 07 '11 at 21:31
  • Also, not sure if this played a role, but the lens itself is almost 20 cm long in the state it was shooting. – Vian Esterhuizen Dec 07 '11 at 21:40
  • 1
    If you guys are currently online, it might be more useful to move to chat and discuss the options and tests real time. – jrista Dec 07 '11 at 22:11
  • @Vian focusing distance is measured from imaging plane (sensor or film), there should be a line on the bottom of your camera on where exactly it is – Imre Dec 07 '11 at 22:29
  • @imre I responded in Chat – Vian Esterhuizen Dec 07 '11 at 22:35
  • 1
    Little bit of background reading: http://en.wikipedia.org/wiki/Rangefinder_camera –  Dec 08 '11 at 08:21

2 Answers2

3

It is possible to estimate the distance to the subject using the auto focus. But to do this you need a camera model of your whole camera system, body and lens. You would most likely have to model this yourself, which will take quite some time and effort. The accuracy would likely be very different for different systems. Your model would probably contribute to the (in)accuracy more than anything else. With a very good model it would be the auto focus that dictated the accuracy.

It sounds like you might benefit from looking at the Kinect system from Microsoft, and all the software available for this on line. The hardware is cheap and it is fairly good.

Håkon K. Olafsen
  • 3,196
  • 1
  • 22
  • 41
1

There is an EXIF field named "Subject Distance." If you use a camera that populates that field (and can be controlled by your controller software), you could just use the EXIF data from the picture.

I just looked at two images from my old Canon SX10IS that have values in that field, and the picture where the subject was closer had a smaller number: so based on a sample size of two, that feature seems to be available and work. However, I looked at a larger set of photos, taken with the same camera but by someone else, and I can't see any correlation between the Subject Distance value and apparent focus distance.

I imagine you'd need a full camera, not just an image sensor, though. Also, I don't know how to find a list of cameras that populate that field.

  • Thank you for your response. Do you have any idea how the camera is able to populate this field? How do they measure the distance and how precise do they measure the distance? – Lucas Dec 07 '11 at 19:44