前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >对nwpu数据集的宽度和高度进行修改

对nwpu数据集的宽度和高度进行修改

作者头像
狼啸风云
修改2022-09-04 20:58:33
1.6K0
修改2022-09-04 20:58:33
举报

NWPU VHR-10目标检测数据集中的ground truth,统一为256x256有时候在使用的时候很不方便,因此需要将宽和高指定为真实的宽和高,python的源代码如下,

代码语言:javascript
复制
from xml.etree.ElementTree import ElementTree,Element
import os
import cv2

def read_xml(in_path):
    tree = ElementTree()
    tree.parse(in_path)
    return tree


if __name__ == '__main__':
  source_pic_root_path = '/home/user8/Desktop/Calculate the size of target/nwpu/JPEGImages/'
  source_xml_root_path = '/home/user8/Desktop/Calculate the size of target/nwpu/Annotations/'
  for parent, _, files in os.walk(source_pic_root_path):
    for file in files:
        pic_path = os.path.join(parent, file)
        img = cv2.imread(pic_path)
        size = img.shape
        xml_path = os.path.join(source_xml_root_path, file[:-4] + '.xml')
        tree = read_xml(xml_path)
        root = tree.getroot()
        for h_node in root.iter('height'):
            height = str(size[0])
            h_node.text = height

        for w_node in root.iter('width'):
            width = str(size[1])
            w_node.text = width
        tree.write(xml_path)
本文参与 腾讯云自媒体分享计划,分享自作者个人站点/博客。
原始发表:2019年05月21日,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体分享计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档