2
$\begingroup$

What is the best approach to find the distance of a person/people from camera, using an image?

$\endgroup$
  • $\begingroup$ Welcome to DS StackExchange. Please make your question more elaborate. Explain for example what sources you found up to now, what did you try, if you have data avilable, etc. As of now it's too general. $\endgroup$ – Leevo May 6 at 12:10
2
$\begingroup$

Updated: Measuring distance from camera to object

Perhaps you could search and find tons of materials. This is a well-established task, for example this tutorial, of more advanced methods combining object detection with distance measurements, see Object-Detection-and-Distance-Measurement, and references at the bottom. In a nutshell, when you know details about your camera focal length and the details about the object in the image, it is a simple formula to estimate the distance base on those details. I am guessing that you may need to do some calibration, but I haven't done this one myself, so I wouldn't know for sure.


Earlier I have had: Measuring distance between objects

One idea that might be worth exploring is to segment your image, for example use the recent package by Facebook Detectron2, that seems to be capable of segmenting people out-of-the-box. Once segmented (filtered only for humans), for each segmentation calculate the center of segment (Centroid) or something similar assigned to each person. And given that would be (x,y) coordinate, you can easily calculate distance from a person to all neighboring people.

For the center of segment , OpenCV is quite handy. See this post Find the Center of a Blob (Centroid)! Or this great tutorial to estimate distance between objects in an image with OpenCV!

In a nutshell: Image Segmentation -> Centroid -> Distance

| improve this answer | |
$\endgroup$
  • $\begingroup$ Thanks for the answer. But looks like this gives the distance between people, but I'm looking for finding the distance from a person to camera. Any thought on that $\endgroup$ – Karthik Sunil May 5 at 8:36
  • $\begingroup$ Oh I misunderstood you then. That is even more straightforward then. Have you searched online? I will update the answer momentarily. $\endgroup$ – TwinPenguins May 5 at 8:40
  • $\begingroup$ I searched, what is needed for distance calculation are * Actual dimension of the object, like width or height. (We might not have it) * Focal length of the camera. (Which we can assume that we will know) $\endgroup$ – Karthik Sunil May 5 at 9:40
  • 1
    $\begingroup$ I see your point. But it doesn't mean you cannot do nothing. Take one person of an average size person (honestly the aspect ratio of people doesn't change that much) at fixed position and calibrate the distance. It seems like a viable option in practice like distance of cars from another car (again cars in various size and shapes). Unless I am missing something. $\endgroup$ – TwinPenguins May 5 at 9:59
  • $\begingroup$ Makes sense. We also thought to train the faces to predict the actual width of the face :-) $\endgroup$ – Karthik Sunil May 5 at 10:16

Not the answer you're looking for? Browse other questions tagged or ask your own question.