A computer vision based object detection command line application that helps to monitor and detect social distancing in public places.
During the pandemic, there were guidelines passed by local government bodies that were to be followed on a personal basis in order to reduce the rise in COVID-19 cases, one of them was following social distancing in public places. Following social distancing is a difficult task for us, as it is something new to us and we have to be constantly monitored so that we follow this rule and reduce the risk of contracting the virus. If there were people appointed to monitor social distancing from the field, this job becomes not only tedious but also would put the respective person at risk of contracting the virus. In order to overcome this problem, we can automate this task and SafetyEye comes right into action. SafetyEye is a command-line application that detects and monitors social distancing using a state-of-the-art object detection model that is tuned to recognize human beings. When CCTV footage of a public place is fed to the application, it outputs a video with a graphical representation of people following social distancing or not. This helps in a way that a person can sit inside a cabin remotely and take a look into the situation for any further action.
- Python3
- Opencv
- cv2's DNN Library
Automation of social distance detection and monitoring.
To install the required prerequisite modules, just run
pip install -r requirements.txt
Next, download the weights of yolov3 network from here and copy-paste the file into this cloned directory
After downloading the weights, go to file app.py and line 17 and change the path of the weights file.
net = cv2.dnn.readNet("<path of weights file>", "yolov3.cfg")
After all the required files and modules are downloaded. Run the command
python3 app.py --path (path of the test video in double quotes)
For example, python3 app.py --path "home/videos/testvideo.avi"
- Then a pop-up with the first frame of the test video appears.
- Here, you have to select first four dots that will appear in red on the frame such that they form a rectangle.
- Order of plotting points is important, and the order is, top-left, top-right, bottom-left and bottom-right
- Later, you have to select two dots that appear in blue along a straight line (preferable), to find out the minimum distance to be maintained by the people in the video. And then press enter.
All these steps are demonstrated below in Example section
Here is a demo on how to run the application,
This is the output of the application after running it on the sample video that is already in this repository.
Here, people bounded by green boxes are maintaining social distancing according to the threshold distance given by the user and the ones bounded by red boxes are not.
P.S: The complete output video is in file out.avi
This application has an inbuilt camera caliberation function, using which we can set the minimum distance between people in the video to classify them whether they are socially distanced or not. This application also has a perspective tranformation of the people so that the distance between people will be independent of the orientation of camera.
Instead of the user entering the minimum distance required to be maintained, the future goal of this application is to automate this process and smartly find out the minimum distance using an algorithm, which would inturn reduce the effort of user entering the points to calculate the distance.