一、Dota数据集准备
安装roLabelImg:http://github.com/cgvict/roLabelImg
下载后解压到没有中文的路径下
打开cmd,创建虚拟环境
conda create -n roLabelImg python=3.8.5
conda activate roLabelImg
安装需要的库
pip install PyQt5
pip install lxml
切换到第一步下载的源码目录,(即有roLabelImg.py的路径下)然后执行代码
pyrcc5 -o resources.py resources.qrc
运行python roLabelImg.py
即可打开标注界面,开始打标签前,改变图片大小,这里缩小为原图片规格的0.5倍,并将所有图片转换成.png格式(必须为png格式)
切换到对应路径下,运行python change2png.py
"author:youngkun date:20180615 function:change the size of pictures in one folder"
import cv2
import os
source_path="./DOTA_demo/before/" #源文件路径
target_path="./DOTA_demo/images/" #输出目标文件路径
if not os.path.exists(target_path):
os.makedirs(target_path)
image_list=os.listdir(source_path) #获得文件名
i=0
for file in image_list:
i=i+1
if file.endswith('.png'):
image_source=cv2.imread(source_path+file)#读取图片
image = cv2.resize(image_source, (0, 0),fx=0.5, fy=0.5, interpolation=cv2.INTER_NEAREST)#修改尺寸
cv2.imwrite(target_path+str(i)+".png",image) #重命名并且保存
print("批量处理完成")
打标签,全部打完标签后,将打标签生成的xml文件转换成txt文件,运行python roxml_to_dota.py
import os
import xml.etree.ElementTree as ET
import math
import cv2
import numpy as np
def edit_xml(xml_file):
if ".xml" not in xml_file:
return