当前位置: 首页 > news >正文

宁海建设局网站wordpress 字段键

宁海建设局网站,wordpress 字段键,外贸 wordpress英文,wordpress移动端模板目标检测是计算机视觉中的基础任务#xff0c;可以让机器在图像中识别和定位物体。为了高效地标注和存储目标检测数据#xff0c;我们使用了各种不同的数据格式。其中一种常用的格式是XML结构#xff0c;通常用于VOC数据集格式。在本文中#xff0c;我们将探讨一个Python脚…目标检测是计算机视觉中的基础任务可以让机器在图像中识别和定位物体。为了高效地标注和存储目标检测数据我们使用了各种不同的数据格式。其中一种常用的格式是XML结构通常用于VOC数据集格式。在本文中我们将探讨一个Python脚本它可以将目标检测标注从特定的文本文件格式转换为XML格式。 问题描述 假设您有一个图像数据集同时还有相应的文本文件其中包含目标检测的标注信息。每个文本文件都提供了有关图像中存在的物体的信息。例如在每个文本文件中每行可能包含物体类别、边界框坐标等信息。然而您希望将这些标注信息转换为XML格式以便更好地组织和管理数据。 Python脚本实现 以下是一个使用Python编写的脚本用于将目标检测标注从文本格式转换为XML格式 # 导入所需库 import os import cv2 import shutil from xml.dom.minidom import Document# 定义物体类别 cls_names [人, 狗]def makexml(picPath, txtPath, xmlPath):# 删除已有的XML保存路径并创建新的路径if os.path.exists(xmlPath):shutil.rmtree(xmlPath)os.makedirs(xmlPath)# 获取图片文件列表files os.listdir(picPath)# 遍历每个图片文件for i, name in enumerate(files):ss os.path.join(picPath, name)print(ss)img cv2.imread(ss)Pheight, Pwidth, Pdepth img.shape# 创建XML文档对象xmlBuilder Document()annotation xmlBuilder.createElement(annotation) # 创建annotation标签xmlBuilder.appendChild(annotation)# 添加folder标签folder xmlBuilder.createElement(folder)folderContent xmlBuilder.createTextNode(VOC2007)folder.appendChild(folderContent)annotation.appendChild(folder)# 添加filename标签filename xmlBuilder.createElement(filename)filenameContent xmlBuilder.createTextNode(name)filename.appendChild(filenameContent)annotation.appendChild(filename)# 添加size标签size xmlBuilder.createElement(size)width xmlBuilder.createElement(width)widthContent xmlBuilder.createTextNode(str(Pwidth))width.appendChild(widthContent)size.appendChild(width)height xmlBuilder.createElement(height)heightContent xmlBuilder.createTextNode(str(Pheight))height.appendChild(heightContent)size.appendChild(height)depth xmlBuilder.createElement(depth)depthContent xmlBuilder.createTextNode(str(Pdepth))depth.appendChild(depthContent)size.appendChild(depth)annotation.appendChild(size)# 读取对应的文本文件txt os.path.join(txtPath, name[0:-3] txt)if not os.path.exists(txt):# 若文本文件不存在则直接保存XML文件并处理下一张图片print(txt)f open(os.path.join(xmlPath, name[0:-4] .xml), w, encodingutf-8)xmlBuilder.writexml(f, indent\t, newl\n, addindent\t, encodingutf-8)f.close()continue# 若文本文件存在则读取文本内容并添加相应的标签txtFile open(txt)txtList txtFile.readlines()for i in txtList:oneline i.strip().split( )object xmlBuilder.createElement(object)picname xmlBuilder.createElement(name)nameContent xmlBuilder.createTextNode(cls_names[int(oneline[0])])picname.appendChild(nameContent)object.appendChild(picname)# 添加pose、truncated、difficult等标签# 添加bndbox标签并计算bounding box的坐标# 将以上标签添加至annotation标签下pose xmlBuilder.createElement(pose)poseContent xmlBuilder.createTextNode(Unspecified)pose.appendChild(poseContent)object.appendChild(pose)truncated xmlBuilder.createElement(truncated)truncatedContent xmlBuilder.createTextNode(0)truncated.appendChild(truncatedContent)object.appendChild(truncated)difficult xmlBuilder.createElement(difficult)difficultContent xmlBuilder.createTextNode(0)difficult.appendChild(difficultContent)object.appendChild(difficult)bndbox xmlBuilder.createElement(bndbox)xmin xmlBuilder.createElement(xmin)mathData int(((float(oneline[1])) * Pwidth 1) - (float(oneline[3])) * 0.5 * Pwidth)xminContent xmlBuilder.createTextNode(str(mathData))xmin.appendChild(xminContent)bndbox.appendChild(xmin)ymin xmlBuilder.createElement(ymin)mathData int(((float(oneline[2])) * Pheight 1) - (float(oneline[4])) * 0.5 * Pheight)yminContent xmlBuilder.createTextNode(str(mathData))ymin.appendChild(yminContent)bndbox.appendChild(ymin)xmax xmlBuilder.createElement(xmax)mathData int(((float(oneline[1])) * Pwidth 1) (float(oneline[3])) * 0.5 * Pwidth)xmaxContent xmlBuilder.createTextNode(str(mathData))xmax.appendChild(xmaxContent)bndbox.appendChild(xmax)ymax xmlBuilder.createElement(ymax)mathData int(((float(oneline[2])) * Pheight 1) (float(oneline[4])) * 0.5 * Pheight)ymaxContent xmlBuilder.createTextNode(str(mathData))ymax.appendChild(ymaxContent)bndbox.appendChild(ymax)object.appendChild(bndbox)annotation.appendChild(object)# 保存生成的XML文件f open(os.path.join(xmlPath, name[0:-4] .xml), w, encodingutf-8)xmlBuilder.writexml(f, indent\t, newl\n, addindent\t, encodingutf-8)f.close()# 调用函数进行转换 makexml(../data/images/, ../runs/detect/exp19/labels/, ../data/all/annotations/)结论 通过使用上述Python脚本您可以将yolov5的推理保存的txt从文本格式转换为更为常见的XML格式从而更好地管理和组织您的数据集。转换后的XML格式可以被广泛用于各种目标检测算法和数据处理工具中为计算机视觉研究和应用提供便利。
http://www.huolong8.cn/news/311855/

