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

相关文章

python处理带有时区的日期和时间数据

《python处理带有时区的日期和时间数据》这篇文章主要为大家详细介绍了如何在Python中使用pytz库处理时区信息,包括获取当前UTC时间,转换为特定时区等,有需要的小伙伴可以参考一下... 目录时区基本信息python datetime使用timezonepandas处理时区数据知识延展时区基本信息

Qt实现网络数据解析的方法总结

《Qt实现网络数据解析的方法总结》在Qt中解析网络数据通常涉及接收原始字节流,并将其转换为有意义的应用层数据,这篇文章为大家介绍了详细步骤和示例,感兴趣的小伙伴可以了解下... 目录1. 网络数据接收2. 缓冲区管理(处理粘包/拆包)3. 常见数据格式解析3.1 jsON解析3.2 XML解析3.3 自定义

SpringMVC 通过ajax 前后端数据交互的实现方法

《SpringMVC通过ajax前后端数据交互的实现方法》:本文主要介绍SpringMVC通过ajax前后端数据交互的实现方法,本文给大家介绍的非常详细,对大家的学习或工作具有一定的参考借鉴价... 在前端的开发过程中,经常在html页面通过AJAX进行前后端数据的交互,SpringMVC的controll

Pandas统计每行数据中的空值的方法示例

《Pandas统计每行数据中的空值的方法示例》处理缺失数据(NaN值)是一个非常常见的问题,本文主要介绍了Pandas统计每行数据中的空值的方法示例,具有一定的参考价值,感兴趣的可以了解一下... 目录什么是空值?为什么要统计空值?准备工作创建示例数据统计每行空值数量进一步分析www.chinasem.cn处

如何使用 Python 读取 Excel 数据

《如何使用Python读取Excel数据》:本文主要介绍使用Python读取Excel数据的详细教程,通过pandas和openpyxl,你可以轻松读取Excel文件,并进行各种数据处理操... 目录使用 python 读取 Excel 数据的详细教程1. 安装必要的依赖2. 读取 Excel 文件3. 读

Spring 请求之传递 JSON 数据的操作方法

《Spring请求之传递JSON数据的操作方法》JSON就是一种数据格式,有自己的格式和语法,使用文本表示一个对象或数组的信息,因此JSON本质是字符串,主要负责在不同的语言中数据传递和交换,这... 目录jsON 概念JSON 语法JSON 的语法JSON 的两种结构JSON 字符串和 Java 对象互转

C++如何通过Qt反射机制实现数据类序列化

《C++如何通过Qt反射机制实现数据类序列化》在C++工程中经常需要使用数据类,并对数据类进行存储、打印、调试等操作,所以本文就来聊聊C++如何通过Qt反射机制实现数据类序列化吧... 目录设计预期设计思路代码实现使用方法在 C++ 工程中经常需要使用数据类,并对数据类进行存储、打印、调试等操作。由于数据类

SpringBoot使用GZIP压缩反回数据问题

《SpringBoot使用GZIP压缩反回数据问题》:本文主要介绍SpringBoot使用GZIP压缩反回数据问题,具有很好的参考价值,希望对大家有所帮助,如有错误或未考虑完全的地方,望不吝赐教... 目录SpringBoot使用GZIP压缩反回数据1、初识gzip2、gzip是什么,可以干什么?3、Spr

SpringBoot集成Milvus实现数据增删改查功能

《SpringBoot集成Milvus实现数据增删改查功能》milvus支持的语言比较多,支持python,Java,Go,node等开发语言,本文主要介绍如何使用Java语言,采用springboo... 目录1、Milvus基本概念2、添加maven依赖3、配置yml文件4、创建MilvusClient

SpringValidation数据校验之约束注解与分组校验方式

《SpringValidation数据校验之约束注解与分组校验方式》本文将深入探讨SpringValidation的核心功能,帮助开发者掌握约束注解的使用技巧和分组校验的高级应用,从而构建更加健壮和可... 目录引言一、Spring Validation基础架构1.1 jsR-380标准与Spring整合1