import cv2
import numpy as np
import os
# 读带有中文路径和中文名称的图片
def cv_imread(file_path):
cv_img = cv2.imdecode(np.fromfile(file_path,dtype = np.uint8), -1)
# imdecode读取的是rgb,如果后续需要opencv处理的话,需要转换成bgr,转换后图片颜色会变化
#cv_img=cv2.cvtColor(cv_img,cv2.COLOR_RGB2BGR)
return cv_img
# 写入到带有中文路径和中文名称的图片
def cv_imwrite(imPath):
(filepath,tempfilename) = os.path.split(imPath) # 分开路径和图片名
(filename,extension) = os.path.splitext(tempfilename) # 分开图片名称和后缀名
newresImagePath = filepath + "/a/"
newresImage = filename + "b" + extension
newPath = newresImagePath + newresImage
if not os.path.exists(newresImagePath):
os.makedirs(newresImagePath)
cv2.imencode('.jpg', imPath)[1].tofile(newPath) # 写入带有中文路径和中文名称的图片
return newPath
python图片(带有中文路径和中文名称的)读写
最新推荐文章于 2024-10-17 16:08:56 发布