【发布时间】:2021-05-13 17:00:59
【问题描述】:
我正在使用 labelImg 在图像行上绘制一个矩形。这给了我 xml 文件。借助此 xml 如何从图像表中提取该文本。为了提取文本,我使用了水平和垂直 ine 检测,但没有得到好的结果。现在我正在使用 labelImg 它给了我想要提取的文本的点,但我不知道如何应用这个方法。请告诉我该怎么做?
我的 xml 文件:
<annotation>
<folder>Test Images</folder>
<filename>FreKa.jpg</filename>
<path>/home/sumit/Desktop/office_works/Fusion_Code/BIS_Final/Test Images/FreKa.jpg</path>
<source>
<database>Unknown</database>
</source>
<size>
<width>679</width>
<height>341</height>
<depth>3</depth>
</size>
<segmented>0</segmented>
<object>
<name>Contact Type</name>
<pose>Unspecified</pose>
<truncated>1</truncated>
<difficult>0</difficult>
<bndbox>
<xmin>1</xmin>
<ymin>100</ymin>
<xmax>678</xmax>
<ymax>157</ymax>
</bndbox>
</object>
</annotation>
我的输入图像:
如何借助 xml 文件从表格中提取合同类型? 谢谢...
【问题讨论】:
-
你想获取 xml 中的哪个值?您可以为此在模块
lxml中使用xpath()- 即。'//annotation/object/bndbox/xmin' -
或者你可以使用正则表达式 -
re.findall('<xmin>(\d+)</xmin>', text) -
借助 xml 我想提取图像的第 3 行。
-
你能告诉我如何使用xml获取对象名称(例如合同,合同描述等)吗?
-
如果你的意思是
<object>,那么//annotation/object应该给你所有<object>的列表,然后你可以使用len(list_with_objects)。或者您可以对//annotation/object/name执行相同操作 - 它应该为您提供所有名称的列表,您可以使用len(list_with_names)
标签: python opencv python-tesseract image-preprocessing labelimg