Finding Social Distance using YOLO and OpenCV

Considering the unfortunate circumstances due to COVID-19, keeping distance among people is crucial. And to find the distance, we can set the goal to detect people using Deep Learning first and then find the distance between them to check whether a norm of social distance of about 6 feet or 1.8m is maintained by people.

Tools and Libraries

  • Python

Steps

  • Step 1: Find the number of people in the frame/Image.

The blog isn’t about YOLO or any Object Tracking architecture for deep learning, will share details of blogs which explains why YOLO is better that other RCNN architectures.

Pixel per Metric

Pixel Density is the measure of pixels per inch(ppi) or pixel per centimeter of an electronic device. It is defined as number of pixels found per inch. Consider the smartphone Oneplus 5t, which has around 402 ppi. It means the number of pixels in an inch is 401 and thats why we get an clear resolution of an image. Greater the density, greater is the quality.

Consider the image of Peaky Blinders, we can see that each character is set apart from each other in some distance. If we think about the pixels of the image, then each of the character occupies some number of pixels on the image and each person has width associated with them. For instance, in the image above the women standing at the left occupies first 200 pixels in x-axis with width of her body as 30 inch then we can make use of this ratio 200/30 to get Pixel per inch.

We can then utilize this ratio value to find distance between the bounding boxes of other people in the frame to measure where each person is located. The task can be extended to a video and also for real time applications.

Result

👏 if you liked it !

Source Code

YOLO vs RCNNs

Machine Learning Engineer | Avid Reader | Movie Buff | https://mayurji.github.io/