COVID-19: Social Distancing Detector

栏目: IT技术 · 发布时间: 5年前

内容简介:Build a simple Social Distancing Detector to monitor the practice of social distancing in a crowdSocial Distancing is one such terminology that has gained popularity over the past few months, thanks toSocial Distancing is possibly the only way to contain t

Build a simple Social Distancing Detector to monitor the practice of social distancing in a crowd

Social Distancing is one such terminology that has gained popularity over the past few months, thanks to COVID-19 . People are forced to maintain a sufficient amount of distance between each other to prevent the spread of this deadly virus. Amidst this crisis, I decided to build a simple Social Distancing Detector that could monitor the practice of social distancing in a huge crowd.

COVID-19: Social Distancing Detector

Photo by Jacek Dylag on Unsplash

Overview-

Social Distancing is possibly the only way to contain the spread of COVID-19 . Recently, Andrew Ng’s Landing AI team created a Social Distancing Tool using the concepts of Computer Vision. This project is inspired by their work.

In this Social Distancing Detector, I’ll be using the weights of the YOLO v3 Object Detection Algorithm and the COCO dataset which are easily available online. Additionally, the main library being used will be the OpenCV along with the Deep Neural Network ( dnn ) module.

There are very few library requirements to build this Social Distancing Detector. So, if you are into Deep Learning, you would already have installed these libraries.

import numpy as np
import cv2
import imutils
import os
import time

We need to define three user-defined functions for this detector program, which will be explained below.

Step 1: Check function

This function is used to calculate the distance between two different points ( a and b ) in an image (single frame of a video). The two points denote the center of the individuals detected in the video. The distance that is calculated is the Euclidean Distance between two points.

Then, calibration is used to find the midpoint between the two points and the ‘ if ’ statement returns a ‘ True ’ if the distance lies in between the range, else returns ‘ False ’.

Step 2: Setup function

This function has one input argument ‘ yolo ’, which is a string that contains an empty directory into which the ‘ weights ’, ‘ cfg ’ and ‘ labels ’. will be stored.

The os.path.sep.join() function is used to join one or more path components intelligently. In simple terms, it stores the “ yolov3.weights ”, “ yolov3.cfg ” and “ coco.names ” files into the “ yolo ” directory.

The variable ‘ net ’ is used to read a network model stored in Darknet model files.

The ‘ ln ’ function is used to get all the layers of the network model such as ‘relu_89’, ‘conv_89’, ‘bn_89’, ‘relu_90’, ‘conv_90’ and then store only the indexes of layers with unconnected outputs. [‘yolo_82’, ‘yolo_94’, ‘yolo_106’] .

Step 3: Image Process function

This is the most complex function in our program. In this function, The argument is a single frame of the video. For every iteration, each frame of the input video gets processed along with the social distancing detection between each individual in a crowd and is returned to the main function.

The code for this function is available in my GitHub repository (link is available below) and can be used for reference.

Step 4: Input parameters

In this, we initialize the input video file as ‘ filename ’ and the output file to be stored in the .mp4 format as ‘ opname

create = None
frameno = 0
filename = "videos/video_1.mp4"
yolo = "yolo-coco/"
opname = "output_videos/output_of_" + filename.split('/')[1][:-4] + '.mp4'

Step 5: Main function

We now come to the final part of the code. In this, the input video is separated into many single frames on which the functions defined above will be performed.

Once that is done, each output frame is received and combined together to create the output video.

The .time() function is used to calculate the time taken to perform the whole operation. Longer the video, longer will be the time taken to process the video. In my example, a 3-second video took approximately 150-seconds to get processed to an output video along with the social distancing detection. So, do the Math!

Demo Video-

I am running this code on an example that was obtained from TRIDE (University of Oxford).

COVID-19: Social Distancing Detector

Input Video (Source — TRIDE )

COVID-19: Social Distancing Detector

Output Video (Source — TRIDE )

By comparing both the videos, we can see that the Social Distancing Detector is able to detect if the crowd is following social distancing and marks the people who are not in safe distances with a red box and the safe people with a green box .

This program can be altered with various threshold values to check for social distancing. For those who are interested, just by tweaking the code a little, you can set the source of the video as the webcam of your PC . I’ll leave that for you to try it out by yourself.

Conclusion-

This program is a very simple and basic implementation of the Social Distancing Detector. This code can serve as a basis for more complex programs which can be developed from this.

For those who are looking for the code, I am also attaching a link to my github repository where you can find the code of this program for your reference. Go ahead, fork this repository and bring in more developments to this simple piece of code!

In this article, we have successfully built a simple Social Distancing Detector using Deep Learning. This has several applications such as the CCTV cameras which can be equipped with this software tool to monitor the practice of social distancing in a huge crowd or in an office environment.

Also, do check out my other article where I have described the program to build a simple CNN model to detect if an individual is wearing a face mask or not.

Social Distancing in the Post-COVID era is one such practice that will be followed for many days to come by. Let us all be safe and stay healthy.Till then, Happy Machine Learning!


以上所述就是小编给大家介绍的《COVID-19: Social Distancing Detector》,希望对大家有所帮助,如果大家有任何疑问请给我留言,小编会及时回复大家的。在此也非常感谢大家对 码农网 的支持!

查看所有标签

猜你喜欢:

本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们

第三次浪潮

第三次浪潮

[美]阿尔文·托夫勒 / 黄明坚 / 中信出版集团 / 2018-7 / 79.00元

《第三次浪潮》是美国著名未来学家阿尔文•托夫勒的代表作之一。1980年出版之际,随即引起全球热评,堪称中国改革开放的指南。本书阐述了由科学技术发展引起的社会各方面的变化与趋势。托夫勒认为,人类迄今为止已经经历了两次浪潮文明的洗礼:第一次是农业革命,人类就此从原始渔猎时代进入以农业为基础的文明社会,并历经千年,直到工业革命的到来。随后,人类社会历时300年摧毁了落后的第一次浪潮文明,并在“二战”后1......一起来看看 《第三次浪潮》 这本书的介绍吧!

MD5 加密
MD5 加密

MD5 加密工具

SHA 加密
SHA 加密

SHA 加密工具

HEX CMYK 转换工具
HEX CMYK 转换工具

HEX CMYK 互转工具