-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path1.face.py
More file actions
34 lines (24 loc) · 911 Bytes
/
1.face.py
File metadata and controls
34 lines (24 loc) · 911 Bytes
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
import cv2
# Choosing the "frontal_face" for detecting a face in webcam
face_cacades = cv2.CascadeClassifier(
"Phase_7\HAAR_CASCADES\haarcascade_frontalface_default.xml"
)
cap = cv2.VideoCapture(0)
while True:
ret, frame = cap.read()
gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
# Detecting face using pre trained model
faces = face_cacades.detectMultiScale(gray, 1.1, 5)
"""
.detectMultiScale -> scan & detect objects (here - face)
1.1 -> scalefactor ( how much zoom level to try out for detecting face)
zoom in by 10% smaller
5 -> minNeighbour count
"""
for x, y, w, h in faces:
cv2.rectangle(frame, (x, y), (x + w, y + h), (0, 255, 0), 2)
cv2.imshow("Webcam Face", frame)
if cv2.waitKey(1) & 0xFF == ord("q"):
break
cap.release()
cv2.destroyAllWindows()