-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathFinalappWebcam.py
173 lines (117 loc) · 4.82 KB
/
FinalappWebcam.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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
import matplotlib
matplotlib.use('TkAgg')
import numpy as np
import tkinter
from matplotlib.backends.backend_tkagg import FigureCanvasTkAgg
from matplotlib.figure import Figure
from tkinter import *
from tkinter.ttk import *
import cv2
import pickle
def facerecog():
face_cascade = cv2.CascadeClassifier('D:\Cascades\haarcascade_frontalface_alt2.xml')
recognizer = cv2.face.LBPHFaceRecognizer_create()
recognizer.read("face-trainner.yml")
labels = {}
with open("face-labels.pickle", 'rb') as f:
og_labels = pickle.load(f)
labels = {v:k for k,v in og_labels.items()}
#frame = cv2.imread("D:\imagesdataset\Mark\mark.jpg")
#frame = cv2.imread("D:\imagesdataset\Lisa\lisa.jpg")
cap = cv2.VideoCapture(0)
while(True):
ret, frame = cap.read()
gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
faces = face_cascade.detectMultiScale(gray, scaleFactor=1.5, minNeighbors=5)
for (x, y, w, h) in faces:
roi_gray = gray[y:y+h, x:x+w]
roi_color = frame[y:y+h, x:x+w]
id_, conf = recognizer.predict(roi_gray)
if conf>=4 and conf <= 85:
name = labels[id_]
font = cv2.FONT_HERSHEY_SIMPLEX
color = (0, 255, 0)
stroke = 1
cv2.putText(frame, name, (x, y), font, 1, color, stroke, cv2.LINE_AA)
color = (255, 0, 0)
stroke = 2
end_cord_x = x + w
end_cord_y = y + h
cv2.rectangle(frame, (x, y), (end_cord_x, end_cord_y), color, stroke)
#print("Access Granted!" + " Hello, " + str(name))
return name
cv2.imshow('Scanning...', frame)
if cv2.waitKey(20) & 0xFF == ord('q'):
break
#------------------------------------------------------GUI SECTION -----------------------------------------------------------------------------------------------
class mclass:
def __init__(self):
self.window = window
window.title("HYDRO - INFINITY WATER MONITOR")
window.geometry("300x300")
self.button1 = Button(window, text="analysis", command=self.plot)
self.button1.place(relx=0.5, rely=0.4, anchor=CENTER)
self.button2 = Button(window, text="use water", command=self.scan)
self.button2.place(relx=0.5, rely=0.6, anchor=CENTER)
def plot(self):
window.geometry("600x550")
window.maxsize(600,550)
self.button3 = Button(window, text="overuse data", command=self.mainmenu)
self.button3.place(x=250,y=510)
fig = Figure(figsize=(6, 5))
a = fig.add_subplot(111)
a.bar(x, v, color='red')
a.set_title("Water Usage graph", fontsize=16)
a.set_ylabel("Number of litres of water used", fontsize=10)
a.set_xlabel("Name of water users", fontsize=10)
canvas = FigureCanvasTkAgg(fig, master=self.window)
canvas.get_tk_widget().pack()
canvas.draw()
def scan(self):
namevar = facerecog()
if namevar:
mclass.finish(self,name=namevar)
def mainmenu(self):
for i in range(len(usage)):
if usage[i]>limit:
print(person[i]+" has overused "+str(usage[i]-limit)+" Ltrs")
def finish(self,name):
window.geometry("600x350")
window.maxsize(600,400)
self.window = window
fig = Figure(figsize=(6, 5))
canvas = FigureCanvasTkAgg(fig, master=self.window)
canvas.get_tk_widget().pack()
canvas.draw()
percentage = 100 - ( ((usagedict[name])/limit)*100)
AccessGranted = Label(window, text="ACCESS GRANTED !").place(x=255, y=50)
HelloUser = Label(window, text="Hello, {}".format(name)).place(x=270, y=80)
Volume = Label(window, text="1.502 L").place(x=285, y=110)
ConsumedAmount = Label(window, text="You have consumed {} L today !".format(usagedict[name])).place(x=215, y=170)
HelloUser = Label(window, text="Remaining").place(x=30, y=250)
Percentage = Label(window, text=str(percentage)+"%").place(x=525, y=250)
pgbar = Progressbar(
window,
length=400,
orient=HORIZONTAL,
maximum=100,
value=percentage,
mode='determinate',
)
pgbar.pack()
btn = tkinter.Button(
window,
text="Finish",
command=exit,
)
pgbar.place(x=110, y=250)
btn.place(x=280, y=280)
person =["lisa","mark"]
usagedict={"lisa":5,"mark":3.5}
usage=[5,3.5]
limit=2
x = np.array(person)
v = np.array(usage)
window = Tk()
start = mclass()
window.mainloop()