-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
43 lines (31 loc) · 1.17 KB
/
main.py
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
import cv2
import sys
# needed input-files via cli as arguments
filePath = sys.argv[0]
cascPath = sys.argv[1]
# create a stream and cascade file for the process
stream = cv2.VideoCapture(filePath)
faceCascade = cv2.CascadeClassifier(cascPath)
# read stream input and convert each frame into a processable file with the given color space
while stream.isOpened():
ret, frame = stream.read()
gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
faces = faceCascade.detectMultiScale\
(
gray,
scaleFactor = 1.2,
minNeighbors = 5,
minSize = (30, 20),
flags = cv2.CASCADE_SCALE_IMAGE
)
# draw a rectangle around the faces
for (x, y, w, h) in faces:
cv2.rectangle(frame, (x, y), (x + w, y + h), (0, 255, 0), 2)
# show the current frame with a reactangle around the existing faces
cv2.imshow('Frame', frame)
# simple break / close statement
if cv2.waitKey(1) & 0xFF == ord('q'):
break
# release() and destroyAllWindows() are needed, otherwise it can result in performance issues on low-spec systems
stream.release()
cv2.destroyAllWindows()