최성환

Delete README.md

1 -# Social-Distancing-in-Real-Time
2 -Social distancing in Real-Time using live video stream/IP camera in OpenCV.
3 -
4 -> This is an improvement/modification to (https://www.pyimagesearch.com/2020/06/01/opencv-social-distancing-detector/).
5 -
6 -> Please refer to the added [Features](#features).
7 -
8 -Output | Output
9 -:-------------------------:|:-------------------------:
10 -![Output](mylib/videos/output.gif?raw=true "Output") | ![Output](mylib/videos/output1.gif?raw=true "Output")
11 -
12 -- Use case: counting the number of people in the stores/buildings/shopping malls etc., in real-time.
13 -- Sending an alert to the staff if the people are way over the social distancing limits.
14 -- Optimizing the real-time stream for better performance (with threading).
15 -- Acts as a measure to tackle COVID-19.
16 -
17 ----
18 -
19 -## Table of Contents
20 -* [Simple Theory](#simple-theory)
21 -* [Running Inference](#running-inference)
22 -* [Features](#features)
23 -* [References](#references)
24 -
25 -## Simple Theory
26 -**Object detection:**
27 -- We will be using YOLOv3, trained on COCO dataset for object detection.
28 -- In general, single-stage detectors like YOLO tend to be less accurate than two-stage detectors (R-CNN) but are significantly faster.
29 -- YOLO treats object detection as a regression problem, taking a given input image and simultaneously learning bounding box coordinates and corresponding class label probabilities.
30 -- It is used to return the person prediction probability, bounding box coordinates for the detection, and the centroid of the person.
31 -
32 ----
33 -**Distance calculation:**
34 -- 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.
35 -- Euclidean distance is then computed between all pairs of the returned centroids. Simply, a centroid is the center of a bounding box.
36 -- Based on these pairwise distances, we check to see if any two people are less than/close to 'N' pixels apart.
37 -
38 -## Running Inference
39 -- Install all the required Python dependencies:
40 -```
41 -pip install -r requirements.txt
42 -```
43 -- If you would like to use GPU, set ```USE_GPU = True``` in the config. options at 'mylib/config.py'.
44 -
45 -- Note that you need to build OpenCV with CUDA (for an NVIDIA GPU) support first:
46 -
47 -> Click [**here**](https://jamesbowley.co.uk/accelerate-opencv-4-2-0-build-with-cuda-and-python-bindings/) for build instructions on Windows.
48 -
49 -> This tutorial also might help. Click [**here**](https://www.youtube.com/watch?v=TT3_dlPL4vo&list=WL&index=108&t=0s).
50 -
51 -- Download the weights file from [**here**](https://drive.google.com/file/d/1O2zmGIIHLX8SGs24W7mjRyFKvE_CSY8n/view?usp=sharing) and place it in the 'yolo' folder.
52 -
53 -- To run inference on a test video file, head into the directory/use the command:
54 -```
55 -python run.py -i mylib/videos/test.mp4
56 -```
57 -- To run inference on an IP camera, Setup your camera url in 'mylib/config.py':
58 -
59 -```
60 -# Enter the ip camera url (e.g., url = 'http://191.138.0.100:8040/video')
61 -url = ''
62 -```
63 -- Then run with the command:
64 -
65 -```
66 -python run.py
67 -```
68 -> Set url = 0 for webcam.
69 -
70 -## Features
71 -The following are examples of the added features. Note: You can easily on/off them in the config. options (mylib/config.py):
72 -
73 -***1. Real-Time alert:***
74 -- 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.
75 -- You can set the max. violations limit in config (```Threshold = 15```).
76 -- This is pretty useful considering the COVID-19 scenario.
77 -
78 -> Note: To setup the sender email, please refer the instructions inside 'mylib/mailer.py'. Setup receiver email in the config.
79 -
80 -***2. Threading:***
81 -- Multi-Threading is implemented in 'mylib/thread.py'. If you ever see a lag/delay in your real-time stream, consider using it.
82 -- 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.
83 -- 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.
84 -- It is most suitable for solid performance on complex real-time applications. To use threading:
85 -
86 -set ```Thread = True``` in the config.
87 -
88 -***3. People counter:***
89 -- If enabled, we simply count the total number of people: set ```People_Counter = True``` in the config.
90 -
91 -***4. Desired violations limits:***
92 -- 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).
93 -- 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).
94 -- Anything above 80 px is considered as a safe distance and thus, 'no' violation (green).
95 -
96 -## References
97 -***Main:***
98 -- YOLOv3 paper: https://arxiv.org/pdf/1804.02767.pdf
99 -- YOLO original paper: https://arxiv.org/abs/1506.02640
100 -- YOLO TensorFlow implementation (darkflow): https://github.com/thtrieu/darkflow
101 -
102 -***Optional:***
103 -- More theory: https://www.pyimagesearch.com/2018/11/12/yolo-object-detection-with-opencv/
104 -- Other trained model weights from official doc: https://pjreddie.com/darknet/yolo/
105 -
106 ----
107 -
108 -## Thanks for the read & have fun!
109 -
110 -> To get started/contribute quickly (optional) ...
111 -
112 -- **Option 1**
113 - - 🍴 Fork this repo and pull request!
114 -
115 -- **Option 2**
116 - - 👯 Clone this repo:
117 - ```
118 - $ git clone https://github.com/saimj7/Social-Distancing-Detection-in-Real-Time.git
119 - ```
120 -
121 -- **Roll it!**
122 -
123 ----
124 -
125 -saimj7/ 02-11-2020 © <a href="http://saimj7.github.io" target="_blank">Sai_Mj</a>.