Search code examples
androidcameraandroid-camerapixel

How to measure distance using camera pixels?


How can I know a distance between phone and an object which appears in the camera? Is there a way to measure it by using pixels of a camera between them? And if yes, then approximately what accuracy will I have?


Solution

  • Are you taking about a camera inside the phone? If so, there is no number of pixels between the phone and the object. In "laboratory conditions" you could measure the size of the known object in the image and use some empirical values to interpolate the distance between phone and object. Maybe openCV for Android helps to get acceptable results outside laboratory conditions.

    I think there is a solution to your problem: Focus the object and use the focus-distance. The results for objects in the distance will be useless, results for nearer objects should be acceptable.