0

am trying to read an image using cv2.imread() but the flow just block there and never returns, tried to read already-existing files but got same issue, am not sure what is the reason is

@app.route('/api/upload', methods=['GET', 'POST'])
def upload_file():
    print('request method is {}'.format(request.method))
    if request.method == 'POST':
        # check if the post request has the file part
        if 'file' not in request.files:
            print('file not in request.files')
            return redirect(request.url)
        file = request.files['file']
        if file.filename == '':
            print('filename is {}'.format(file.filename))
            return redirect(request.url)
        print(file and allowed_file(file.filename))
        if file and allowed_file(file.filename):
            print('receiving ... ', file.filename)
            filename = secure_filename(file.filename)
            ts = int(time.time())
            file_name = file_name_template.format(ts, filename)
            print(file_name)
            filePath = os.path.join(app.root_path, app.config['UPLOAD_FOLDER'], file_name)

            file.save(filePath)
            print('reading image')
            cv2.imread(filePath)
            return 'done' #never executed

note : this is a flask application running on WAMP server + WSGI

Exorcismus
  • 2,243
  • 1
  • 35
  • 68

1 Answers1

0

I believe this has been answered already in another posting. Also see http://blog.rtwilson.com/how-to-fix-flask-wsgi-webapp-hanging-when-importing-a-module-such-as-numpy-or-matplotlib/.

Basically, it's not using the main interpreter to run the cv2.imread, which isn't running properly in a sub-interpreter.