-
Notifications
You must be signed in to change notification settings - Fork 0
/
face.py
executable file
·63 lines (47 loc) · 1.75 KB
/
face.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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
# import cv2
# import sys
# import os
# import pickle
# def check_img():
# face_cascade = cv2.CascadeClassifier(
# 'cascades/data/haarcascade_frontalface_alt2.xml')
# recognizer = cv2.face.LBPHFaceRecognizer_create()
# recognizer.read("Trainer.yml")
# labels = {"person_name": 1}
# with open('labels.pickle', "rb") as f:
# og_labels = pickle.load(f)
# labels = {v: k for k, v in og_labels.items()}
# video_capture = cv2.VideoCapture(0)
# while True:
# # Capture Frame by Frame
# returnValue, frame = video_capture.read()
# # Convert RGB to GrayScale
# gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
# # Detect Faces from haarcascade
# faces = face_cascade.detectMultiScale(
# gray,
# scaleFactor=1.4,
# minNeighbors=5,
# minSize=(30, 30)
# )
# # Draw Rectangle around faces
# for (x, y, w, h) in faces:
# cv2.rectangle(frame, (x, y), (x+w, y+h), (150, 150, 0), 4)
# # Region of Intreset
# roi_gray = gray[y:y+h, x:x+w]
# # Try to Recognize the face
# id_, conf = recognizer.predict(roi_gray)
# print(id_, conf)
# if conf >= 25 and conf <= 100:
# font = cv2.FONT_HERSHEY_SIMPLEX
# name = labels.get(id_)
# color = (255, 255, 255)
# stroke = 2
# cv2.putText(frame, name, (x, y), font, 2, color, stroke, cv2.LINE_AA)
# cv2.imshow('Video', frame)
# if cv2.waitKey(1) & 0xFF == ord('q'):
# break
# # When everything is done, release the capture
# video_capture.release()
# cv2.destroyAllWindows()
# check_img()