-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathFace_identification.py
35 lines (27 loc) · 1012 Bytes
/
Face_identification.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
import cv2
import numpy as np
class face_detection:
def __init__(self) -> None:
pass
def draw_rectangle(self,image):
faces = self.face_cascade.detectMultiScale(image, scaleFactor=1.1, minNeighbors=5)
for i, (x, y, w, h) in enumerate(faces):
cv2.rectangle(image, (x, y), (x + w, y + h), (0, 255, 0), 4)
return image
def face_detect(self):
self.face_cascade = cv2.CascadeClassifier(cv2.data.haarcascades + "haarcascade_frontalface_default.xml")
cap = cv2.VideoCapture(0)
cap.set(10,100)
if not cap.isOpened():
print("Cannot open camera")
exit()
while True:
ret, frame = cap.read()
detected = self.draw_rectangle(frame)
cv2.imshow('Wen cam', detected)
if cv2.waitKey(20) & 0xFF == ord('q'):
break
cap.release()
cv2.destroyAllWindows()
L = face_detection()
L.face_detect()