如何在xml文件中的图像上显示边界框

时间:2019-10-15 12:30:59

标签: php 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文件保存标签边界框的位置。现在,上面的代码显示图像和其中存在的标签。我想在图像上得到边界框。有人可以说怎么做。

0 个答案:

没有答案