Python show Ground True

Image data using Pascal voc 2007 000012 inside, copy this picture and the corresponding xml file to the same directory Code

import xml.etree.ElementTree as ET
import matplotlib.pyplot as plt
import matplotlib.image as mpimg # mpimg 用于读取图片
xml_path='000012.xml'
tree = ET.parse(xml_path)
root=tree.getroot()
for object in root.findall('object'):
    a = []
    a.append(object.find('name').text)
    a.append(int(object.find('bndbox').find('xmin').text))
    a.append(int(object.find('bndbox').find('ymin').text))
    a.append(int(object.find('bndbox').find('xmax').text))
    a.append(int(object.find('bndbox').find('ymax').text))

pic = mpimg.imread('000012.jpg')
fig, ax = plt.subplots()
ax.add_patch(plt.Rectangle((a[1],a[2]),a[3]-a[1],a[4]-a[2],fill=False,edgecolor='r', linewidth=2.5))
plt.imshow(pic)
plt.show()

Original:

Figure GT:

 

Guess you like

Origin www.cnblogs.com/vshen999/p/11270550.html