- 代码
import os
import xml.dom.minidom
import cv2
ImgPath = './train-A/image/'
AnnoPath = './train-A/box/'
imagelist = os.listdir(ImgPath)
for image in imagelist:
image_pre, ext = os.path.splitext(image)
imgfile = ImgPath + image
xmlfile = AnnoPath + image_pre + '.xml'
DOMTree = xml.dom.minidom.parse(xmlfile)
collection = DOMTree.documentElement
img = cv2.imread(imgfile)
filenamelist = collection.getElementsByTagName("frame")
filename = filenamelist[0].childNodes[0].data
cv2.putText(img,filename,(10,20), cv2.FONT_HERSHEY_COMPLEX, 0.7, (0, 255, 0), thickness=2)
img_size_list=collection.getElementsByTagName('size')
for img_size in img_size_list:
img_width_list = img_size.getElementsByTagName('width')
img_height_list = img_size.getElementsByTagName('height')
img_width = img_width_list[0].childNodes[0].data
img_height = img_height_list[0].childNodes[0].data
cv2.putText(img, img_width, (10,