DOTA数据集转VOC数据集,模仿DIOR数据集类型

2023-12-12 02:10

本文主要是介绍DOTA数据集转VOC数据集,模仿DIOR数据集类型,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

DOTA文本数据集转XML格式

说明:由于本人比较喜欢DIOR数据集格式,所以仿照DIOR数据集转的相同格式

DOTA数据集下载链接:https://pan.baidu.com/s/1lksAYbogYT3OjTBzNuQuNA
提取码:7vwv

DOIR数据集下载链接:
https://pan.baidu.com/s/1QPALicrLHqhblnGu_EBjlw
提取码:jcpg

代码如下(改了网上的代码,此处贴上链接)

import os
from xml.dom.minidom import Document
from xml.dom.minidom import parse
import xml.dom.minidom
import numpy as np
import csv
import cv2
import stringdef WriterXMLFiles(filename,img_name, path, box_list, label_list, w, h, d):# dict_box[filename]=json_dict[filename]doc = xml.dom.minidom.Document()root = doc.createElement('annotation')doc.appendChild(root)# foldername = doc.createElement("folder")# foldername.appendChild(doc.createTextNode("JPEGImages"))# root.appendChild(foldername)nodeFilename = doc.createElement('filename')nodeFilename.appendChild(doc.createTextNode(img_name))root.appendChild(nodeFilename)# pathname = doc.createElement("path")# pathname.appendChild(doc.createTextNode("xxxx"))# root.appendChild(pathname)sourcename=doc.createElement("source")databasename = doc.createElement("database")databasename.appendChild(doc.createTextNode("DOTA"))sourcename.appendChild(databasename)# annotationname = doc.createElement("annotation")# annotationname.appendChild(doc.createTextNode("xxx"))# sourcename.appendChild(annotationname)# imagename = doc.createElement("image")# imagename.appendChild(doc.createTextNode("xxx"))# sourcename.appendChild(imagename)# flickridname = doc.createElement("flickrid")# flickridname.appendChild(doc.createTextNode("0"))# sourcename.appendChild(flickridname)root.appendChild(sourcename)nodesize = doc.createElement('size')nodewidth = doc.createElement('width')nodewidth.appendChild(doc.createTextNode(str(w)))nodesize.appendChild(nodewidth)nodeheight = doc.createElement('height')nodeheight.appendChild(doc.createTextNode(str(h)))nodesize.appendChild(nodeheight)nodedepth = doc.createElement('depth')nodedepth.appendChild(doc.createTextNode(str(d)))nodesize.appendChild(nodedepth)root.appendChild(nodesize)segname = doc.createElement("segmented")segname.appendChild(doc.createTextNode("0"))root.appendChild(segname)for (box, label) in zip(box_list, label_list):nodeobject = doc.createElement('object')nodename = doc.createElement('name')nodename.appendChild(doc.createTextNode(str(label)))nodeobject.appendChild(nodename)nodebndbox = doc.createElement('bndbox')nodex1 = doc.createElement('x1')nodex1.appendChild(doc.createTextNode(str(box[0])))nodebndbox.appendChild(nodex1)nodey1 = doc.createElement('y1')nodey1.appendChild(doc.createTextNode(str(box[1])))nodebndbox.appendChild(nodey1)nodex2 = doc.createElement('x2')nodex2.appendChild(doc.createTextNode(str(box[2])))nodebndbox.appendChild(nodex2)nodey2 = doc.createElement('y2')nodey2.appendChild(doc.createTextNode(str(box[3])))nodebndbox.appendChild(nodey2)nodex3 = doc.createElement('x3')nodex3.appendChild(doc.createTextNode(str(box[4])))nodebndbox.appendChild(nodex3)nodey3 = doc.createElement('y3')nodey3.appendChild(doc.createTextNode(str(box[5])))nodebndbox.appendChild(nodey3)nodex4 = doc.createElement('x4')nodex4.appendChild(doc.createTextNode(str(box[6])))nodebndbox.appendChild(nodex4)nodey4 = doc.createElement('y4')nodey4.appendChild(doc.createTextNode(str(box[7])))nodebndbox.appendChild(nodey4)# ang = doc.createElement('angle')# ang.appendChild(doc.createTextNode(str(angle)))# nodebndbox.appendChild(ang)nodeobject.appendChild(nodebndbox)root.appendChild(nodeobject)fp = open(path + filename, 'w')doc.writexml(fp, indent='\n')fp.close()def load_annoataion(p):'''load annotation from the text file:param p::return:'''text_polys = []text_tags = []if not os.path.exists(p):return np.array(text_polys, dtype=np.float32)with open(p, 'r') as f:for line in f.readlines()[2:]:label = 'text'# strip BOM. \ufeff for python3,  \xef\xbb\bf for python2#line = [i.strip('\ufeff').strip('\xef\xbb\xbf') for i in line]#print(line)x1, y1, x2, y2, x3, y3, x4, y4 ,label= line.split(' ')[0:9]#print(label)text_polys.append([x1, y1, x2, y2, x3, y3, x4, y4])text_tags.append(label)return np.array(text_polys, dtype=np.float), np.array(text_tags, dtype=np.str)txt_path = r'E:/baidudisk/DOTA/train/labelTxt-v1.5/DOTA-v1.5_train/'
xml_path = r'E:/baidudisk/DOTA/train/labelTxt-v1.5-voc/DOTA-v1.5_train/'
img_path = r'E:/baidudisk/DOTA/train/images/images/'
print(os.path.exists(txt_path))
txts = os.listdir(txt_path)
for count, t in enumerate(txts):path = os.path.join(txt_path,t)print(path)# boxes存储的是八个坐标# labels存储的是标签boxes, labels = load_annoataion(os.path.join(txt_path, t))# P0000.xmlxml_name = t.replace('.txt', '.xml')img_name = t.replace('.txt', '.png')# P0000.pngimg = cv2.imread(os.path.join(img_path, img_name))h, w, d = img.shape#print(xml_name, xml_path, boxes, labels, w, h, d)WriterXMLFiles(xml_name,img_name, xml_path, boxes, labels, w, h, d)if count % 1000 == 0:print(count)

