-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdetector.py
73 lines (61 loc) · 2.74 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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
# -*- coding: utf-8 -*-
"""
Created on Mon Aug 6 22:52:18 2018
@author: sidgo
"""
import cv2
import sqlite3
from datetime import datetime
rec=cv2.face.LBPHFaceRecognizer_create();
rec.read("recognizer/TrainingData.yml")
cascadePath = "Classifiers/haarcascade_frontalface_default.xml"
faceCascade = cv2.CascadeClassifier(cascadePath)
path='dataSet'
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
cap = cv2.VideoCapture(0)
font = cv2.FONT_HERSHEY_SIMPLEX
while(True):
if datetime.now().time().hour == 23 and datetime.now().time().minute < 25 and datetime.now().time().minute > 20:
ret, img = cap.read()
gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
faces=faceCascade.detectMultiScale(gray,1.3,5);
for (x,y,w,h) in faces:
nbr_predicted,conf=rec.predict(gray[y:y+h,x:x+w])
cv2.rectangle(img,(x,y),(x+w,y+h),(255,0,0),2)
profile=getProfile(nbr_predicted)
if (profile!=None):
cv2.putText(img, "Name: "+str(profile[1]),(x, y + h+ 30),font, 0.4, (0, 0, 255), 1)
cv2.putText(img, "Age: "+str(profile[2]),(x, y + h + 50),font, 0.4, (0, 0, 255), 1)
cv2.putText(img, "Gender: "+str(profile[3]),(x, y + h + 70),font, 0.4, (0, 0, 255), 1)
cv2.putText(img, "Criminal Records: "+str(profile[4]),(x, y + h + 90),font, 0.4, (0, 0, 255), 1)
conn = sqlite3.connect('FaceBase.db')
c = conn.cursor()
time_entry = str(datetime.now().strftime('%Y-%m-%d %I:%M:%S%p'))
tname = 'Entries_for_'+str(datetime.now().date().strftime('%d%m%Y'))
values = (time_entry, 'Present', str(nbr_predicted),)
c.execute('UPDATE '+tname+' SET Time=?,Status=? WHERE ID=?',values)
conn.commit()
c.close()
conn.close()
else:
cv2.putText(img, "Name: Unknown", (x, y + h + 30), font, 0.4, (0, 0, 255), 1);
cv2.putText(img, "Age: Unknown", (x, y + h + 50), font, 0.4, (0, 0, 255), 1);
cv2.putText(img, "Gender: Unknown", (x, y + h + 70), font, 0.4, (0, 0, 255), 1);
cv2.putText(img, "Criminal Records: Unknown", (x, y + h + 90), font, 0.4, (0, 0, 255), 1);
cv2.imshow("img",img);
if(cv2.waitKey(10) & 0xFF == ord('q')):
break;
else:
if(cv2.waitKey(10) & 0xFF == ord('q')):
break;
continue
cap.release()
cv2.destroyAllWindows()