from PIL import Image
import os
file_root = 'C:/Users/Administrator/Desktop/采矿数据/0307hhdata/切好/zn/images/' # 当前文件夹下的所有图片
file_list = os.listdir(file_root)
save_out = "C:/Users/Administrator/Desktop/采矿数据/0307hhdata/mineral_data/positive/" # 保存图片的文件夹名称
save_out_negative = "C:/Users/Administrator/Desktop/采矿数据/0307hhdata/mineral_data/negative/" # 保存图片的文件夹名称
list = [52,58,59,71,72,73,74,75,93,94,
98,111,114,115,132,191,192,211,212,213,
232,233,234,240,254,258,261,275,283,296,
297,298,301,304,322,325,345,346,366,367,
387]
for img_name in file_list:
for l in list:
if img_name == 'zn_'+str(l)+'.jpg':
img_path = file_root + img_name
img = Image.open(img_path) # 读取图片
out_name = img_name.split('.')[0]
save_path = save_out + out_name + '.jpg'
img.save(save_path) # 保存图片
os.remove(img_path) # 删除图片
file_list2 = os.listdir(file_root)
for img_name in file_list2:
img_path = file_root + img_name
img = Image.open(img_path) # 读取图片
out_name = img_name.split('.')[0]
save_path = save_out_negative + out_name + '.jpg'
img.save(save_path) # 保存图片
os.remove(img_path) # 删除图片
print('Done!')
05-26
1338
05-11