Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Finding distance from camera to object of known size

I am trying to write a program using opencv to calculate the distance from a webcam to a one inch white sphere. I feel like this should be pretty easy, but for whatever reason I'm drawing a blank. Thanks for the help ahead of time.

like image 828
David Harbage Avatar asked Jul 15 '11 23:07

David Harbage


People also ask

How do you find the distance from a camera to an object?

The formula: distance = size_obj * focal_length / size_obj_on_sensor. The whole method depends on figuring out the size of the object as it appears on the sensor given the focal length and the measured object size. Otherwise you have two unknowns.

Can you calculate distance using camera?

Google's augmented reality app “Measure” turns ARCore-compatible Android smartphones into digital measuring tapes, as reported by Ars Technica. Using the app appears to be rather simple. Simply launch Measure, point the phone's camera to an object, then pick two points to measure the distance in between.

How do you find the distance of an object from its size?

The relationship between object size and distance is an inverse linear relationship, i.e. size is 1 / distance. This makes sense when you think about it as if you double the distance the size halves.

How do you find the distance of an object from the camera on Opencv?

Steps for Distance Estimation: Capture Reference Image: Measure the distance from the object(face) to the camera, capture a Reference image and note down the measured distance. Measure the object (face) width, make sure that measurement units are kept for reference image and object(face) width. Mine Reference Image.


1 Answers

You can use triangle similarity to calibrate the camera angle and find the distance.
You know your ball's size: D units (e.g. cm). Place it at a known distance Z, say 1 meter = 100cm, in front of the camera and measure its apparent width in pixels. Call this width d.
The focal length of the camera f (which is slightly different from camera to camera) is then f=d*Z/D.

When you see this ball again with this camera, and its apparent width is d' pixels, then by triangle similarity, you know that f/d'=Z'/D and thus: Z'=D*f/d' where Z' is the ball's current distance from the camera.

like image 191
Adi Shavit Avatar answered Oct 06 '22 05:10

Adi Shavit