Git Product home page Git Product logo

social-distancing-detection-in-real-time's Introduction

Social-Distancing-in-Real-Time

Social distancing in Real-Time using live video stream/IP camera in OpenCV.

This is an improvement/modification to (https://www.pyimagesearch.com/2020/06/01/opencv-social-distancing-detector/).

Please refer to the added Features.

Output Output
Output Output
  • Use case: counting the number of people in the stores/buildings/shopping malls etc., in real-time.
  • Sending an alert to the staff if the people are way over the social distancing limits.
  • Optimizing the real-time stream for better performance (with threading).
  • Acts as a measure to tackle COVID-19.

Table of Contents

Simple Theory

Object detection:

  • We will be using YOLOv3, trained on COCO dataset for object detection.
  • In general, single-stage detectors like YOLO tend to be less accurate than two-stage detectors (R-CNN) but are significantly faster.
  • YOLO treats object detection as a regression problem, taking a given input image and simultaneously learning bounding box coordinates and corresponding class label probabilities.
  • It is used to return the person prediction probability, bounding box coordinates for the detection, and the centroid of the person.

Distance calculation:

  • NMS (Non-maxima suppression) is also used to reduce overlapping bounding boxes to only a single bounding box, thus representing the true detection of the object. Having overlapping boxes is not exactly practical and ideal, especially if we need to count the number of objects in an image.
  • Euclidean distance is then computed between all pairs of the returned centroids. Simply, a centroid is the center of a bounding box.
  • Based on these pairwise distances, we check to see if any two people are less than/close to 'N' pixels apart.

Running Inference

  • Install all the required Python dependencies:
pip install -r requirements.txt
  • If you would like to use GPU, set USE_GPU = True in the config. options at 'mylib/config.py'.

  • Note that you need to build OpenCV with CUDA (for an NVIDIA GPU) support first:

Click here for build instructions on Windows.

This tutorial also might help. Click here.

  • To run inference on a test video file, head into the directory/use the command:
python run.py -i mylib/videos/test.mp4
  • To run inference on an IP camera, Setup your camera url in 'mylib/config.py':
# Enter the ip camera url (e.g., url = 'http://191.138.0.100:8040/video')
url = ''
  • Then run with the command:
python run.py

Set url = 0 for webcam.

Features

The following are examples of the added features. Note: You can easily on/off them in the config. options (mylib/config.py):

1. Real-Time alert:

  • If selected, we send an email alert in real-time. Use case: If the total number of violations (say 10 or 30) exceeded in a store/building, we simply alert the staff.
  • You can set the max. violations limit in config (Threshold = 15).
  • This is pretty useful considering the COVID-19 scenario.

Note: To setup the sender email, please refer the instructions inside 'mylib/mailer.py'. Setup receiver email in the config.

2. Threading:

  • Multi-Threading is implemented in 'mylib/thread.py'. If you ever see a lag/delay in your real-time stream, consider using it.
  • Threading removes OpenCV's internal buffer (which basically stores the new frames yet to be processed until your system processes the old frames) and thus reduces the lag/increases fps.
  • If your system is not capable of simultaneously processing and outputting the result, you might see a delay in the stream. This is where threading comes into action.
  • It is most suitable for solid performance on complex real-time applications. To use threading:

set Thread = True in the config.

3. People counter:

  • If enabled, we simply count the total number of people: set People_Counter = True in the config.

4. Desired violations limits:

  • You can also set your desired minimum and maximum violations limits. For example, MAX_DISTANCE = 80 implies the maximum distance 2 people can be closer together is 80 pixels. If they fell under 80, we treat it as an 'abnormal' violation (yellow).
  • Similarly MIN_DISTANCE = 50 implies the minimum distance between 2 people. If they fell under 50 px (which is closer than 80), we treat it as a more 'serious' violation (red).
  • Anything above 80 px is considered as a safe distance and thus, 'no' violation (green).

References

Main:

Optional:


Thanks for the read & have fun!

To get started/contribute quickly (optional) ...

  • Option 1

    • ๐Ÿด Fork this repo and pull request!
  • Option 2

    • ๐Ÿ‘ฏ Clone this repo:
    $ git clone https://github.com/saimj7/Social-Distancing-Detection-in-Real-Time.git
    
  • Roll it!


saimj7/ 02-11-2020 ยฉ Sai_Mj.

social-distancing-detection-in-real-time's People

Contributors

saimj7 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

social-distancing-detection-in-real-time's Issues

System Requirements

Hello My Friend , sorry for Disturbing you but my question is i use i3 with Ubuntu but every frame lagging by 3 sec interval so its not looks pretty any system requirement to handle this script ?? And Also having a question like how can i use this in CCTV grid like 4 cameras together.

(-215:Assertion failed) !_filename.empty()

[INFO] Looking for GPU
[INFO] Starting the live stream..
[ERROR:0] global C:\projects\opencv-python\opencv\modules\videoio\src\cap.cpp (116) cv::VideoCapture::open VIDEOIO(CV_IMAGES): raised OpenCV exception:

OpenCV(4.2.0) C:\projects\opencv-python\opencv\modules\videoio\src\cap_images.cpp:293: error: (-215:Assertion failed) !_filename.empty() in function 'cv::CvCapture_Images::open'

Time threshold for the violation detection

Currently, i had tried to modify the algorithm so that have the feature for the time threshold to recoginse the violation as red color rectangle box after 4seconds.

The concept is like this, once the algorithm detect the 2 people are very close to each other, it will show a white color box as the buffer zone of the time threshold for around 4 second. After 4 second, if that 2 person are still close to each other, the box will turn into red color. i had tried many solution for this modification but i still unable to achieve that feature.

Question

Hello, i am having a little problem understanding how we know that the distance between two detected persons is 1.5 or 2 meters? How do we determine/proximate the distance in meters from the euclidean distance between two objects?

Thanks

[Errno 2] No such file or directory: 'yolo\\coco.names'

File "c:/Users/trapt/Downloads/Social-Distancing-Detection-in-Real-Time-main/Social-Distancing-Detection-in-Real-Time-main/Run.py", line 27, in
LABELS = open(labelsPath).read().strip().split("\n")
FileNotFoundError: [Errno 2] No such file or directory: 'yolo\coco.names'

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.