-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdetect.py
More file actions
46 lines (35 loc) · 1.21 KB
/
detect.py
File metadata and controls
46 lines (35 loc) · 1.21 KB
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
39
40
41
42
43
44
45
46
import numpy as np
import cv2
#Load the template and initialize the webcam
#HOG Algorithm
hog = cv2.HOGDescriptor()
hog.setSVMDetector( cv2.HOGDescriptor_getDefaultPeopleDetector() )
cap = cv2.VideoCapture(0)
# variables
c_punt=[244,0,0]
n_peatons=0
while(True):
x1=0;
y1=0;
#We read a frame and keep it.
ret,img1 = cap.read()
#turn the image
img = cv2.flip(img1,1)
#We convert the image to black and white
gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
#We look for the coordinates if there is one and we keep their position
found,x=hog.detectMultiScale(gray, winStride=(8,8), padding=(32,32), scale=1.09)
#A rectangle is drawn in the coordinates of each person
for (x,y,w,h) in found:
cv2.rectangle(img,(x,y),(x+w,y+h),(125,255,0),2)
#Number of pedestrians
size = len(found);
cv2.putText(img,str(size), (350,40), cv2.FONT_HERSHEY_TRIPLEX, 1,(0,0,255),2)
cv2.putText(img,str('Detect Person :'), (50,40), cv2.FONT_HERSHEY_TRIPLEX, 1,(0,0,255),2)
#Name of the window
cv2.imshow('Kamera',img)
#With the 'x' key we exit the program
if cv2.waitKey(1) & 0xFF == ord('x'):
break
cap.release()
cv2.destroyAllWindows()