Tuesday, March 19, 2024

Crowd Detection Camera To Prevent COVID-19

Ashwini Kumar Sinha

- Advertisement -

ashwiniIn this time when COVID-19 is spreading rapidly, it is essential to maintain social distance and avoid large public gatherings at one place to break the chain of corona infection.But maintaining this is not easy. Many people, knowingly or unknowingly, gather and roam on the streets. Keeping an eye on all these activities is not an easy job. The authorities need reliable technology that can survey such places to prevent any unnecessary movement. Our COVID-19 Crowd Detection Camera can help in isolating the poeple 

So, today we have decided to make a Smart COVID-19 Crowd Detection Camera that will keep a watchful eye on all illegal activities and detect any crowd/person/vehicle on the road. The device also can alert the authorities regarding unnecessary gatherings. 

However, this camera is not just limited to this. It can be used to:

- Advertisement -
  • Detect high traffic on roads.
  • Identify any unauthorised human entry in a restricted area.
  • Observe the number of people in a hall/auditorium.
  • Maintain and monitor the flow of the crowd in a protest demonstration.

How it works?

We are going to use an RPi with a camera for capturing live video. The video is then processed frame-by-frame.

By using image processing with the help of TensorFlow, people and vehicles in the video are identified. When that happens, the device gives an alert by speaking and/or by triggering the lights/bulb.

 Bill Of Materials

Let’s start our project by collecting the following components.

Bill for Crowd Detection Camera

Prerequisites

Assuming that you already have the RPi ready with Raspbian Image and Python environment setup, we can install the required libraries and modules. 

Firstly, install the following libraries in Python.

  • Espeak
  • Numpy
  • Scipy
  • Opencv
  • Dlib
  • Keras
  • TensorFlow/TensorFlow Lite 

To install the above libraries, open the LX terminal and then type the following commands: 

sudo  apt-get update

sudo apt-get upgrade

sudo nano /etc/dphys-swapfile

Then change the line CONF_SWAPSIZE=100 to  CONF_SWAPSIZE=1024

sudo /etc/init.d/dphys-swapfile stop  

sudo /etc/init.d/dphys-swapfile start

sudo pip3 install opencv

sudo pip3 install numpy

wget https://bootstrap.pypa.io/get-pip.py

pip3 install dlib

pip3 install tensorflow

After the installation you can now proceed with the cloning of TF modules and examples and files using the following command: 

git clone https://github.com/tensorflow/tensorflow.git  

After successfully cloning, go to the directory →  research folder → create a new Python file and paste the code attached with the article. 

Coding 

In the first part of the code, we have to initialize the required library. Then we will have the code that uses the camera module to take live video and then process it frame-by-frame to detect the desired objects such as:

  • Bike
  • Bicycle
  • People
  • Bus
  • Car 

Now using the if() condition, we will check whether any desired objects have been detected. If nothing is detected, then no action will be taken. But if detected, the code will trigger the speaker to give an alert. You can also attach a bulb/buzzer to pin 17 to get the alert notification.

Using Opencv
Fig 1.
Path for Crowd Detection models
Fig 2.
Tensorflow model processing
Fig 3
Counting people fro crowd detection
Fig 4.

Connection 

Now connect the camera to the RPi4 board using a ribbon cable and power the Raspberry Pi using an adaptor. To get a live video output from the camera, you can either use an RCA Cable with RCA Input of TV or use HDMI cable with TV. 

You can also use a VNC. Just connect RPi and PC/Laptop with your network/hotspot and then mirror its screen  using VNC. Now, connect a speaker to the audio port of RPI and power it. If you want any alert using bulb/buzzer, then connect the buzzer to GPIO pin 17 of Raspberry Pi.

Csmera for crowd detection
Fig 5.

Testing

Camera attached to raspberry pi
Fig 6.

 

Dtecting drowd and people
Fig 7. Detecting the people on Road

After making all the connections and setup, now let’s test our project. Open the folder and then run the code. Wait for a few seconds to let the Python initialize all the modules. Then run the code. After a few seconds, a new window opens up and shows the results of the cam. The detected people are shown in the window and an alert is given about their presence on the road.

Download Source Code

61 COMMENTS

    • The project does not require a circuit diagram or block diagram.It works on following way:-
      RPI camera takes video—> video is sliced into frames—–>frame is resized For processing—>Tensor flow process the frames and detect people

  1. Hello, i would like to seek clarification for this part ,”After successfully cloning, go to the directory → research folder → create a new Python file and paste the code attached with the article. ” I am not sure what should i do in my Pi desktop now. Please advise thank you!

      • Traceback (most recent call last):
        File “/home/pi/tensorflow/tensorflow/python/det.py”, line 29, in
        from utils import label_map_util
        ImportError: cannot import name ‘label_map_util’ from ‘utils’ (/usr/local/lib/python3.7/dist-packages/utils/__init__.py)

        i faced these type of error. I installed every library related utils, but it getting these type of error

SHARE YOUR THOUGHTS & COMMENTS

Electronics News

Truly Innovative Tech

MOst Popular Videos

Electronics Components

Calculators