opencv 使用flask,在包含文件上传的POST请求的处理程序中,我如何读取该数据?

du7egjpx  于 2023-02-05  发布在  其他
关注(0)|答案(1)|浏览(234)

我需要从一个HTML表单的输入类型文件中获取一个图像,然后用opencv裁剪它,但是我不知道如何阅读它,有人能帮助我吗?
超文本:

<form role="form" method="POST" action="update-doc" enctype="multipart/form-data">
   <div class="input-group input-group-lg mb-3">
    <label class="input-group-text" for="inputGroupFile01">UPLOAD</label>
    <input type="file" class="form-control" name="pic" accept="image/png, image/jpeg" id="inputGroupFile01">
   </div>
   <button type="submit" class="btn btn-primary px-5 shadow">UPLOAD</button>
</form
    • Python:
from flask import Flask, render_template, request, url_for, redirect, session, flash
import cv2
profileimg = request.files['pic']
img = cv2.imread(profileimg)
8ehkhllq

8ehkhllq1#

这对我很有效

from urllib import request
import cv2
profileimg = request.form['pic']
img = cv2.imread(profileimg)
crop_img = img[y_begin:height, x_begin:width]

相关问题