【发布时间】:2020-01-24 16:21:08
【问题描述】:
我正在开发 API 以使用 Flask 上传图像。上传后我想使用openCV修改图像,因为openCV需要numpy数组对象我有文件对象,我如何转换为numpy数组? 这是我的代码
@app.route('/upload', methods=['POST'])
def enroll_user():
file = request.files['fileName']
# file.save(os.path.join(file.filename))
return response
编辑:更新代码
@app.route('/upload', methods=['POST'])
def enroll_user():
file = request.files['fileName']
response = file.read()
# file.save(os.path.join(file.filename))
return response
我想用下面的代码将文件转换为 cv2 帧
ret, frame = cv2.imread(file)
一种方法是将图像写入磁盘并使用 cv2.imread 再次读取,但我不想这样做,因为这会很耗时。那么有没有办法从文件对象转换为 cv2 帧呢?
谢谢
【问题讨论】:
-
类似this?
-
能分享一下发送http请求的代码吗?
-
OpenCV图像对象是 numpy对象,一般dtype为np.uint8。 -
@QuangHoang 你说得对,OpenCV 图像对象是 numpy 对象,但我想将上传的 jpg 文件转换为 OpenCV 图像对象。