0

I'm currently working on image labeling for multiple files and the labels are saved in XML. Turns out all the labels need to be shortened in height as the details in the upper part of the label are similar to other unrelated pictures. Therefore, I would like to subtract the value of all <ymax>(number)</ymax> in all of the XML files by a certain value. Is there a way to do this using notepad++ or python?

Below is an example of a full XML file. All of the files have the same format.

<annotation>
    <folder>01</folder>
    <filename>S249.jpeg</filename>
    <path>D:\databs\01\01\S249.jpeg</path>
    <source>
        <database>Unknown</database>
    </source>
    <size>
        <width>375</width>
        <height>500</height>
        <depth>3</depth>
    </size>
    <segmented>0</segmented>
    <object>
        <name>A</name>
        <pose>Unspecified</pose>
        <truncated>0</truncated>
        <difficult>0</difficult>
        <bndbox>
            <xmin>116</xmin>
            <ymin>280</ymin>
            <xmax>141</xmax>
            <ymax>325</ymax>
        </bndbox>
    </object>
    <object>
        <name>A</name>
        <pose>Unspecified</pose>
        <truncated>0</truncated>
        <difficult>0</difficult>
        <bndbox>
            <xmin>143</xmin>
            <ymin>280</ymin>
            <xmax>169</xmax>
            <ymax>324</ymax>
        </bndbox>
    </object>
    <object>
        <name>A</name>
        <pose>Unspecified</pose>
        <truncated>0</truncated>
        <difficult>0</difficult>
        <bndbox>
            <xmin>169</xmin>
            <ymin>280</ymin>
            <xmax>195</xmax>
            <ymax>324</ymax>
        </bndbox>
    </object>
    <object>
        <name>A</name>
        <pose>Unspecified</pose>
        <truncated>0</truncated>
        <difficult>0</difficult>
        <bndbox>
            <xmin>220</xmin>
            <ymin>280</ymin>
            <xmax>241</xmax>
            <ymax>324</ymax>
        </bndbox>
    </object>
    <object>
        <name>B</name>
        <pose>Unspecified</pose>
        <truncated>0</truncated>
        <difficult>0</difficult>
        <bndbox>
            <xmin>206</xmin>
            <ymin>396</ymin>
            <xmax>229</xmax>
            <ymax>431</ymax>
        </bndbox>
    </object>
    <object>
        <name>B</name>
        <pose>Unspecified</pose>
        <truncated>0</truncated>
        <difficult>0</difficult>
        <bndbox>
            <xmin>230</xmin>
            <ymin>396</ymin>
            <xmax>260</xmax>
            <ymax>428</ymax>
        </bndbox>
    </object>
    <object>
        <name>B</name>
        <pose>Unspecified</pose>
        <truncated>0</truncated>
        <difficult>0</difficult>
        <bndbox>
            <xmin>261</xmin>
            <ymin>391</ymin>
            <xmax>285</xmax>
            <ymax>428</ymax>
        </bndbox>
    </object>
</annotation>
Erwin Bolwidt
  • 30,799
  • 15
  • 56
  • 79
  • You ask "Is there a way to do this using notepad++ or python?" - why did you label your question with "Java" if you're not interested in answers for Java? And what about the language that is meant for XML transformation, XSLT? – Erwin Bolwidt Jul 02 '19 at 07:56
  • Look here. https://stackoverflow.com/questions/56795764/python-scale-down-numbers-in-xml-file/56797837#56797837 This can work for you as well. – balderman Jul 02 '19 at 09:18

0 Answers0