中文名称读取与保存方式如下主代码:

img = cv2.imdecode(np.fromfile(data_root, dtype=np.uint8), -1)#中文名读取方式
cv2.imencode('.jpg', img_draw)[1].tofile(os.path.join(out_img,img_name))#中文名保存方式

 

 

 

def read_chinese_name_img(target_size=(500, 500)):
    # 该函数读取具有中文名称的图片,并将其resize成某个尺寸,以自定义名称保存图片
    import cv2
    import numpy as np
    import os
    path = 'C:/Users/tj/Desktop/company/region_map_esri5'  # 读取图片路径
    path_save = 'C:/Users/tj/Desktop/unet-master/data/build_img3/true_predict/'  # 保存图片路径
    # 读入中文命名图片
    names = os.listdir(path)
    def cv_imread(in_path):
        cv_img = cv2.imdecode(np.fromfile(in_path, dtype=np.uint8), -1)  # -1表示cv2.IMREAD_UNCHANGED
        return cv_img
    num = 0
    for name in names:
        in_path = os.path.join(path, name)
        img = cv_imread(in_path)
        print(in_path)
        # img = cv2.cvtColor(img, cv2.COLOR_RGB2GRAY)
        # img = cv2.cvtColor(img)
        if target_size is not None:
            img = cv2.resize(img, target_size)
        cv2.imwrite(path_save + str(num) + '.png', img)
        num = num + 1