python3 opencv中文路径图片读取和写入

问题描述

cv2.imread路径为中文时返回None。

方案

在这里插入图片描述

读取(先用np.fromfile读取为np.uint8格式,再使用cv2.imdecode解码):

# 文件路径file_path,返回读取后的图片
cv_img = cv2.imdecode(np.fromfile(file_path,dtype=np.uint8),-1)

写入:

cv2.imencode('.jpg',img)[1].tofile(file_path)

参考:https://www.zhihu.com/question/47184512

猜你喜欢

转载自blog.csdn.net/nima1994/article/details/86505192