自己整理的红外无人机数据集(voc格式)

原始数据来源于这个网站:A dataset for infrared image dim-small aircraft target detection and tracking under ground / air background自己整理的红外无人机数据集(voc格式)_第1张图片

由于网站上数据集标注是点的格式而且是txt文本,不是框标注,所以自己重新整理一下给变成通用矩形框标注的xml格式;

由于时间原因,只整理了data1 data3 data4的,共726张图片和对应xml标注;

可视化矩形框如下所示:

自己整理的红外无人机数据集(voc格式)_第2张图片自己整理的红外无人机数据集(voc格式)_第3张图片

 

 自己整理的红外无人机数据集(voc格式)_第4张图片

 将原本数据集标注转变为3*3的标记框并转化为xml格式的代码如下:

代码来源博客:【数据集处理三】地_空背景下红外图像弱小飞机目标检测跟踪数据集标签格式转换_爱学习的大志的博客-CSDN博客

import os
import csv
channel = 1
#空标签
 
def Annotations0_write():
 
    rename = str(index)
    # print (rename)#打印文件名
    with open(os.path.join(foldername, rename + '.xml'), 'w') as f:
        f.write(f"""
    {foldername}
    {rename}.bmp
    D:/Research direction/data set/foldername/rename.bmp
	
		Unknown
	
    
        {256}
        {256}
        {channel}
    
    0\n""")
        f.write("")
 
###############################################
#一个标签
def Annotations1_write(xmid1,ymid1):
 
    rename = str(index)
    # print (rename)#打印文件名
    with open(os.path.join(foldername, rename + '.xml'), 'w') as f:
        f.write(f"""
    {foldername}
    {rename}.bmp
     D:/Research direction/data set/foldername/rename.bmp
	
		Unknown
	
    
        {256}
        {256}
        {channel}
    
    0\n""")
        f.write(f"""    
            drone
            Unspecified
            0
            0
            
                  {float(xmid1)-3.5} //这里将点变为7*7的框,如果想变成10*10的框,把这里的3.5和下面的3.5改为5即可,以此类推
                  {float(ymid1)-3.5}
                  {float(xmid1)+3.5}
                  {float(ymid1)+3.5}
            
        \n""")
        f.write("")
 
#两个标签
def Annotations2_write(xmid1,ymid1,xmid2,ymid2):
 
    rename = str(index)
    # print (rename)#打印文件名
    with open(os.path.join(foldername, rename + '.xml'), 'w') as f:
        f.write(f"""
    {foldername}
    {rename}.bmp
     D:/Research direction/data set/foldername/rename.bmp
	
		Unknown
	
    
        {256}
        {256}
        {channel}
    
    0\n""")
        f.write(f"""    
            drone
            Unspecified
            0
            0
            
                    {float(xmid1) - 3.5}
                    {float(ymid1) - 3.5}
                    {float(xmid1) + 3.5}
                    {float(ymid1) + 3.5}
            
        
        
             drone
             Unspecified
             0
             0
             
                  {float(xmid2) - 3.5}
                  {float(ymid2) - 3.5}
                  {float(xmid2) + 3.5}
                  {float(ymid2) + 3.5}
              
        \n""")
        f.write("")
 
#读取第i+2行(i=0,表示从第二行开始读)
def read(index):
    for line in lines[index:index + 1:]:
        a = line.split()
        objnum = int(a[1])
        # print(line)
 
        if objnum == 1:
            xmid1 = a[3]
            ymid1 = a[4]
            Annotations1_write(xmid1,ymid1)
        elif objnum == 0:
            Annotations0_write()
        elif objnum == 2:
            xmid1 = a[3]
            ymid1 = a[4]
            xmid2 = a[6]
            ymid2 = a[7]
            Annotations2_write(xmid1,ymid1,xmid2,ymid2)
 
        else:
            print('出错了')
 
 
 
#########
with open ('data22.txt') as data:
# filename =  'data1.txt'
# data =open (filename)
  folder=data.readline() #读取第一行
  folder1=folder.split() #看做字符串
  foldername=folder1[1]  #文件夹名称
  num=int(folder1[2])#帧数
#print (foldername)
  path = foldername
  # print(num)
# 创建文件夹
  if not os.path.exists(path):
      os.mkdir(path)
 
  index=0
  a=folder1#给一个a原始值
  #外面一个while循环
  lines = data.readlines()
  while index != num:
 
     # if index != num:
     read(index)
     index = index + 1
 

 我整理好的数据集:私信我分享给你

你可能感兴趣的:(深度学习,python基础,python,目标检测)