如何反归一化坐标?

我正在为计算机视觉应用注释数据集。我有一个以xml文件形式存储的归一化坐标(xmin, ymin, xmax, ymax)。

完整的xml文件看起来像这样:

<annotation>    <folder>image</folder>    <filename>100_icdar13.png</filename>    <path>/Users/image/100_icdar13.png</path>    <source>        <database>Unknown</database>    </source>    <size>        <width>816</width>        <height>608</height>        <depth>3</depth>    </size>    <segmented>0</segmented>    <object>        <name>text</name>        <pose>Unspecified</pose>        <truncated>0</truncated>        <difficult>0</difficult>        <bndbox>            <xmin>192</xmin>            <ymin>157</ymin>            <xmax>530</xmax>            <ymax>223</ymax>        </bndbox>    </object>    <object>        <name>text</name>        <pose>Unspecified</pose>        <truncated>0</truncated>        <difficult>0</difficult>        <bndbox>            <xmin>561</xmin>            <ymin>159</ymin>            <xmax>645</xmax>            <ymax>219</ymax>        </bndbox>    </object>    <object>        <name>text</name>        <pose>Unspecified</pose>        <truncated>0</truncated>        <difficult>0</difficult>        <bndbox>            <xmin>74</xmin>            <ymin>247</ymin>            <xmax>465</xmax>            <ymax>311</ymax>        </bndbox>    </object>    <object>        <name>text</name>        <pose>Unspecified</pose>        <truncated>0</truncated>        <difficult>0</difficult>        <bndbox>            <xmin>493</xmin>            <ymin>255</ymin>            <xmax>625</xmax>            <ymax>305</ymax>        </bndbox>    </object>    <object>        <name>text</name>        <pose>Unspecified</pose>        <truncated>0</truncated>        <difficult>0</difficult>        <bndbox>            <xmin>85</xmin>            <ymin>339</ymin>            <xmax>496</xmax>            <ymax>400</ymax>        </bndbox>    </object></annotation>

我想反归一化这个数据集,并以以下格式导出所有框:

x1, y1, x2, y2, x3, y3, x4, y4, text

我该怎么做,有什么算法可以实现这个目标?


回答:

您可以使用ElementTree来解析XML并提取坐标:

import xml.etree.ElementTree as ETfrom xml.etree.ElementTree import Elementxml_raw = '''<annotation>    ...    <object>        <name>text</name>        <pose>Unspecified</pose>        <truncated>0</truncated>        <difficult>0</difficult>        <bndbox>            <xmin>192</xmin>            <ymin>157</ymin>            <xmax>530</xmax>            <ymax>223</ymax>        </bndbox>    </object>    <object>        ...    </object>    ...</annotation>'''if __name__ == '__main__':    root: Element = ET.fromstring(xml_raw)    for obj in root.findall('object'):        bndbox: Element = obj.find('bndbox')        name = obj.find('name').text        xmin, xmax, ymin, ymax = [int(bndbox.find(x).text) for x in ['xmin', 'xmax', 'ymin', 'ymax']]        coords = [(x, y) for x in [xmin, xmax] for y in [ymin, ymax]]        print(name, coords)

输出结果如下:

text [(192, 157), (192, 223), (530, 157), (530, 223)]text [(561, 159), (561, 219), (645, 159), (645, 219)]text [(74, 247), (74, 311), (465, 247), (465, 311)]text [(493, 255), (493, 305), (625, 255), (625, 305)]text [(85, 339), (85, 400), (496, 339), (496, 400)]

Related Posts

使用LSTM在Python中预测未来值

这段代码可以预测指定股票的当前日期之前的值,但不能预测…

如何在gensim的word2vec模型中查找双词组的相似性

我有一个word2vec模型,假设我使用的是googl…

dask_xgboost.predict 可以工作但无法显示 – 数据必须是一维的

我试图使用 XGBoost 创建模型。 看起来我成功地…

ML Tuning – Cross Validation in Spark

我在https://spark.apache.org/…

如何在React JS中使用fetch从REST API获取预测

我正在开发一个应用程序,其中Flask REST AP…

如何分析ML.NET中多类分类预测得分数组?

我在ML.NET中创建了一个多类分类项目。该项目可以对…

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注