opencv_python3使用cv2.imread()、cv2.imwrite()、cv2.imdecode、cv2.imencode读取中文路径报错问题

版权声明:版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/z564359805/article/details/84448594

场景应用:https://blog.csdn.net/z564359805/article/details/84447377

import cv2
import numpy as np

# img_path图片路径需要更换
img=cv2.imdecode(np.fromfile(img_path, dtype=np.uint8), -1)
# 以下这个不能处理图片放在中文名字的文件夹中,并且img如果返回None说明路径中有中文
# img = cv2.imread(img_path)
# img.shape返回(高度,宽度,通道数)的元组。
if img.shape[0] > img.shape[1]:
    dim = (600, 800)
else:
    dim = (800, 600)
# 修改图片尺寸后生成的图片
img_small = cv2.resize(img, dim)
# img_small_path生成的图片保存路径地址,这个不知道为啥返回None
status = cv2.imencode('.jpg', img_small)[1].tofile(img_small_path)
# 返回true或false,处理中文路径不是很好
# status = cv2.imwrite(img_small_path, img_small)

猜你喜欢

转载自blog.csdn.net/z564359805/article/details/84448594