-
Notifications
You must be signed in to change notification settings - Fork 0
/
video.py
38 lines (31 loc) · 1.21 KB
/
video.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
import cv2
import os
import numpy as np
import face_detect as fr
face_recognizer=cv2.face.LBPHFaceRecognizer_create()
face_recognizer.read("\\Users\\Purvika pandey\\AppData\\Local\\Programs\\Python\\Python37-32\\cs_project\\training_image.yml")
name={0:"deepika",1:"purvika"}
cap=cv2.VideoCapture(0)
while True:
ret,test_img=cap.read()
faces_detected,gray_img=fr.facedetection(test_img)
#for (x,y,w,h) in faces_detected:
# cv2.rectangle(test_img,(x,y),(x+w,y+h),(255,0,0),thickness=5)
#resized_img = cv2.resize(test_img,(800,500))
#cv2.imshow("face video detected",resized_img)
#cv2.waitKey(10)
for face in faces_detected:
(x,y,w,h)=face
roi_gray=gray_img[y:y+h,x:x+h]
label,confidence=face_recognizer.predict(roi_gray)
print("confidence:",confidence)
print("label:",label)
fr.draw_rect(test_img,face)
predicted_name=name[label]
if(confidence>37):
fr.put_text(test_img,predicted_name,x,y)
resized_img = cv2.resize(test_img,(800,500))
cv2.imshow("face recognition ",resized_img)
if cv2.waitKey(10) ==ord('q'):break
cap.release()
cv2.destroyAllWindows