簡體   English   中英

cv2.imread阻塞了流量

[英]cv2.imread is blocking flow

我試圖使用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上運行的燒瓶應用程序

我相信這已經在另一篇帖子中得到了回答。 另請參閱http://blog.rtwilson.com/how-to-fix-flask-wsgi-webapp-hanging-when-importing-a-module-such-as-numpy-or-matplotlib/

基本上,它沒有使用主解釋器來運行cv2.imread,它在子解釋器中運行不正常。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM