Few months ago, Covid-19 happened one again in Vietnam and it’s more dangerous than ever. It has affected a lot of people, families, and companies. With Social distancing and wearing a face mask, we can slow the spreading speed of coronavirus.
By Katapult Magazin, CC BY-SA 4.0, https://commons.wikimedia.org/w/index.php?curid=88464207
I used 2 separate data sets to train 2 separate custom yolov4 model. One model (Yolov4-tiny) is to detect if there is any person in the image captured from camera, and calculate the distance between 2 or more people in the image, then check if the distance is lower than 2 meter or not, the other model (yolov4) is to detect if a person is wearing a mask or not.
Yolov4 has high accuracy and fast, to perform real-time detection compare to others models.
This dataset has total 1034 images, I used 80% of the data for training, 20% for validation.
Final result (mAP): 88,38%
You can download weights for face mask detection here: https://drive.google.com/file/d/1rVnBIqvlinL2BUONjOaFDj8PM9Yw4k1q/view?usp=sharing
This dataset has total 902 images, I used 80% of the data for training, 20% for validation.
Final result (mAP): 98,33%
Each camera have a unique focal length. I calculated mine by stand front the camera, measure distance between me and the camera (d), take my real height (R = 172cm), and calculated height of bounding box of me (from result when detected by yolov4-tiny) in pixel.
Calculate focal length f = (r x d) / R
With f, we can calculate distance between objects and the camera:
We already calculate distance d between each person to camera and with position giving by yolov4 when detect a person (middle point of the bounding box), we can calculate Euclidean distance by using this formula:
streamlit run app.py
Real-time detect using camera:
python main.py --confidence 0.5
Run with video:
python main.py --confidence 0.5 --video <path_to_video>
Use email and sms to alert (need to change phone number (using Twilio), account and password of your email in sendMSG.py)
python main.py --confidence 0.5 --use_sms 1 --use_email 1
https://www.pyimagesearch.com/2020/06/01/opencv-social-distancing-detector/
https://github.com/Subikshaa/Social-Distance-Detection-using-OpenCV