Calculating distance to an object with camera

Oliver Bosse

Member
Licensed User
Longtime User
Hi all,

does anybody know a concept/algorithm how to get or calculate the distance
to an object using the camera?

i want to point to an object with the camera and then show the distance to it in the display.

let me give you an example that hopefully explains the difficulty ;-) :
i am standing on a boat and see another boat passing.
now i want to know the distance to it without driving there to get its gps-coordinates.

since i only have my own gps-coordinates with the gps-library i need a way
to calculate the ones from the other boat.

oliver
 

Erel

B4X founder
Staff member
Licensed User
Longtime User
I'm sure that there are better solutions, but here are my 2 cents:
- First you need to do some calibration by taking a picture of an item with a known height and in a known distance.
- Later you can take a photo of the boat, show the image to the user and let him mark the boat vertical axis. Now you should assume that the actual height of a boat is some known value (you could actually have several models for smaller and larger boats). Using all these values it should be pretty simple to calculate the distance.

You should find the metric that is most similar in boats (maybe the height above the sea?).
 
Upvote 0

robotop

Member
Licensed User
Longtime User
Hello, you can take two pictures of subject from two points at same distance from target, but at different angle (i.e. a couple of meters left). Then you can use the two pictures sliding one of that and measuring how many pixels shift is needed for collimate images. Then you can use trigononometric formula for angle and distance from target, knowing the distance from the two pictures was taken.
This is the principle of Galileian's focus in some old cameras.
(obviously, you must calculate a K factor from pixels to horizontal distance)
If I said something stupid, please don't shot me...
 
Upvote 0

Oliver Bosse

Member
Licensed User
Longtime User
hi guys,

thanks a lot for your ideas!
i am still smiling about the creativity you have!
and how different solutions can be from different developers :sign0098:

i knew there would be some math involved but hoped that the device itself could serve at least a few more information.

i've put all your ideas together plus i found this following method
http://developer.android.com/reference/android/hardware/Camera.Parameters.html#getFocusDistances(float[])

i couldn' get it to work yet because it seems a little tricky and only possible via intent but i will let you know as soon as i did

of course any help is still very much appreciated ;)

oliver
 
Upvote 0

Oliver Bosse

Member
Licensed User
Longtime User
well, it is like LineCutter said....using the camera autofocus is pointless.
at a certain distance the value always stays the same.
some camera models don't even have autofocus.
so it seems like it's always INFINITY.

i'll keep on trying something else ;)
 
Upvote 0

LineCutter

Active Member
Licensed User
Longtime User
Your only real hope is some known (or estimated) sized object on the target, that you can use trigonometry on. The camera then gives the pixel size.

How about putting lines of different sizes on the camera view & providing a (scrolling) zoom that resizes them. Provide an option of horizontal/vertical.
Let the lines be indicative of known sizes (say 30cm, 1m, 2m & 10m) & then once you know the zoom factor (camera & line length) you can do the trigonometry to work out the estimated distance.
See the thumb distance estimation link for more detail.
 
Upvote 0

ZJP

Active Member
Licensed User
Longtime User
HI,

The ​​Erel idea is simple to implement. By the way, how to make a "overlay picture" with the camera library ?

JP

EDIT found!!!
 
Last edited:
Upvote 0
Top