-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscan.py
39 lines (30 loc) · 1.11 KB
/
scan.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
import cv2 as cv, time, os
from training import personFolders as pf
camera = 0
video = cv.VideoCapture(camera, cv.CAP_DSHOW)
haarCascade = cv.CascadeClassifier('haarcascade_frontalface_default.xml')
recognizer = cv.face.LBPHFaceRecognizer.create()
recognizer.read('training.xml')
# Check if video capture is successful
if not video.isOpened():
print("Error: Could not open video capture.")
exit()
while True:
ret, frame = video.read()
greyscale = cv.cvtColor(frame, cv.COLOR_BGR2GRAY)
face = haarCascade.detectMultiScale(greyscale, scaleFactor=1.3, minNeighbors=5)
for (x, y, w, h) in face:
cv.rectangle(frame, (x,y), (x+w, y+h), (0,255,0), 2)
##
id, conf = recognizer.predict(greyscale[y:y+h, x:x+w])
##
#if conf <= 5:
cv.putText(frame, pf[id-1], (x+10, y-10), cv.FONT_HERSHEY_DUPLEX, 1, (0,255,0))
#else:
# cv.putText(frame, 'unknown', (x+10, y-10), cv.FONT_HERSHEY_DUPLEX, 1, (0,255,0))
cv.imshow("Face Recognition", frame)
key = cv.waitKey(1)
if key == ord('q'):
break
video.release()
cv.destroyAllWindows()