Pedestrian Detection Using Open CV

Vidushraj Chandrasekaran
3 min readOct 4, 2019
https://www.tu-auto.com/ntsb-calls-for-standards-on-automated-pedestrian-detection/

Image-processing

For this, we should have a haar cascade_fullbody.xml file and the video footage which is taken from a CCTV camera.

Initially, we will be importing the various packages which are required, so we require computer vision, we require numerical python also we require time

We used cv2.CascadeClassifier is a built-in function and we give the path of the file, the.XML file. When you open the particular file you can see the features of the entire human body, so different people from different regions this XML file is generated it is available on the internet, so you can use this particular file.

Initially, we will initialize the video capturing object, so in our case, we are using cv2.VideoCapture and then the path of the video which located on our computer so it will be loaded in the variable called CCTV_Video.

After that, we will be checking if this particular video has successfully opened, so we have got a while condition capture.isOpened(). So if this particular video is opened, so this particular function capture.isOpened() will give the output as true, so while true it will enter the while loop.

we give a delay in seconds than 0.05 seconds this is optional you can increase it or you can execute it without delay as well.

so now we start capturing the frames, we have got the CCTV_Video.read()

We are using cv2.resize is a built-in function used to resize and this particular built-in function you have to give the variable which has the captured video and then the size and then we know the size that is in x dimension and y scale. that is x-scale as well as y scale and the interpolation.

I have discussed more image processing operations in my last blog you can check it out for more clarification.

After that, I am converting this RGB to gray so by now you know, there is a built-in function cv2.COLOR_BGR2GRAY, why BGR because bytes are saved in reverse order, then we are converting from one color space to another, so again we have a built-in function cv2.cvtColor, so we have got here cv2.cvtColor in the bracket frame then we are converting RGB to GRAY using the built-in function cv2.COLOR_BGR2GRAY so it will in a variable called as gray, so now again we want to detect pedestrians which are captured in the CCTV footage, again we have a built-in function detect that is cv2.CascadeClassifer.detectMultiScale it has three parameters (gray, scaleFactor, minNeighbors).

scaleFactor=Specifies the image size to be reduced.

minNeighbors=Specifies the number of neighbors each rectangle should have to retain it.

Here is the link for my Github you can find the code.

I will update pedestrian detection using Mask RCNN and Yolo object detection methods in my future posts.

--

--

Vidushraj Chandrasekaran

Graduated in Electrical & Telecommunication Engineering | Data Engineering | Machine Learning | Deep Learning Enthusiast