функция входа в систему является основной функцией, она отлично работает в первый раз, но затем вызывает Пустой Sr c ошибка из flask импорт Flask, render_template
app = Flask ( name )
@app.route ('/ login') def login (): импорт cv2 import numpy как np import os
success = "no name"
face_classifier = cv2.CascadeClassifier('haarcascade_frontalface_default.xml')
newmodel=cv2.face_LBPHFaceRecognizer.create()
newmodel.read("savedstate.xml")
def face_detector(img, size=0.5):
# Convert image to grayscale
gray = cv2.cvtColor(img,cv2.COLOR_BGR2GRAY)
faces = face_classifier.detectMultiScale(gray, 1.3, 5)
if faces is ():
return img, []
for (x,y,w,h) in faces:
cv2.rectangle(img,(x,y),(x+w,y+h),(0,255,255),2)
roi = img[y:y+h, x:x+w]
roi = cv2.resize(roi, (200, 200))
return img, roi
# Open Webcam
cap = cv2.VideoCapture(0)
while True:
ret, frame = cap.read()
image, face = face_detector(frame)
try:
face = cv2.cvtColor(face, cv2.COLOR_BGR2GRAY)
# Pass face to prediction model
# "results" comprises of a tuple containing the label and the confidence value
results = newmodel.predict(face)
print(results)
if results[1] < 500:
confidence = int( 100 * (1 - (results[1])/400) )
display_string = str(confidence) + '% Confident it is User'
cv2.putText(image, display_string, (100, 120), cv2.FONT_HERSHEY_COMPLEX, 1, (255,120,150), 2)
if confidence > 80:
#os.system("docker run -d -i -t --name vimalos ubuntu:latest")
cv2.putText(image, "Hey Vimal", (250, 450), cv2.FONT_HERSHEY_COMPLEX, 1, (0,255,0), 2)
cv2.imshow('Face Recognition', image )
success = "Karmveer"
break
#webbrowser.open('http://google.com/')
else:
cv2.putText(image, "i dont know", (250, 450), cv2.FONT_HERSHEY_COMPLEX, 1, (0,0,255), 2)
cv2.imshow('Face Recognition', image )
except:
cv2.putText(image, "No Face Found", (220, 120) , cv2.FONT_HERSHEY_COMPLEX, 1, (0,0,255), 2)
cv2.putText(image, "Locked", (250, 450), cv2.FONT_HERSHEY_COMPLEX, 1, (0,0,255), 2)
cv2.imshow('Face Recognition', image )
pass
if cv2.waitKey(1) == 13: #13 is the Enter Key
break
cap.release()
cv2.destroyAllWindows()
#return render_template('hello.html', name = success)
@app.route ('/') def signup (): вернуть "привет"
, если name == ' main ': app.run ( host = '0.0.0.0', debug = True, use_reloader = False)