【问题标题】:cv2.imread is blocking flowcv2.imread 阻塞流
【发布时间】:2019-09-17 15:09:38
【问题描述】:

我正在尝试使用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

注意:这是一个在 WAMP server + WSGI 上运行的烧瓶应用程序

【问题讨论】:

    标签: python apache opencv wamp wsgi


    【解决方案1】:

    我相信这个问题已经在另一个posting 中得到了回答。另见http://blog.rtwilson.com/how-to-fix-flask-wsgi-webapp-hanging-when-importing-a-module-such-as-numpy-or-matplotlib/

    基本上,它没有使用主解释器来运行 cv2.imread,它在子解释器中无法正常运行。

    【讨论】:

      猜你喜欢
      • 2020-05-08
      • 2021-04-05
      • 2017-11-17
      • 2019-03-28
      • 1970-01-01
      • 2013-07-30
      • 2013-10-01
      • 2018-04-07
      相关资源
      最近更新 更多