Sign inGet started
← Back to all data apps

Social distancing detector

By Filip Žitný

Updated on August 14, 2024

Use template ->

The COVID-19 pandemic introduced a need for innovative solutions to ensure public safety, particularly in maintaining social distancing. One such solution is the development of a social distancing detector, a project that combines deep learning with computer vision technologies. This high-level overview explores a project that utilizes TensorFlow, Python, and OpenCV to create a robust social distancing detector.

The social distancing detector project leverages pre-trained object detection models available in the TensorFlow Model Zoo. These models, trained on the COCO (Common Objects in Context) dataset, are capable of identifying a variety of objects, including people, within an image or video frame. The selected model for this project, faster_rcnn_inception_v2_coco, was chosen for its balance between accuracy and processing speed, making it suitable for detecting individuals in a non-real-time setting.

Key components and methodology

People detection: the project begins with loading the pre-trained TensorFlow model into a computational graph. For each frame of the video input, the model processes the image to detect objects, filtering specifically for people. This filtering is crucial to exclude irrelevant objects and focus solely on identifying persons in the scene.

Bird's eye view transformation: to accurately measure the distance between individuals, the project employs a bird's eye view transformation using OpenCV. This transformation converts the perspective view of a scene into a top-down view, allowing for more precise spatial measurements. The process involves selecting key points in the image and applying a transformation matrix to adjust the image's perspective.

Distance measurement: with the transformed image, the project computes the "GPS" coordinates for each detected person. Using these coordinates, it calculates the distance between every pair of individuals in the scene. If the distance between any two people falls below a predefined threshold (e.g., 2 feet), the system flags this as a social distancing violation, marking the individuals in red.

The results of this project demonstrate the feasibility of using deep learning and computer vision for monitoring social distancing. The project utilized video footage from the PETS2009 dataset, successfully detecting and flagging instances where social distancing was not maintained.

However, the project is not without its limitations. It is primarily a proof of concept and not intended for real-world deployment due to privacy and ethical concerns. Potential improvements include using faster models for real-time detection, enhancing the system's robustness against occlusions, and implementing automatic calibration to improve accuracy across different scenes.

This social distancing detector is an excellent example of how advanced technologies like TensorFlow and OpenCV can be harnessed to address public health challenges. While the project serves as a conceptual framework, it opens the door for further developments in creating effective, ethical, and scalable solutions for monitoring and enforcing social distancing in various environments.

Filip Žitný

Data Scientist

Follow Filip on Twitter, LinkedIn and GitHub

That’s it, time to try Deepnote

Get started – it’s free
Book a demo

Footer

Solutions

  • Notebook
  • Data apps
  • Machine learning
  • Data teams

Product

Company

Comparisons

Resources

  • Privacy
  • Terms

© Deepnote