from xml.dom.minidom import Document
import os
import cv2
def makexml(picPath, txtPath, xmlPath): # txt所在文件夹路径,xml文件保存路径,图片所在文件夹路径
"""此函数用于将yolo格式txt标注文件转换为voc格式xml标注文件
在自己的标注图片文件夹下建三个子文件夹,分别命名为picture、txt、xml
"""
# 此处的字典要与自己的classes.txt文件中的类对应,且顺序要一致
dic = {'0': 'class1', # 创建字典用来对类型进行转换
'1': 'class2',
'2': 'class3',
'3': 'class4',
'4': 'class5',
'5': 'class6',
}
files = os.listdir(txtPath)
for i, name in enumerate(files):
xmlBuilder = Document()
annotation = xmlBuilder.createElement("annotation") # 创建annotation标签
xmlBuilder.appendChild(annotation)
txtFile = open(txtPath + name)
txtList = txtFile.readlines()
img = cv2.imread(picPat
04-27
3万+
02-03
606
04-29
369
08-01
634