由于目前的imglabel画出来框都是voc类型的xml文件:

<annotation><folder>rotate_jueyuanzi_zip</folder><filename>0004.jpg</filename><path>D:\Desktop\rotate\dataset\rotate_jueyuanzi_zip\0004.jpg</path><source><database>Unknown</database></source><size><width>1037</width><height>778</height><depth>3</depth></size><segmented>0</segmented><object><name>comp</name><pose>Unspecified</pose><truncated>0</truncated><difficult>0</difficult><robndbox><cx>453.9988</cx><cy>159.4623</cy><w>44.3132</w><h>106.04</h><angle>4.963185</angle></robndbox><extra/></object><object><name>comp</name><pose>Unspecified</pose><truncated>0</truncated><difficult>0</difficult><robndbox><cx>548.4988</cx><cy>159.4623</cy><w>35.867</w><h>98.7147</h><angle>4.963185</angle></robndbox><extra/></object><object><name>comp</name><pose>Unspecified</pose><truncated>0</truncated><difficult>0</difficult><robndbox><cx>486.0786</cx><cy>304.3616</cy><w>45.8548</w><h>99.6275</h><angle>0.81</angle></robndbox><extra/></object><object><name>comp</name><pose>Unspecified</pose><truncated>0</truncated><difficult>0</difficult><robndbox><cx>585.526</cx><cy>326.5931</cy><w>46.7375</w><h>102.784</h><angle>0.81</angle></robndbox><extra/></object>
</annotation>

想要转换成为DOTA类型的数据:

513.9 363.3 622.1 466.1 578.5 511.9 470.3 409.1 comp 0
280.0 198.9 411.9 159.6 427.1 210.7 295.3 250.1 comp 0
404.4 198.2 538.1 165.5 550.7 217.4 417.1 250.1 comp 0
373.9 332.3 482.1 435.1 438.5 480.9 330.3 378.1 comp 0

转换代码:

import os
import xml.etree.ElementTree as ET
import mathdef voc_to_dota(xml_path, xml_name):txt_name = xml_name[:-4] + '.txt'txt_path = xml_path + '/txt_label'if not os.path.exists(txt_path):os.makedirs(txt_path)txt_file = os.path.join(txt_path, txt_name)file_path = os.path.join(xml_path, file_list[i])tree = ET.parse(os.path.join(file_path))root = tree.getroot()# print(root[6][0].text)with open(txt_file, "w+", encoding='UTF-8') as out_file:# out_file.write('imagesource:null' + '\n' + 'gsd:null' + '\n')for obj in root.findall('object'):name = obj.find('name').textdifficult = obj.find('difficult').text# print(name, difficult)robndbox = obj.find('robndbox')cx = float(robndbox.find('cx').text)cy = float(robndbox.find('cy').text)w = float(robndbox.find('w').text)h = float(robndbox.find('h').text)angle = float(robndbox.find('angle').text)# print(cx, cy, w, h, angle)p0x, p0y = rotatePoint(cx, cy, cx - w / 2, cy - h / 2, -angle)p1x, p1y = rotatePoint(cx, cy, cx + w / 2, cy - h / 2, -angle)p2x, p2y = rotatePoint(cx, cy, cx + w / 2, cy + h / 2, -angle)p3x, p3y = rotatePoint(cx, cy, cx - w / 2, cy + h / 2, -angle)data = str(p0x) + " " + str(p0y) + " " + str(p1x) + " " + str(p1y) + " " + \str(p2x) + " " + str(p2y) + " " + str(p3x) + " " + str(p3y) + " "data = data + name + " " + difficult + "\n"out_file.write(data)# 转换成四点坐标
def rotatePoint(xc, yc, xp, yp, theta):xoff = xp - xcyoff = yp - yccosTheta = math.cos(theta)sinTheta = math.sin(theta)pResx = cosTheta * xoff + sinTheta * yoffpResy = - sinTheta * xoff + cosTheta * yoff# pRes = (xc + pResx, yc + pResy)# 保留一位小数点return float(format(xc + pResx, '.1f')), float(format(yc + pResy, '.1f'))# return xc + pResx, yc + pResyif __name__ == '__main__':root_path = '../annotation'file_list = os.listdir(root_path)for i in range(0, len(file_list)):if ('.xml' in file_list[i]) or ('.XML' in file_list[i]):voc_to_dota(root_path, file_list[i])print('----------------------------------------{}{}----------------------------------------'.format(file_list[i], ' has Done!'))else:print(file_list[i] + ' is not xml file')

