-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfaceRecognition.py
35 lines (23 loc) · 984 Bytes
/
faceRecognition.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
import cv2
import sys
#!pip install opencv-python-headless
haarCascadeFrontal = cv2.CascadeClassifier("haarcascade_frontalface_default.xml")
haarCascadeEye = cv2.CascadeClassifier("haarcascade_eye_tree_eyeglasses.xml")
#videoCapture = cv2.VideoCapture(0)
videoCapture = cv2.VideoCapture("contoh.mp4")
while 1:
_, frame = videoCapture.read()
gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
faces = haarCascadeFrontal.detectMultiScale(gray, 1.3, 4)
for (x, y, w, h) in faces:
cv2.rectangle(frame, (x, y), (x + w, y + h), (0, 255, 0), 2)
face_gray = gray[y:y+h, x:x+w]
face_ori = frame[y:y+h, x:x+w]
eyes = haarCascadeEye.detectMultiScale(face_gray, 1.3, 6)
for (ex,ey,ew,eh) in eyes:
cv2.rectangle(face_ori, (ex,ey), (ex + ew,ey + eh), (255, 0, 0), 2)
cv2.imshow("Simple Face Rec", frame)
if cv2.waitKey(1) & 0xFF == ord('q'):
break
videoCapture.release()
cv2.destroyAllWindows()