后端从前端获取jpg格式的图片,想要用opencv处理,但该图片是jpg格式,而opencv需要一个矩阵,所以通过下面一段代码进行转换:参考原博文
TypeError: src is not a numpy array, neither a scalar----PIL Image转成opencv Image_GaoSimin-CSDN博客
image = request.files["image"]
pil_image = Image.open(image)
contrast_enhancer = ImageEnhance.Contrast(pil_image)
pil_enhanced_image = contrast_enhancer.enhance(2)
enhanced_image = np.asarray(pil_enhanced_image)
r, g, b = cv2.split(enhanced_image)
frame = cv2.merge([b, g, r])
#下面的不用写 是我的opencv操作
small_frame = cv2.resize(frame, (0, 0), fx=0.25, fy=0.25)
前端:
<form action="/FaceRecognition/" method="post" enctype="multipart/form-data">
<label for="">请上传图片:</label>
<input type="file" name="image"><br>
<input type="submit" value="提交">
</form>