【发布时间】:2022-11-21 20:02:13
【问题描述】:
我有一个文件夹,其中包含许多图像的 Pascal Voc XML 注释。注释看起来像下面的那个
<annotation>
<folder>images</folder>
<filename>Norway_000000.jpg</filename>
<size>
<width>3650</width>
<height>2044</height>
<depth/>
</size>
<segmented>0</segmented>
<object>
<name>D00</name>
<truncated>0</truncated>
<occluded>0</occluded>
<difficult>0</difficult>
<bndbox>
<xmin>1138.46</xmin>
<ymin>1281.93</ymin>
<xmax>1169.35</xmax>
<ymax>1336.85</ymax>
</bndbox>
<attributes>
<attribute>
<name>rotation</name>
<value>0.0</value>
</attribute>
</attributes>
</object>
<object>
<name>D20</name>
<truncated>0</truncated>
<occluded>0</occluded>
<difficult>0</difficult>
<bndbox>
<xmin>1537.53</xmin>
<ymin>1131.79</ymin>
<xmax>1629.06</xmax>
<ymax>1247.64</ymax>
</bndbox>
<attributes>
<attribute>
<name>rotation</name>
<value>0.0</value>
</attribute>
</attributes>
</object>
<object>
<name>D00</name>
<truncated>0</truncated>
<occluded>0</occluded>
<difficult>0</difficult>
<bndbox>
<xmin>1773.45</xmin>
<ymin>1825.97</ymin>
<xmax>1862.69</xmax>
<ymax>2038.78</ymax>
</bndbox>
<attributes>
<attribute>
<name>rotation</name>
<value>0.0</value>
</attribute>
</attributes>
</object>
<object>
<name>D00</name>
<truncated>0</truncated>
<occluded>0</occluded>
<difficult>0</difficult>
<bndbox>
<xmin>1589.02</xmin>
<ymin>1296.26</ymin>
<xmax>1624.77</xmax>
<ymax>1343.46</ymax>
</bndbox>
<attributes>
<attribute>
<name>rotation</name>
<value>0.0</value>
</attribute>
</attributes>
</object>
<object>
<name>D00</name>
<truncated>0</truncated>
<occluded>0</occluded>
<difficult>0</difficult>
<bndbox>
<xmin>1507.53</xmin>
<ymin>1216.53</ymin>
<xmax>1527.49</xmax>
<ymax>1254.27</ymax>
</bndbox>
<attributes>
<attribute>
<name>rotation</name>
<value>0.0</value>
</attribute>
</attributes>
</object>
</annotation>
我只想提取以下部分并保存新的 xml 文件。
<object>
<name>D00</name>
<truncated>0</truncated>
<occluded>0</occluded>
<difficult>0</difficult>
<bndbox>
<xmin>1138.46</xmin>
<ymin>1281.93</ymin>
<xmax>1169.35</xmax>
<ymax>1336.85</ymax>
</bndbox>
<attributes>
<attribute>
<name>rotation</name>
<value>0.0</value>
</attribute>
</attributes>
</object>
除了手动删除不需要的部分外,我没有找到任何特定的资源或指南来解决这个问题。如何读取文件夹中的所有文件,仅提取所需的注释,然后保存新的 xml 文件?我需要张量流中自定义对象检测的图像。
【问题讨论】:
-
从原始 XML 中提取特定
object元素的标准是什么?
标签: python xml tensorflow annotations object-detection