Page.py规格化图片、xml的序号
import os
import sys
def page(path, type):
names = os.listdir(path)
lenth = len(names)
num = [0] * lenth
for i in range(int(lenth)):
num[i] = "%02d" % i
temp = names[i]
new_name = num[i] + '.' + type
os.rename(path + '/' + temp, path + '/' + new_name)
if __name__ == '__main__':
path = "VOC2007/JPEGImages"
type = "jpg"
page(path, type)
bmp2jpg.py
import os
from PIL import Image
def bmpToJpg(file_path):
for fileName in os.listdir(file_path):
print(fileName)
newFileName = fileName.split('.')[0] + ".jpg"
print(newFileName)
img = Image.open(file_path + "\\" + fileName)
img = img.convert('RGB')
save_path = file_path + "\\output"
if not os.path.exists(save_path):
os.makedirs(save_path)
print("目录创建成功!")
img.save(save_path + "\\" + newFileName)
def deleteImages(file_path, imageFormat):
command = "del " + file_path + "\\*." + imageFormat
os.system(command)
def main():
file_path = r"D:\Study\yolov4-spore\VOCdevkit\VOC2007\JPEGImages"
bmpToJpg(file_path)
if __name__ == '__main__':
main()
predict_dir.py
from yolo import YOLO
from PIL import Image
import os
def get_file(path, save_path):
yolo = YOLO()
dir = os.listdir(path)
if not os.path.exists(save_path):
os.makedirs(save_path)
for file in dir:
print(file)
image = Image.open(path + "\\" + file)
r_image = yolo.detect_image(image)
r_image.save(save_path + "\\" + str(file))
if __name__ == '__main__':
path = r"D:\Study\yolov4-spore\VOCdevkit\VOC2007\JPEGImages"
save_path = path + "\\output"
get_file(path, save_path)