-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathproject1b.py
32 lines (27 loc) · 1.14 KB
/
project1b.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
import cv2 as cv
import numpy as np
face_detect=cv.CascadeClassifier(cv.data.haarcascades+"haarcascade_frontalface_default.xml")
manager_name=['lampard','hansi flick','jurgen klopp','mourinho','pep guardiola']
#Load trained model
face_recognizer=cv.face.LBPHFaceRecognizer_create()
face_recognizer.read('face_trained.yml')
#Load trained features and labels
features=np.load('features.npy',allow_pickle=True)
labels=np.load('labels.npy')
video=cv.VideoCapture('managerdetection.mp4')
while True:
isTrue,frame=video.read()
gray=cv.cvtColor(frame,cv.COLOR_BGR2GRAY)
face=face_detect.detectMultiScale(gray,1.3,1)
for (x,y,w,h) in face:
#Remember the size of face_roi is (height,width)
face_roi=gray[y:y+h,x:x+w,]
label,confidence = face_recognizer.predict(face_roi)
cv.putText(frame, str(manager_name[label]), (50,50), cv.FONT_HERSHEY_COMPLEX, 1.0, (0,255,0), thickness=2)
cv.rectangle(frame, (x,y), (x+w,y+h), (0,255,0), thickness=2)
cv.imshow('Test',frame)
if cv.waitKey(20) & 0xFF==ord(' '):
break
video.release()
video.destroyAllWindows()
cv.waitKey(0)