目标检测数据集的xml标签中坐标形式转换

目标检测 发现以前几个数据集中的xml标签里面的格式是:

<?xml version='1.0' encoding='UTF-8'?>
<document filename="cTDaR_t00000.jpg">
  <table>
    <Coords points="1722,698 3961,698 3961,3247 1722,3247"/>
    <cell start-row="0" end-row="5" start-col="0" end-col="1">
      <Coords points="1722,698 1718,764 1715,829 1714,868 1712,920 1710,965 1709,1007 1793,1007 2238,1012 2239,971 2239,927 2240,874 2240,834 2241,769 2248,704 1804,698"/>
    </cell>

其中坐标在 Coords points="1722,698 3961,698 3961,3247 1722,3247"

而我最近用的几个数据集xml标签里储存坐标的格式是

<object>
    <name>box</name>
    <difficult>0</difficult>
    <bndbox>
      <xmin>45.0</xmin>
      <ymin>172.0</ymin>
      <xmax>92.0</xmax>
      <ymax>304.0</ymax>
      <x1>45.0</x1>
      <y1>172.0</y1>
      <x2>92.0</x2>
      <y2>172.0</y2>
      <x3>92.0</x3>
      <y3>304.0</y3>
      <x4>45.0</x4>
      <y4>304.0</y4>

有没有方法能将旧的标签格式转换成新的标签格式?

新建一张空白图片,将旧的坐标,用opencv的fillpoly接口将旧坐标区域填满,然后用findcontour找到该区域的外接矩形,就是你想要的新的坐标格式了。如果觉得有用,请点击采纳