目录
step1_x_使用VOC切出类来——生成【jpedimage+annotation】
step1_x_labelImg
step1_x_labelImg
参考:
https://blog.csdn.net/qq_34809033/article/details/80589868
需要环境:python+pyqt
代码:
pip install PyQt5
pip install pyqt5_tools
pip install lxml
到labelImg的解压包,运行代码:
pyrcc5 -o resources.py resources.qrc
运行代码:
python labelImg.py
step1_x_使用VOC切出类来——生成【jpedimage+annotation】
# -*- coding: utf-8 -*-
# @Function:There are 20 classes in VOC data set. If you need to extract specific classes, you can use this program to extract them.
'''
# 根据需要更改三个地方
'''
import os
import shutil
ann_filepath='./VOC2007/Annotations/'
img_filepath='./VOC2007/JPEGImages/'
# step 1/3 根据需要改
img_savepath='./VOC2007_Pensorn/JPEGImages/'
ann_savepath='./VOC2007_Pensorn/Annotations/'
if not os.path.exists(img_savepath):
os.mkdir(img_savepath)
if not os.path.exists(ann_savepath):
os.mkdir(ann_savepath)
names = locals()
classes = ['aeroplane','bicycle','bird', 'boat', 'bottle',
'bus', 'car', 'cat', 'chair', 'cow','diningtable',
'dog', 'horse', 'motorbike', 'pottedplant',
'sheep', 'sofa', 'train', 'tvmonitor', 'person']
for file in os.listdir(ann_filepath):
print(file)
fp = open(ann_filepath + '\\' + file)
ann_savefile=ann_savepath+file
fp_w = open(ann_savefile, 'w')
lines = fp.readlines()
ind_start = []
ind_end = []
lines_id_start = lines[:]
lines_id_end = lines[:]
# step 2/3 根据需要改
#classes1 = '\t\t<name>bicycle</name>\n'
#classes2 = '\t\t<name>motorbike</name>\n'
#classes3 = '\t\t<name>bus</name>\n'
#classes4 = '\t\t<name>car</name>\n'
classes5 = '\t\t<name>person</name>\n'
#在xml中找到object块,并将其记录下来
while "\t<object>\n" in lines_id_start:
a = lines_id_start.index("\t<object>\n")
ind_start.append(a)
lines_id_start[a] = "delete"
while "\t</object>\n" in lines_id_end:
b = lines_id_end.index("\t</object>\n")
ind_end.append(b)
lines_id_e