python读入写入中文名图片
作者:互联网
import os import cv2 import numpy as np # 读入中文命名图片 def cv_imread(in_path): cv_img = cv2.imdecode(np.fromfile(in_path, dtype=np.uint8), -1) # -1表示cv2.IMREAD_UNCHANGED return cv_img # 写入中文命名图片 def cv_imwrite(out_path, img_np): cv2.imencode('.png', img_np)[1].tofile(out_path) in_dir = 'C:/Users/pic/' out_dir = 'C:/Users/pic/' for img_name in os.listdir(in_dir): img = cv_imread(in_dir + img_name) new_name = img_name.replace('.jpg', '.png') cv_imwrite(out_dir + new_name, img) print(new_name)
标签:name,img,python,中文名,读入,np,cv,dir,out 来源: https://www.cnblogs.com/Lynn0101/p/10944124.html