AndrewCarterUK / pascal-voc-writer

A python library for generating annotations in the PASCAL VOC format.
MIT License
220 stars 57 forks source link

XML file if malformed for successive writer.addObject(‘cat’, 100, 100, 200, 200) #8

Open Cbhihe opened 3 years ago

Cbhihe commented 3 years ago

[Python 3.7.0] The code snippet is:

for i in range(0,len(yhat['rois'])):
    ymin, xmin, ymax, xmax = yhat['rois'][i]    
    writer.addObject(classids[yhat['class_ids'][i]],xmin,ymin,xmax,ymax)
writer.save(‘path/to/img.xml’)

produces malformed PASCAL VOC xml files. Successive objects sections are not correctly aligned. Instead what you get is:

    <object>
        <name>sheep</name>
        <pose>Unspecified</pose>
        <truncated>0</truncated>
        <difficult>0</difficult>
        <bndbox>
            <xmin>348</xmin>
            <ymin>277</ymin>
            <xmax>401</xmax>
            <ymax>325</ymax>
        </bndbox>
    </object>    <object>
        <name>shepherd</name>
        <pose>Unspecified</pose>
        <truncated>0</truncated>
        <difficult>0</difficult>
        <bndbox>
            <xmin>260</xmin>
            <ymin>165</ymin>
            <xmax>364</xmax>
            <ymax>381</ymax>
        </bndbox>
    </object>    <object>
        <name>cow</name>
        <pose>Unspecified</pose>
        <truncated>0</truncated>
        <difficult>0</difficult>
        <bndbox>
            <xmin>604</xmin>
            <ymin>300</ymin>
            <xmax>665</xmax>
            <ymax>353</ymax>
        </bndbox>
    </object>

Everything is correctly aligned except for the </object> <object> . There is a missing newline character between closing and opening "object" tags.