【AI目标检测】VOC格式数据集转换为DOTA类型数据集相关推荐

  1. 【自制数据集自动标注】yolo目标检测 voc格式 单调无遮挡背景单个物体自制数据集自动标注

    垃圾分类目标检测数据集准备 数据集背景: 参加全国大学生工程训练综合能力竞赛智能生活垃圾分类赛道时深感采集制作数据集过分彰显"有多少人工,就有多少智能"的惨痛,为了不辛苦麻烦身边小 ...

  2. 【机器学习】 - 目标检测 - VOC格式数据集介绍与自己制作

    一.VOC数据集 PASCAL VOC 挑战赛主要有 Object Classification .Object Detection.Object Segmentation.Human Layout. ...

  3. python实现目标检测voc格式标签数据增强

    文章目录 前言 一.显示图片(可关闭) 二.创建图像变换的类 1.增强数据代码 2.图像加噪声 3.调整图像亮度 4.添加黑色像素块 5.旋转图像 6.图像裁剪 7.平移图像 8.图像镜像 9.图像随 ...

  4. 深度学习目标检测:YOLOv5实现车辆检测(含车辆检测数据集+训练代码)

    深度学习目标检测:YOLOv5实现车辆检测(含车辆检测数据集+训练代码) 目录 深度学习目标检测:YOLOv5实现车辆检测(含车辆检测数据集+训练代码) 1. 前言 2. 车辆检测数据集说明 (1)车 ...

  5. 何恺明团队最新研究:3D目标检测新框架VoteNet,两大数据集刷新最高精度

    [导读]FAIR何恺明等人团队提出3D目标检测新框架VoteNet,直接处理原始数据,不依赖任何2D检测器.该模型设计简单,模型紧凑,效率高,在两大真实3D扫描数据集上实现了最先进的3D检测精度. 当 ...

  6. 目标检测voc转coco改良版

    <目标检测voc转coco改良版>   我训练目标检测的一般流程:1.labelme标注:2.labelme转voc,对img和voc进行数据增广:3.voc转coco:4.计算图片的RG ...

  7. Citypersons数据集转VOC标准格式(YOLO 目标检测txt格式)

    CItyscapes城市数据集包含一组不同的立体视频序列中记录来自50个不同城市的街景,高质量的进行像素级的注释.数据集下载地址(需要申请注册,通过申请才能下载)[https://www.citysc ...

  8. 目标检测-VOC数据集txt文件制作方法

    个人微信公众号:AI研习图书馆,欢迎关注~ 深度学习知识及资源分享,学习交流,共同进步~ VOC数据集中txt文件的制作方法 1.引言 本文介绍两种VOC数据集txt文件生成方法,一种是Python实 ...

  9. 目标检测simple Faster R-CNN训练自己的数据集

    一.复现 刚开始接触目标检测,自己动手复现的第一个开源项目是github上chenyuntc的simple faster rcnn.历经千辛万苦最后貌似因为服务器显卡内存不够,在训练时一直出现一个错误 ...

最新文章

  1. Go 知识点(10) — 子协程能否使用主协程变量
  2. java restful项目打包_听说你在接私活? 一个助你效率翻倍的项目工具!!
  3. 利用php比较精确的统计在线人数的办法
  4. Bit-Z携手Bit-MY落户马来西亚 已获得经营牌照
  5. amoeba for mysql配置_Amoeba for mysql 读写分离
  6. 继承extends、super、this、方法重写overiding、final、代码块_DAY08
  7. java mapper.readtree_java - 杰克逊的readValue和readTree:何时使用哪个? - 堆栈内存溢出...
  8. 华为畅享20 Pro测评:5G双模六频段+90Hz刷新率屏幕
  9. 程序员35岁辞职后都做了什么工作三位过来人透露了实情,引热议
  10. windows桌面的“我的电脑”“IE”等消失的解决方法
  11. html获取url后面的参数_【python量化】用Python获取基金历史净值数据
  12. Excise1_Exception
  13. 电视剧神话剧情介绍-电视剧神话剧情简介
  14. OpenStack Days China:华云数据CTO郑军分享OpenStack创新实践
  15. 几个分形的matlab实现1,几个分形的matlab实现
  16. 搭建本地Spring Initializr服务(2020/4/17)
  17. 打开机顶盒显示e16服务器加扰,机顶盒常见错误代码说明和解决方法
  18. 瞬间几千次的重复提交,我用 SpringBoot+Redis 扛住了
  19. 安装python包时报‘HTMLParser‘ object has no attribute ‘unescape‘
  20. python文件有关的操作

热门文章

  1. BIM时代的来临,建筑设计院的未来将何去何从?
  2. 100天,离开学校的日子......
  3. Lucene-4.8.1+paoding-analysis菜鸟试验:中文索引和查询
  4. 外部h5跳转小程序页面传递参数
  5. flairNLP / flair
  6. sqllite的基本使用封装
  7. 半同步/半异步模式和领导者/追随者模式
  8. 无参构造方法和有参构造方法的调用
  9. automake 的使用(一)
  10. Gephi--网络可视化分析