文章预览
提取图片代码:
# -*- coding: UTF-8 -*-
# !/usr/bin/env python
import sys
import re
from PIL import Image
sys.path.append('F:\\beifen')
import numpy as np
data = []
for line in open("F:\\beifen\keras-yolo3-master\VOC2018\ImageSets\Main/testjpg.txt", "r"): # 设置文件对象并读取每一行文件
data.append(line)
for a in data:
im = Image.open('F:\\beifen\keras-yolo3-master\VOC2018\JPEGImages/{}'.format(a[:-1])) # 打开改路径下的line3记录的的文件名
im.save('F:\\beifen\keras-yolo3-master\VOC2018\ImageSets\Layout/{}'.format(a[:-1])) # 把文件夹中指定的文件名称的图片另存到该路径下
im.close()
提取XML文件代码:
import os
import shutil
if __name__ == '__main__':
f = open("testxml.txt","r") #存放有XML文件名字的txt
line = f.readline()
line = line[:-1]
while line:
line = f.readline()
line = line.strip('\n')
print(line)
path = os.getcwd()
new_path = "F:\\beifen\keras-yolo3-master\VOC2018\Annotations\\"+line #路径为保存XML文件的文件夹
print(new_path)
try:
shutil.move(new_path, 'F:\\beifen\\keras-yolo3-master\\VOC2018\\123') #提取后保存的位置
except:
print("Not find error.")
# print(path)
f.close()
………………………………