LabelMe XML转换为CSV

时间:2018-10-19 06:34:26

标签: python csv image-processing object-detection

我有从LabelMe工具生成的带注释的xml文件。 我必须将其转换为csv文件。

<annotation><filename>image10.jpg</filename><folder>users/mayurakewar//card</folder><source><submittedBy>Mayur Akewar</submittedBy></source><imagesize><nrows>480</nrows><ncols>640</ncols></imagesize><object><name>id card</name><deleted>0</deleted><verified>0</verified><occluded>yes</occluded><attributes/><parts></parts><date>18-Oct-2018 18:01:12</date><id>0</id><polygon><username>anonymous</username><pt><x>141</x><y>167</y></pt><pt><x>228</x><y>161</y></pt><pt><x>237</x><y>307</y></pt><pt><x>149</x><y>308</y></pt></polygon></object></annotation>

CSV的列必须为图像,标签,x和y对象检测边界的大小。


以下是相同数据的“精美图片”:

<annotation>
    <filename>image10.jpg</filename>
    <folder>users/mayurakewar//card</folder>
    <source>
        <submittedBy>Mayur Akewar</submittedBy>
    </source>
    <imagesize>
        <nrows>480</nrows>
        <ncols>640</ncols>
    </imagesize>
    <object>
        <name>id card</name>
        <deleted>0</deleted>
        <verified>0</verified>
        <occluded>yes</occluded>
        <attributes/>
        <parts></parts>
        <date>18-Oct-2018 18:01:12</date>
        <id>0</id>
        <polygon>
            <username>anonymous</username>
            <pt>
                <x>141</x>
                <y>167</y>
            </pt>
            <pt>
                <x>228</x>
                <y>161</y>
            </pt>
            <pt>
                <x>237</x>
                <y>307</y>
            </pt>
            <pt>
                <x>149</x>
                <y>308</y>
            </pt>
        </polygon>
    </object>
</annotation>

1 个答案:

答案 0 :(得分:0)

这是一个嵌套的数据结构。我不确定是否可以将其转换为CSV。首先,您需要先将其转换为平面结构,然后按其列对其进行排序。

顺便说一句,我不确定这个问题在StackOverflow中是否合适。