说明
1:请务必将自己的文件路径进行修改
2:导包出现如下图横线,感觉也没有影响程序运行
在这里插入图片描述
3:文件转换最终如下图:
在这里插入图片描述

这篇关于DOTA数据集转VOC数据集,模仿DIOR数据集类型的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/482891

相关文章

SpringBoot分段处理List集合多线程批量插入数据方式

《SpringBoot分段处理List集合多线程批量插入数据方式》文章介绍如何处理大数据量List批量插入数据库的优化方案:通过拆分List并分配独立线程处理,结合Spring线程池与异步方法提升效率... 目录项目场景解决方案1.实体类2.Mapper3.spring容器注入线程池bejsan对象4.创建

PHP轻松处理千万行数据的方法详解

《PHP轻松处理千万行数据的方法详解》说到处理大数据集,PHP通常不是第一个想到的语言,但如果你曾经需要处理数百万行数据而不让服务器崩溃或内存耗尽,你就会知道PHP用对了工具有多强大,下面小编就... 目录问题的本质php 中的数据流处理:为什么必不可少生成器:内存高效的迭代方式流量控制:避免系统过载一次性

C#实现千万数据秒级导入的代码

《C#实现千万数据秒级导入的代码》在实际开发中excel导入很常见,现代社会中很容易遇到大数据处理业务,所以本文我就给大家分享一下千万数据秒级导入怎么实现,文中有详细的代码示例供大家参考,需要的朋友可... 目录前言一、数据存储二、处理逻辑优化前代码处理逻辑优化后的代码总结前言在实际开发中excel导入很

MyBatis-plus处理存储json数据过程

《MyBatis-plus处理存储json数据过程》文章介绍MyBatis-Plus3.4.21处理对象与集合的差异:对象可用内置Handler配合autoResultMap,集合需自定义处理器继承F... 目录1、如果是对象2、如果需要转换的是List集合总结对象和集合分两种情况处理,目前我用的MP的版本

Python中Json和其他类型相互转换的实现示例

《Python中Json和其他类型相互转换的实现示例》本文介绍了在Python中使用json模块实现json数据与dict、object之间的高效转换,包括loads(),load(),dumps()... 项目中经常会用到json格式转为object对象、dict字典格式等。在此做个记录,方便后续用到该方

GSON框架下将百度天气JSON数据转JavaBean

《GSON框架下将百度天气JSON数据转JavaBean》这篇文章主要为大家详细介绍了如何在GSON框架下实现将百度天气JSON数据转JavaBean,文中的示例代码讲解详细,感兴趣的小伙伴可以了解下... 目录前言一、百度天气jsON1、请求参数2、返回参数3、属性映射二、GSON属性映射实战1、类对象映

C# LiteDB处理时间序列数据的高性能解决方案

《C#LiteDB处理时间序列数据的高性能解决方案》LiteDB作为.NET生态下的轻量级嵌入式NoSQL数据库,一直是时间序列处理的优选方案,本文将为大家大家简单介绍一下LiteDB处理时间序列数... 目录为什么选择LiteDB处理时间序列数据第一章:LiteDB时间序列数据模型设计1.1 核心设计原则

Java+AI驱动实现PDF文件数据提取与解析

《Java+AI驱动实现PDF文件数据提取与解析》本文将和大家分享一套基于AI的体检报告智能评估方案,详细介绍从PDF上传、内容提取到AI分析、数据存储的全流程自动化实现方法,感兴趣的可以了解下... 目录一、核心流程:从上传到评估的完整链路二、第一步:解析 PDF,提取体检报告内容1. 引入依赖2. 封装

python中的显式声明类型参数使用方式

《python中的显式声明类型参数使用方式》文章探讨了Python3.10+版本中类型注解的使用,指出FastAPI官方示例强调显式声明参数类型,通过|操作符替代Union/Optional,可提升代... 目录背景python函数显式声明的类型汇总基本类型集合类型Optional and Union(py

MySQL中查询和展示LONGBLOB类型数据的技巧总结

《MySQL中查询和展示LONGBLOB类型数据的技巧总结》在MySQL中LONGBLOB是一种二进制大对象(BLOB)数据类型,用于存储大量的二进制数据,:本文主要介绍MySQL中查询和展示LO... 目录前言1. 查询 LONGBLOB 数据的大小2. 查询并展示 LONGBLOB 数据2.1 转换为十