Ask Your Question
0

Calculate Distance to Object in Android knowing the Size, Focal Length

asked 2015-01-27 06:53:21 -0600

ricardo.nascimento gravatar image

I'm trying to find the distance to an object with my Android.

I know the real size of object, also done some camera calibration with OpenCV to calculate focal length, camera matrix and distortion parameters as well. To easy up the question, it's assumed that the orientation is 0 degrees (can compute the angle of the android device when detecting the object)

My previous method was using some sort of manual calibration: - Calculated the area in pixels at several known distances and saved both values (area and distance). Every time I see the object i compute a regression based on the area measured. But this method is obviously inaccurate.

So based in the parameters I know that I mentioned above, what do you recommend as best method?

edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted
0

answered 2015-01-27 09:25:49 -0600

BillyBag2 gravatar image

Not sure of the relationship between the parameters you have and the field of view. However if you can get this I think an approximate calculation of distance would be easier.

Angle of arc = (field of view) * (object pixel width)/(screen pixel width).

Then tan(arc/2) = (true width/2)/(true distance).

So (true distance) = width/2.tan(arc/2). (very approximate.)

May contain mistakes, lots of simple assumptions made, low tech answer.

(PS lots of info in the exif data from a still from the camera. Something may be useful. I think its an augmented reality trick to get your app to take a sample picture and read this info to get approximate camera geometry.)

edit flag offensive delete link more

Comments

I think the bit I missed was the relationship between field of view and focal length. This looks quite easy too. See http://paulbourke.net/miscellaneous/l....

The difficult question is do you have the effective focal length or the actual focal length? Probably the effective focal length. I which case the width is 35mm. If its the true focal length (which I don't think you have enough information to know) use the sensor size from the EXIF data.

So you fov is probably, 2 x aTan( 0.5 x 35mm / (effective focal length in mm))

BillyBag2 gravatar imageBillyBag2 ( 2015-01-27 09:38:00 -0600 )edit

Question Tools

1 follower

Stats

Asked: 2015-01-27 06:53:21 -0600

Seen: 2,988 times

Last updated: Jan 27 '15