0

I made a small python app for face recognition and now I am converting it into a flask application.

@app.route('/save', methods=['POST'])
def save_image():
    if request.method == 'POST':
        if 'imageFile' not in request.files:
            return {"detail": "No file found"}, 400
        image = request.files['imageFile']
        imageFileName = secure_filename(image.filename)
        image.save('./images/' + imageFileName)
        image = cv2.imread('./images/' + imageFileName)
        image = cv2.cvtColor(image,cv2.COLOR_BGR2RGB)
        face_encoding = face_recognition.face_encodings(image)[0]   
        np.savetxt('./encodings/' + request.form['indexNumber'] + '.csv', face_encoding, delimiter=',')
    return 'saving image' 

In the above code I have saved the image posted to the server and read it again using cv2.imread and have later used it to create the face encoding. What I want is to do this without saving the image in the server. Is there a way to directly read the image posted and use like above?

  • https://stackoverflow.com/questions/13329445/how-to-read-image-from-in-memory-buffer-stringio-or-from-url-with-opencv-pytho – Dave W. Smith Oct 16 '20 at 17:31
  • Does this answer your question? [How to read image from in memory buffer (StringIO) or from url with opencv python library](https://stackoverflow.com/questions/13329445/how-to-read-image-from-in-memory-buffer-stringio-or-from-url-with-opencv-pytho) – Dave W. Smith Oct 17 '20 at 17:30
  • Nope sadly it didnt work. Still looking for a way – Gimantha Dissanayake Oct 18 '20 at 03:07

0 Answers0