我试图使用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
上运行的烧瓶应用程序
我相信已经在另一个posting回答了这个问题。另见http://blog.rtwilson.com/how-to-fix-flask-wsgi-webapp-hanging-when-importing-a-module-such-as-numpy-or-matplotlib/。
基本上,它没有使用主解释器来运行cv2.imread,它在子解释器中运行不正常。