Python3 Opencv 读取图片是中文路径乱码
# 解决读取中文路径乱码的问题
def cv_imread(file_path):
# imdedcode读取的是RGB图像
cvimg = cv2.imdecode(np.fromfile(file_path, dtype=np.uint8), -1)
return cvimg
# 解决读取中文路径乱码的问题
def cv_imwrite(file_path, image):
cv2.imencode('.png', image)[1].tofile(file_path)
应用 - JPG 转 PNG
# 图片格式转换, Jpg转Png
# 方法1
from PIL import Image
root = "D:\study\project\python\技巧\Jpg转Png\"
img = Image.open(root + '1.jpg')
img.save(root + '1.png')
# 方法2
import cv2
import np
# 解决读取中文路径乱码的问题
def cv_imread(file_path):
# imdedcode读取的是RGB图像
cvimg = cv2.imdecode(np.fromfile(file_path, dtype=np.uint8), -1)
return cvimg
# 解决读取中文路径乱码的问题
def cv_imwrite(file_path, image):
cv2.imencode('.png', image)[1].tofile(file_path)
image = cv_imread(root + "2.jpg")
cv_imwrite(root + "2.png")