-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmainRec.py
More file actions
40 lines (30 loc) · 903 Bytes
/
mainRec.py
File metadata and controls
40 lines (30 loc) · 903 Bytes
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
import cv2
import numpy as np
import os
import json
recognizer = cv2.face.createLBPHFaceRecognizer()
recognizer.load('training/training.yml')
detector= cv2.CascadeClassifier('/home/geekysethi/opencv-3.2.0/data/haarcascades/haarcascade_frontalface_default.xml')
with open('data.txt') as json_file:
data = json.load(json_file)
cam =cv2.VideoCapture(0)
font = cv2.FONT_HERSHEY_SIMPLEX
while(True):
ret,img = cam.read()
gray=cv2.cvtColor(img,cv2.COLOR_BGR2GRAY)
faces = detector.detectMultiScale(gray,1.2,5)
for x,y,w,h in faces:
cv2.rectangle(img,(x,y),(x+w,y+h),(0,255,0),2)
Id,conf=recognizer.predict(gray[y:y+h,x:x+w])
if(conf<50):
text=data[str(Id)]
else:
text="Unknown"
print("ID",Id)
print("Conf",conf)
cv2.putText(img,text,(x,y+h), font,1,(255,0,0))
cv2.imshow('image',img)
if cv2.waitKey(10) & 0xFF==ord('q'):
break
cam.release()
cv2.destroyAllWindows()