The distance between the camera and the recognized “subject”

I would like to calculate the distance between my camera and a recognized “subject”. The recognized “object” is a black rectangular sticker on a white board, for example. I know the values ​​of the rectangle (x, y).

Is there a method that I can use to calculate the distance with the values ​​of the source rectangle and the image value of the rectangle that I took with the camera?

I searched the forum for answers, but none of them were listed for calculating the distance with these attributes.

I am working on a robot called Nao from Aldebaran Robotics, I plan to use OpenCV to recognize a black rectangle.

+4
source share
3 answers

If you could calculate the angle occupied by the image of the target, then the distance to the target should be proportional to cot (i.e. 1/tan ) of this angle. You should find that the number of pixels in the image corresponds approximately to the corners, but I doubt that it is completely linear, especially close.

The behavior of your camera lens is likely to affect this measurement, so it will depend on your exact setting.

Why not measure the size of the target at several distances and build a scatter plot? Then you can pick up a curve for the data to get the function size-> distance for your specific system. If your camera is close to a “perfect” camera, you should find that this graph looks like cot , and you should find your a and b values ​​to match dist = a * cot (b * width) .

If you try this experiment, why not post the answers here so that others can take advantage?

[Edit: note on “ideal” cameras]

In order for the camera image to look “realistic” for us, the image must approximate the projection onto the plane located in front of the eye (since we view the camera images while holding the flat image in front of our eyes). Imagine that you are holding a sheet of a business card in front of your eye and draw silhouettes of objects on this paper. The second diagram on this page shows what I mean. You can describe a camera that provides this as an ideal camera.

Of course, in real life, cameras do not work through tracing papers, but with lenses. Very sophisticated lenses. Look at the lens diagram on this page . For various reasons that you could spend studying throughout your life, it’s very difficult to create a lens that works just like an example of tracing paper will work under any conditions. Start with this wiki page and read if you want to know more.

Thus, you are unlikely to be able to calculate the exact relationship between the pixel length and the distance: you have to measure it and set the curve.

+2
source

This is a big topic. If you want to move from one image, look at this old article by A. Kriminisi. For an in-depth review, read his Ph.D. thesis. Thesis. Then start playing with the OpenCV routines in the projective geometry section.

+1
source

I also worked on Image / Object Recognition. I just released a python-oriented Android app (ported to android) that recognizes objects, people, cars, books, logos, trees, flowers ... something :) It also shows that this is a thought process, since he "thinks" :) I put it as a test for 99 cents on a Google game. Here's a link, if you're interested, there is also a video about this: https://play.google.com/store/apps/details?id=com.davecote.androideyes

Enjoy it! :)

-2
source

All Articles