此函数用于将yolo格式txt标注文件转换为voc格式xml标注文件
from xml.dom.minidom import Document
import os
import cv2
def makexml(picPath, txtPath, xmlPath):
"""此函数用于将yolo格式txt标注文件转换为voc格式xml标注文件
"""
dic = {
'0': 'hat',
'1': 'smoke'
}
files = os.listdir(txtPath)
for i, name in enumerate(files):
xmlBuilder = Document()
annotation = xmlBuilder.createElement("annotation")
xmlBuilder.appendChild(annotation)
txtFile = open(txtPath + name)
txtList = txtFile.readlines()
img = cv2.imread(picPath + name[0:-4] + ".png")
Pheight, Pwidth, Pdepth = img.shape
folder = xmlBuilder.createElement("folder")
foldercontent = xmlBuilder.createTextNode("driving_annotation_dataset")
folder.appendChild(foldercontent)
annotation.appendChild(folder)
filename = xmlBuilder.createElement("filename")
filenamecontent = xmlBuilder.createTextNode(