Calculate the distance to object from camera

Jay K Daftary

The ratio of the size of the object (imageHeight) in picture and the height of the object in real life is the same as the ratio between the focal length and distance of object and camera.

so the simple formula for getting Distance of object from camera is

distance(mm) = (focal length (mm) * real height of the object (mm) * camera frame height in device (pixels) ) / ( image height (pixels) * sensor height (mm))

where Sensorheight for perticular device can be obtain from
for phone and tablet camera it is 3.42mm

Lets asume the following:

Focal Length: 4.42mm
Real Height of object: 1620mm
Camera frame Height: 696px
Image Height: 228px
Sensor height: 3.42mm

distance = (4.42mm * 1620mm * 696px) / (228px * 3.42mm)

so distance is 6391mm.

This test is performed with Samsung Galaxy S3 and as a result actual distance and calculated distance of object are same.

about the author

Jay K Daftary

  1. Minecraftaccountgenera

    March 19, 2013

    Attractive section of content. I just stumbled upon your web site and in accession capital to assert that I acquire in fact enjoyed account your blog posts. Any way I’ll be subscribing to your feeds and even I achievement you access consistently rapidly. Minecraft account generator

  2. HowtotakeExcellentCare

    March 22, 2013

    I had been wondering if your hosting is OK? Not that I’m complaining, but slow loading instances times will very frequently affect your placement in google and could damage your high quality score if ads and marketing with Adwords. How to take Excellent Care of your Wedding Bands and Engagement Rings

  3. Riyas Kokkur

    June 25, 2013

    I am really interested on this topic.Can you give what exactly means the terms of Sensor Height, Focal Length, Camera frame height.I have Some basics about this ,.I just wish to clarify my doubts.

  4. Muhamed Riyas

    June 25, 2013

    I am really interested in this topic.Can you give what exactly means the terms of Sensor Height,Focal Length,Camera frame height.I have Some basics about this ,.I just wish to clarify my doubts

  5. Jay

    June 25, 2013

    Camera Frame height – the frame in which image is rendering

    Sensor height – basically sensor dimensions width and height – can find from this

    Focal length – distance between center of lens and focal point. the below url is contain image which will explain you everything.

    in image
    F – Focal Point
    f- focal length

    Wikipedia link for Focal length

  6. minecraft server port

    July 5, 2013

    Thank you for yet another beneficial blog. Exactly where more might just I am getting in which style of information designed in this sort of fantastic strategy? I’ve a enterprise that we’re only right now operating upon, and that i have been on the look out and about intended for like information and facts.

  7. details about commercial real estate from Regency Executive Offices

    July 12, 2013

    Thanks for spending the time to share, I really feel strongly about it and love studying more on this. Please keep updating your page with additional details.


    July 13, 2013

    I am very happy that I stumbled across your website in my search for info relating to this.

  9. Lilia Yournet

    August 15, 2013

    Alege elegant si simplu, alege online! Rochii Online iti aduce cele mai noi colectii de rochii din Marea Britanie. Indiferent daca esti in cautare de: Rochii de Ocazie, Rochii Club, Rochii de Vara 2012 sau Rochii Office Rochii Online este locul potrivit. Preturi mici si calitate maxima, numai pe Reduceri la doar un click distanta. Alege eficient si elegant!

  10. Chiradeep

    August 30, 2013

    Can u give the source code of your sample? I need it badly


    November 11, 2013

    Heya i’m for the primary time here. I came across this
    board and I to find It really helpful & it helped me out much.
    I am hoping to provide something again and help others like you aided me.

  12. vickas sharma

    April 11, 2014

    can you please give the code to find out the distance of an object from camera?

    i will be very thankful.
    if you can send me the code on my mail-

    thank you.

  13. Sachin Babu

    July 14, 2014

    Could u please send me the same code to this mail id

  14. Adarsh Mn

    November 10, 2014

    can u please send me the code to my mail

  15. Attu

    April 4, 2017

    Thanks for the informative article. Do you have any code to share ? Just for quick reference i need it.

  16. Meriem Memmiche

    July 27, 2017

    Hello, Thank you for this article but I didn’t undrestand what do you mean by camera frame height in device. Can you explain more please?