相关文章:

  • 电商网站功能全网推广图片
  • 有没有做公司网站的那个网站可以免费建站
  • 小学文化学网站开发苏州相城区最新通告
  • 苏州网站建设软件做任务什么网站
  • 国外的旅游网站做的如何xin网站ftp上传
  • 潮州木雕世家木雕网站建设案例分享wordpress鏁版嵁
  • 网站非法篡改兰州网站建设慕枫
  • 泰安网站建设入门推荐互联网推广营销隐迅推知名
  • 网站建设教程txt织梦dedecms网站简略标题shorttitle的使用方法
  • 长寿网站建设国外WordPress主题购买
  • 三门峡市建设局官方网站网站icp备案系统下载
  • 网站制作可以wordpress标签多重筛选
  • 自建网站优缺点织带东莞网站建设技术支持
  • 中国做的最好的网站商业运营是做什么的
  • 企业建站系统免费软件设计说明书模板
  • 外文网站建站网络域名备案流程
  • wordpress编辑网站的链接是中文建站行业导航网站
  • 建站报价贴吧推广400一个月
  • 做暖dnf动态ufo网站客户管理系统哪个好用
  • 成华区微信网站建设推上百度首页
  • 河北特定网站建设推荐网站内页标题
  • 福建省工程建设信息官方网站wordpress 漫画站
  • 网站导航栏怎么做简单wordpress 返回顶部代码
  • 旺旺号查询网站怎么做网站登陆模板
  • 微信官方网站是多少钱莱芜招聘信息最新招聘2022
  • 找网站建设公司信用网站建设情况
  • 网站建设的意义和目的蓝色的网站登录页面模版
  • 购物网站开发的意义石家庄展为网络科技有限公司
  • vs2013 网站开发163网易邮箱
  • 精诚时代 网站谁做的签名设计免费版