In this python project, we are going to build the Human Detection and Counting System through Webcam or you can give your own video or images. This is an intermediate level deep learning project on computer vision, which will help you to master the concepts and make you an expert in the field of Data Science. Let’s build an exciting project.

human detection project output

Human Detection with Computer Vision

Project Prerequisites

The project in Python requires you to have basic knowledge of python programming and the OpenCV library. We will be needing following libraries:

  • OpenCV: A strong library used for machine learning
  • Imutils: To Image Processing
  • Numpy: Used for Scientific Computing. Image is stored in a numpy array.
  • Argparse: Used to give input in command line.

To install the required library, run the following code in your terminal.

Download Project Code

Before proceeding ahead, please download the source of real-time human detection project: Human Detection & Counting Project

Histogram of Oriented Gradient Descriptor

HOG is a feature descriptor used in computer vision and image processing for the purpose of object detection. This is one of the most popular techniques for object detection, to our fortune, OpenCV has already been implemented in an efficient way to combine the HOG Descriptor algorithm with Support Vector Machine or SVM.

Steps To Build Human Detection Project

1. Import the libraries:

2. Create a model which will detect Humans:

As discussed earlier, We will use HOGDescriptor with SVM already implemented in OpenCV. Below code will do this work:
cv2.HOGDescriptor_getDefaultPeopleDetector() calls the pre-trained model for Human detection of OpenCV and then we will feed our support vector machine with it.

3. Detect() method:

Here, the actual magic will happen.

Video: A video combines a sequence of images to form a moving picture. We call these images as Frame. So in general we will detect the person in the frame. And show it one after another that it looks like a video.

That is exactly what our Detect() method will do. It will take a frame to detect a person in it. Make a box around a person and show the frame…and return the frame with person bounded by a green box.

Everything will be done by detectMultiScale(). It returns 2-tuple.

  1. List containing Coordinates of bounding Box of person.
  2. Coordinates are in form X, Y, W, H.
  3. Where x,y are starting coordinates of box and w, h are width and height of box respectively.
  4. Confidence Value that it is a person.

Now, We have our detect method. Let’s Create a Detector.

4. HumanDetector() method

There are two ways of getting Video.

  1. Web Camera
  2. Path of file stored

In this deep learning project, we can take images also. So our method will check if a path is given then search for the video or image in the given path and operate. Otherwise, it will open the webCam.

cv2.VideoCapture(0) passing 0 in this function means we want to record from a webcam. video.read() read frame by frame. It returns a check which is True if this was able to read a frame otherwise False.

Now, For each Frame, we will call detect() method. Then we write the frame in our output file.

#python tutorials #deep learning

Python Project - Real-time Human Detection & Counting - DataFlair
40.30 GEEK