Python 小程序
'''
功能:读取文件夹里的所有文件,判断是不是图片文件,然后进行图片反转,更改文件名后保存到指定文件夹中
入参:
file_compare:读取文件路径,
save_Path:保存文件路径
输出图片
''’
import os import cv2 import numpy as np def deal_Image( file_compare, save_Path): for i in os.listdir(file_compare): image_Path = os.path.join(file_compare, i) string_name = os.path.splitext(i) name = {'.jpg', '.bmp', '.png', '.jpeg', '.rgb', '.tif'} if string_name[1] in name: img = cv2.imread(image_Path, -1) img = 255 - img cv2.imwrite(save_Path + "/" + string_name[0]+"_label"+".png", img) if __name__ == '__main__': file_compare = r'D:\xuexi1\region' save_Path = r'D:\xuexi1\model' deal_Image(file_compare,save_Path)