-
Notifications
You must be signed in to change notification settings - Fork 0
/
freak.py
executable file
·254 lines (241 loc) · 11.5 KB
/
freak.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
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
from pyrebase import pyrebase
from flask import (
Flask,
url_for,
render_template,
redirect,
request
)
import datetime
from forms import SignUpForm
from forms import OrderFood
from wtforms import Form, TextField, TextAreaField, validators, StringField, SubmitField
from flask import Flask, render_template, request, flash
import cv2
import cv2 as cv
import numpy as np
#import imutils
import time
# from imutils.video import VideoStream
# from imutils.video import FPS
import os
from PIL import Image
import sys
sys.path.append('/aneeshakodati/env/lib/python3.8/site-packages')
app=Flask(__name__)
app.config['SECRET_KEY'] = 'any secret string'
Config = {
"apiKey": "AIzaSyC6z8NHE2s9mg265PgOZNVsNuOJvQxkSzM",
"authDomain": "free-ak-app.firebaseapp.com",
"databaseURL": "https://free-ak-app-default-rtdb.firebaseio.com",
"projectId": "free-ak-app",
"storageBucket": "free-ak-app.appspot.com",
"messagingSenderId": "1088930365757",
"appId": "1:1088930365757:web:df1a7163b11981f7ec8554",
"measurementId": "G-VKK8XKSWC7"
}
firebase=pyrebase.initialize_app(Config)
auth=firebase.auth()
db=firebase.database()
storage=firebase.storage()
# faceCascade = cv.CascadeClassifier("haarcascade_frontalface_default.xml")
# recognizer = cv.face.LBPHFaceRecognizer_create()
# recognizer.read('trainer.yml')
# cascadePath = "haarcascade_frontalface_default.xml"
# faceCascade = cv.CascadeClassifier(cascadePath);
# font = cv.FONT_HERSHEY_SIMPLEX
id = 0
@app.route('/', methods=['GET', 'POST'])
def welcome():
# file = open("ids.txt", "r")
# names = (file.read()).split()
# video_feed = VideoStream(src=0).start()
# print("\n[INFO] Entering Stream Stage...")
# print("[INFO] starting video stream...")
# time.sleep(2.0)
# fps = FPS().start()
# while ((cv.waitKey(1) & 0xFF) != ord("q")):
# frame = video_feed.read() #get webcam feed
# #frame = cv.flip(frame, -1)
# frame = imutils.resize(frame, width=500)
# gray = cv.cvtColor(frame, cv.COLOR_BGR2GRAY) #grayscale image
# found = faceCascade.detectMultiScale (gray, scaleFactor=1.1, minNeighbors=10, minSize = (30, 30)) #detect faces
# for(x,y,w,h) in found:
# cv.rectangle(frame, (x,y), (x+w,y+h), (0,255,0), 2)
# id, confidence = recognizer.predict(gray[y:y+h,x:x+w])
# if (confidence < 100):
# id =str( names[id].split("*")[-1])
# print(id)
# information=db.child("users").child(id.replace("@", "").replace("_", "").replace(".", "")).get()
# fps.stop()
# video_feed.stream.release()
# return render_template('user.html', information=information.val())
# confidence = " {0}%".format(round(100 - confidence))
# else:
# fps.stop()
# video_feed.stream.release()
form=SignUpForm()
if form.is_submitted():
result=request.form
try:
auth.sign_in_with_email_and_password(str(form.email)[50:len(str(form.email))-2],(str(form.password)[56:len(str(form.password))-2]) )
except:
return render_template('wrongpasswordusername.html', result=result, form=form)
try:
email=str(form.email)[50:len(str(form.email))-2].replace(".", "").replace("@", "").replace("_", "").replace("-", "")
information=db.child("users").child(email).get()
return render_template('user.html', result=result, information=information.val())
except:
print("Error in getting information from database")
return render_template('facenotrecognized.html', form=form)
return render_template ('home.html', form=form)
# def getImagesAndLabels(path):
# imagePaths = [os.path.join(path,f) for f in os.listdir(path)]
# faceSamples=[]
# ids = []
# f=open("ids.txt", "a+")
# f1=f.readlines()
# id=0
# for imagePath in imagePaths:
# PIL_img = Image.open(imagePath).convert('L') # convert it to grayscale
# img_numpy = np.array(PIL_img,'uint8')
# emailid = str(os.path.split(imagePath)[-1].split("~")[1])
# for x in f1:
# if(str(x.split("*")[-1])==emailid):
# id=int(x.split("*")[0])
# faces = detector.detectMultiScale(img_numpy)
# for (x,y,w,h) in faces:
# faceSamples.append(img_numpy[y:y+h,x:x+w])
# ids.append(id)
# return faceSamples,ids
# def getImagesAndLabels(path):
# imagePaths = [os.path.join(path,f) for f in os.listdir(path)]
# faceSamples=[]
# ids = []
# f=open("ids.txt", "a+")
# f1=f.readlines()
# id=0
# for imagePath in imagePaths:
# PIL_img = Image.open(imagePath).convert('L') # convert it to grayscale
# img_numpy = np.array(PIL_img,'uint8')
# emailid = str(os.path.split(imagePath)[-1].split("~")[1])
# for x in f1:
# if(str(x.split("*")[-1])==emailid):
# id=int(x.split("*")[0])
# detector = cv.CascadeClassifier("haarcascade_frontalface_default.xml");
# faces = detector.detectMultiScale(img_numpy)
# for (x,y,w,h) in faces:
# faceSamples.append(img_numpy[y:y+h,x:x+w])
# ids.append(id)
# return faceSamples,ids
@app.route("/orderfood", methods=['GET', 'POST'])
def menu():
form=OrderFood()
if form.is_submitted():
result=request.form
item=form.item
print (item)
quantity=request.form.get('quantity', type=int)
print (quantity)
type=form.type
print (type)
pico=form.pico
print (pico)
beans=form.beans
print (beans)
email=str(form.email)[50:len(str(form.email))-2].replace(".", "").replace("@", "").replace("_", "").replace("-", "")
data={'item': str(item), 'pico':str(pico), 'quantity':str(quantity), 'beans':str(beans), 'type':str(type)}
today=datetime.datetime.today()
db.child("users").child(email).child("orders").child(today.strftime("%B %d, %Y")).child(today.strftime("%H:%M:%S")).set(data)
return render_template('ordersuccessful.html', form=form, price=quantity*8)
return render_template('menu.html', form=form)
@app.route("/createaccount", methods=['GET', 'POST'])
def createAccount():
form=SignUpForm()
if form.is_submitted():
result=request.form
email=str(form.email)[50:len(str(form.email))-2]
password=(str(form.password)[56:len(str(form.password))-2])
name=str(form.name)[48:len(str(form.name))-2]
cardno=str(form.creditCardNumber)[48:len(str(form.name))-2]
cardexp= str(form.creditCardExpiration)[48:len(str(form.name))-2]
cvv=str(form.cardCVV)[48:len(str(form.name))-2]
try:
auth.create_user_with_email_and_password(email, password )
data={'email': email, 'password':password, 'name':name, 'creditCard':cardno, 'ccc':cvv, 'expiryDate': cardexp}
db.child("users").child(email.replace(".","").replace("@", "").replace("_", "")).set(data)
f= open("ids.txt","r")
lines=f.readlines()
# ids=0
# for line in lines:
# print(line);
# if(int(line.split("*")[0])>int(ids)):
# ids=int(line.split("*")[0])
# ids+=1
# faceCascade = cv.CascadeClassifier("haarcascade_frontalface_default.xml")
# video_feed = VideoStream(src=0).start()
# time.sleep(2.0)
# count = 0
# f=open("ids.txt", "a+")
# f.write(str(ids)+"*"+email+"\n")
# print("[INFO] Starting capture...")
# while (True):
# if count >= 10:
# break
# frame = video_feed.read() #get webcam feed
# #frame = cv.flip(frame, -1)
# frame = imutils.resize(frame, width=500)
# gray = cv.cvtColor(frame, cv.COLOR_BGR2GRAY) #grayscale image
# found = faceCascade.detectMultiScale (gray, scaleFactor=1.1, minNeighbors=10, minSize = (30, 30)) #detect faces
# for (x,y,w,h) in found:
# cv.rectangle(frame,(x,y),(x+w,y+h),(0,255,0),2)
# count += 1
# roi_gray = gray[y:y+h, x:x+w]
# roi_color = frame[y:y+h, x:x+w]
# cv.imwrite( "images/" +email+ '~' +
# str(count) +
# ".jpg", gray[y:y+h,x:x+w])
# #storage.child(email.replace(".","").replace("@", "").replace("_", "")).child("img" + '.' +str(count) +".jpg").put( "img" + '.' +str(count) +".jpg")
# print("stored image" + str(count))
# video_feed.stream.release()
# path = "images"
# recognizer = cv.face.LBPHFaceRecognizer_create()
# detector = cv.CascadeClassifier("haarcascade_frontalface_default.xml");
# print("\n[INFO] Entering Training Stage...")
# print ("[INFO] Training faces. It will take a few seconds. Wait...")
# faces,ids = getImagesAndLabels(path)
# recognizer.train(faces, np.array(ids))
# # Save the model into trainer/trainer.yml
# recognizer.write('trainer.yml')
# print("[INFO] {0} faces trained ...".format(len(np.unique(ids))))
# return render_template('facialrecognition.html', result=result)
except:
information=db.child("users").child(email.replace("@","").replace("_", "").replace(".", "").replace("-", "")).get()
return render_template('user.html', result=result, information=information.val())
return render_template('newaccount.html', form=form)
@app.route("/updateinfo", methods=['GET', 'POST'])
def updateinfo():
form=SignUpForm()
if form.is_submitted():
result=request.form
try:
auth=sign_in_with_email_and_password (str(form.email)[50:len(str(form.email))-2], str(form.password)[56:len(str(form.password))-2])
db.child("users").child(email_wnsc).update({'password':str(form.password)[56:len(str(form.password))-2], 'name':str(form.name)[48:len(str(form.name))-2], 'creditCard':str(form.creditCardNumber)[48:len(str(form.name))-2]})
return render_template('facialrecognition.html', result=result)
except:
return render_template('wrongpasswordusername.html', result=result)
return render_template('updateinfo.html', form=form)
# def facialrecog(form, result):
# for i in range(1, 5):
# s, image=cam.read()
# if s:
# namedWindow("facial recognition image", CV_WINDOW_AUTOSIZE)
# imshow("facial recognition image", img)
# waitKey(0)
# destroyWindow("facial recognition image")
# filename="image"+str(i)+".jpg"
# imwrite(filename, img)
# storage.child(str(form.email)[50:len(str(form.email))-2]+"/facialrecog").put(filename)
# return render_template('facialrecognition.html', result=result)
if __name__=='__main__':
app.run(debug=True)