首页 > 解决方案 > 如何从 xml 文件中显示图像上的边界框

问题描述

我有一个用于图像标签管理的页面。图像的标签取自 xml 文件。

我试过类似的东西:

<?php

if (isset($_POST['img_url'])) {
    $img = $_POST['img_url'];
    ?>
    <div class="container container-flex">
    <div class="left imgappend left-sec">
    <div class="img_text">
    <?php
    $link = $_POST['img_url'];
    $link_array = explode('/',$link);
    $imgpath = end($link_array);
    $ext = substr($imgpath, strrpos($imgpath, "."));
    $imgname= str_replace($ext,'',$imgpath);

    $dire="Annotated Dataset/data/";
    $file = $dire.$imgname.'.xml';
    $xml = simplexml_load_file($file);

    foreach($xml->object as $object){ ?>

    <div class='dynamic_text <?php echo $object->name; ?>' style='display:none;'><?php echo $object->name; ?></div>

    <?php } ?>
    </div>
    <img src="<?php echo "$img"; ?>" id="scale_img">
    </div>
    <div class="right right-sec">
    <div class="input-container">
    <form action="validationxml.php" method="post" id="img_data" name="validationform">
    <span class="right-sec-text">Existing Tags in the image</span>
    <div class="exits_tags">
    <?php
    $link = $_POST['img_url'];
    $link_array = explode('/',$link);
    $imgpath = end($link_array)
    $ext = substr($imgpath, strrpos($imgpath, "."));
    $imgname= str_replace($ext,'',$imgpath);

    $dire="Annotated Dataset/data/";

    $file = $dire.$imgname.'.xml';

    $xml = simplexml_load_file($file);

    foreach($xml->object as $object){ ?>

    <div class='inputtag'>
    <i class='fa fa-trash-o' aria-hidden='true'></i>

            <span><?php echo $object->name; ?></span>

            <input type='hidden' name='tag_name[]' value='<?php echo $object->name; ?>'>

             <input type='hidden' name='xmin[]' value='<?php echo $object->bndbox->xmin; ?>'>

             <input type='hidden' name='ymin[]' value='<?php echo $object->bndbox->ymin; ?>'>

             <input type='hidden' name='xmax[]' value='<?php echo $object->bndbox->xmax; ?>'>

             <input type='hidden' name='ymax[]' value='<?php echo $object->bndbox->ymax; ?>'>
                            </div>
    <?php } ?>
    </div>

上面显示了图像和其中存在的标签。标签是从 xml 文件中获取的。

xml 文件如下所示:

    -<foto>
     <folder>images/fashion/MAN_BACKSTAGE_SHOW_FW18</folder>
     <scenario>Fashion</scenario>
     <filename>MAN_BACKSTAGE_SHOW_FW1833.jpg</filename>
     -<size>
      <width>1620</width>
      <height>1080</height>
      </size>
      -<object>
        <type>highlevel</type>
        <name>Tie</name>
        <created>auto</created>
       -<bndbox>
         <xmin>289</xmin>
         <ymin>0</ymin>
         <xmax>1167</xmax>
         <ymax>1059</ymax>
        </bndbox>
        </fotoinmotion>

xml 文件保存标签边界框的位置。现在,上面的代码显示图像和其中存在的标签。我想获得图像上的边界框。有人可以说怎么做。

标签: phpxml

解决方案


推荐阅读