I was developing an app that returns JSON data if an uploaded image matches the image in the app folder. After selecting a particular image, I click "Upload" image it shows "No file chosen". The below given whole code. How can I fix this up? Thank you, in advance!
import cv2
import face_recognition
import os
from flask import Flask, jsonify, request, redirect
app = Flask(__name__)
@app.route('/', methods=['GET', 'POST'])
def upload_image():
# Check if a valid image file was uploaded
if request.method == 'POST':
if 'file' not in request.files:
return redirect(request.url)
file = request.files['file']
if file.filename == '':
return redirect(request.url)
return '''
<!doctype html>
<h1>Upload a picture for image recognition</h1>
<form method="POST" enctype="multipart/form-data">
<input type="file" name="file">
<input type="submit" value="Upload">
</form>
'''
path = "Images"
images = []
myList = os.listdir(path)
#print(myList)
for cl in myList:
curImg = face_recognition.load_image_file(f'{path}/{cl}')
images.append(curImg)
encodeList=[]
for img in images:
encode=face_recognition.face_encodings(img)[0]
encodeList.append(encode)
print(encodeList)
def findEncodings(file_stream):
img = face_recognition.load_image_file(file)
# Get face encodings for any faces in the uploaded image
unknown_face_encodings = face_recognition.face_encodings(img)[0]
is_the_same_person = False
if len(unknown_face_encodings) > 0:
match_results = face_recognition.compare_faces(encodeList, unknown_face_encodings)
if match_results[0]:
is_obama = True
# Return the result as json
result = {
"is_the_same_person": same
}
return jsonify(result)
if __name__ == "__main__":
app.run(debug=True)
findEncodings()
is not being called anywhere. Does it serve any purpose or should it be removed from the code snippet?