-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdetector.py
42 lines (37 loc) · 1.21 KB
/
detector.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
import numpy as np
import cv2
import sqlite3
face_cascade = cv2.CascadeClassifier('cascades/data/haarcascade_frontalface_default.xml')
cap = cv2.VideoCapture(0)
rec = cv2.face.LBPHFaceRecognizer_create()
rec.read('recognizer/trainningData.yml')
id=0
font=cv2.FONT_HERSHEY_SIMPLEX
def getProfile(id):
conn=sqlite3.connect("facebase.db")
cmd="SELECT * FROM People WHERE Id="+str(id)
cursor=conn.execute(cmd)
profile=None
for row in cursor:
profile=row
conn.close()
return profile
while(True):
ret, img= cap.read()
gray = cv2.cvtColor(img,cv2.COLOR_BGR2GRAY)
faces = face_cascade.detectMultiScale(gray, scaleFactor=1.3, minNeighbors=5)
for (x,y,w,h) in faces:
color = (0,255,0)
stroke = 2
end_cord_x = x+w
end_cord_y = y+h
cv2.rectangle(img, (x,y), (end_cord_x,end_cord_y), color, stroke)
id,conf=rec.predict(gray[y:y+h,x:x+w])
profile=getProfile(id)
if(profile!=None):
cv2.putText(img,str(profile[1]),(x,y+h+30),font, .75, (0, 0, 255))
cv2.imshow('Face',img)
if cv2.waitKey(1) & 0xFF == ord('q'):
break
cap.release()
cv2.destroyAllWindows()