简体   繁体   English

cv2.imread阻塞了流量

[英]cv2.imread is blocking flow

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 我试图使用cv2.imread()读取图像,但流程只是阻止那里,永远不会返回,试图读取已经存在的文件,但同样的问题,我不知道是什么原因是

@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 注意 :这是在WAMP server + WSGI上运行的烧瓶应用程序

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/ . 另请参阅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. 基本上,它没有使用主解释器来运行cv2.imread,它在子解释器中运行不正常。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM