How do I calculate the distance from an real-life object to the device?

I was wondering how do you make a functionality similar to the People Detection feature in the Magnifier app, but I couldn’t find any documentation for finding out the distance from a device to a real-world object or person.
  • Can anybody help?

How do I calculate the distance from an real-life object to the device?
 
 
Q