darknet里面有将voc转换成yolo格式数据集的脚本,有时需要反过来转换,因此写了一个脚本。
import cv2
import os
xml_head = '''<annotation>
<folder>VOC2007</folder>
<!--文件名-->
<filename>{}</filename>.
<source>
<database>The VOC2007 Database</database>
<annotation>PASCAL VOC2007</annotation>
<image>flickr</image>
<flickrid>325991873</flickrid>
</source>
<owner>
<flickrid>null</flickrid>
<name>null</name>
</owner>
<size>
<width>{}</width>
<height>{}</height>
<depth>{}</depth>
</size>
<segmented>0</segmented>
'''
xml_obj = '''
<object>
<name>{}</name>
<pose>Rear