-
Notifications
You must be signed in to change notification settings - Fork 2
/
StartDetection.py
112 lines (67 loc) · 2.67 KB
/
StartDetection.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
import DbOperations
import cv2
import threading
import FaceRecognition
import urllib.request
import numpy as np
import tkinter as tk
import time
def main(cameraIp, userName, password, cameraType):
try:
global isRunning,RecognitionObj,runTimeArray
password_mgr = urllib.request.HTTPPasswordMgrWithDefaultRealm()
url = cameraIp
password_mgr.add_password(None, url, userName, password)
handler = urllib.request.HTTPBasicAuthHandler(password_mgr)
opener = urllib.request.build_opener(handler)
while isRunning:
info = opener.open(url).read()
imgNp=np.array(bytearray(info),dtype=np.uint8)
frame=cv2.imdecode(imgNp,-1)
frame_gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
PredictedUsers = RecognitionObj.PredictUsers(frame_gray)
for Label,Accuracy,x,y,w,h in PredictedUsers:
print(Label,Accuracy)
if(Accuracy<thresholdAccuracy):
if(Label not in runTimeArray):
if(cameraType=="In"):
db.insertInTime(Label)
else:
db.insertOutTime(Label)
runTimeArray.append(Label)
cv2.destroyAllWindows()
except Exception as e:
print(e)
def trainNewUsers():
def subThread():
rows = db.getNewEmployeeImageDir()
print(rows)
for row in rows:
Id = row['Id']
imageDirectory = row['ImageDirectory']
RecognitionObj.TrainUser(imageDirectory,Id)
db.insertLastTrainedAt()
ButtonTrain.config(state="normal")
ButtonTrain.config(state="disabled")
threading.Thread(target=subThread).start()
def clearRunTimeArray():
global runTimeArray
t = time.time()
while isRunning:
if(time.time()-t > 60):
runTimeArray = []
t = time.time()
runTimeArray = []
db = DbOperations.DbOperations("attendancemanagementsystem")
isRunning = True
thresholdAccuracy = 90
RecognitionObj = FaceRecognition.FaceRecognition("Models/haarcascade_frontalface_default.xml","Models/FaceRecognition.xml")
threading.Thread(target=clearRunTimeArray).start()
threading.Thread(target=main,args=("http://192.168.43.99/cgi-bin/snapshot.cgi","admin","mycamera2",'In')).start()
#threading.Thread(target=main,args=("http://192.168.43.98/cgi-bin/snapshot.cgi","admin","mycamera1",'Out')).start()
root = tk.Tk()
root.geometry("100x100")
root.resizable(0, 0)
ButtonTrain = tk.Button(root,text="Train",command=trainNewUsers)
ButtonTrain.grid(row=0,column=0,sticky=tk.W+tk.N+tk.S+tk.E)
root.mainloop()