Reputation: 13
I want to know the distance of person form camera . i am using android motorola tablet.
i am using camera api of android - API Level 14.
i am using following formula:
objectDistnance = ((objectheight(pixel) * focal-length(mm)) / imageheight(pixel);
imageHeight is height of my preview screen;
focal length i am getting from Camera api : 4.42 mm;
object height i am giving as input of person's height in mm : 1620mm
and i want to calculate the distance of person from camera.
by using this formula i am getting wrong distance it is giving me 60mm but actually it is more then 2500mm
so please anyone help me with this am i using correct formula ?
what should i do to get the correct distance of person from camera
Upvotes: 1
Views: 2655
Reputation: 1661
From here I got the following formula:
distance to object (mm) = focal length (mm) * real height of the object (mm) * image height (pixels)
---------------------------------------------------------------------------
object height (pixels) * sensor height (mm)
So it seems you did not include enough reference variables.
Lets asume the following:
Focal Length: 4,42mm
Real Height of object: 1620mm
Image Height: 2048px
Object Height: 1024px
Sensor height: 24mm
4.42mm * 1620mm * 2048px
-----------------------
1024px * 24mm
The Result of this would be 1193 mm
Since I don't know all of your variables I could not recalculate your situation.
edit I just checked this formula using my Samsung Galaxy S with the following values:
3.79mm focal length
100mm real object height
2592px image height
1200px object height on image
4.54mm sensor height
I took a picture from about 200 - 250 mm away (I did not measure the exact distance). The result of this calculation is ~200mm which would fit to this test.
Upvotes: 2