-
Notifications
You must be signed in to change notification settings - Fork 91
/
Copy pathPedestrian Detection in recorded videos
38 lines (32 loc) · 1.32 KB
/
Pedestrian Detection in recorded videos
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# -*- coding: utf-8 -*-
"""
Created on Sat Dec 28 11:47:27 2019
@author: vchan
"""
# OpenCV Python program to detect pedestrians in video frame
# import libraries of python OpenCV
import cv2
# capture frames from a video
cap = cv2.VideoCapture( r'C:\Users\vchan\OneDrive\Desktop\Untitled Folder\pedestrian and walk 360.mp4',0)
# Trained XML classifiers describes some features of some object we want to detect
pedestrian_cascade = cv2.CascadeClassifier(r'C:\Users\vchan\OneDrive\Desktop\Untitled Folder\haarcascade_fullbody.xml')
# loop runs if capturing has been initialized.
while True:
# reads frames from a video
ret, frames = cap.read()
# convert to gray scale of each frames
#gray = cv2.cvtColor(frames, cv2.COLOR_BGR2GRAY)
# Detects pedestrians of different sizes in the input image
pedestrians = pedestrian_cascade.detectMultiScale( frames, 1.1, 1)
# To draw a rectangle in each pedestrians
for (x,y,w,h) in pedestrians:
cv2.rectangle(frames,(x,y),(x+w,y+h),(0,255,0),2)
font = cv2.FONT_HERSHEY_DUPLEX
cv2.putText(frames, 'Person', (x + 6, y - 6), font, 0.5, (0, 255, 0), 1)
# Display frames in a window
cv2.imshow('Pedestrian detection', frames)
# Wait for Enter key to stop
if cv2.waitKey(33) == 13:
break
cap.release()
cv2.destroyAllWindows()