0

I have developed an application that detects faces with Google Vision API(offline) and then sends the image of the detection to Microsoft Azure to obtain the information of this face (age,gender...). In my case I also need to calculate (approximate at least) the distance between the camera and the face detected, I didn't see this option in the Microsoft Azure Documentation so I suppose that's not implemented. What should I implement to calculate the distance between camera and face ? Can I achieve this objective with OpenCV or another OpenSource library ?

I've seen this answer here in SO (How to measure height, width and distance of object using camera?) but in my case I don't have the altitude of the device so I don't think I can implement this solution (1st answer - drulabs's answer).

Gerard E
  • 27
  • 9
  • The image you are getting from the camera is 2D so it only has x-axis and y-axis, but it does not have z-axis, so unable to calculate the distance of the object from the camera. – Bahramdun Adil Jun 06 '19 at 17:49
  • So there's no option to calculate the distance ? can I do it with the "streaming" instead ? – Gerard E Jun 07 '19 at 07:24
  • Yes, there is no option by just using image processing to calculate the distance. But I don't know what do you mean by "streaming"? – Bahramdun Adil Jun 07 '19 at 14:42
  • I mean the live video, as i I am doing face detection I have the image(bitmap) but also I have access to the video or the frames that the camera is detecting, I have seen some APIs as QUIVIDI that gets the distance with the detection. – Gerard E Jun 11 '19 at 07:37

1 Answers1

0

The question dates from over a year ago, but recently I was looking for an answer to this question too, and I found a simple solution that works for me.

In this article the authors describe a method for calculating an estimate for the distance between a camera and a person, based on the distance (in pixels) between the person’s eyes.

The only thing I used from this article is a graph on page 31 that suggests (but does not mention) an inverse relation between the eye distance (dE) and the camera distance (dC):

dC = some_constant / dE

I use this simple formula for estimating the distance. Instead of the eye distance, I use the estimate for the width of the face that is returned by my face recognition software. You can safely do this because the article on page 35 states that the ‘relation between eye distance and face dimension is linear, regardless of [the] height of a person’.

After some experimenting I found a value for some_constant that for me worked well enough to be useful. Deviations from the real distance were in the order of 15% for distances up to 5 meters (I did not test beyond that). The precision obviously also depends on the precision of the face dimensions (width) reported by the face recognition software.

John Pool
  • 46
  • 5