一、数据集介绍
Vehicle Detection in Aerial Imagery是一个机载图像目标检测的数据集,包括,包含9个类别:‘plane’, ‘boat’, ‘camping car’, ‘car’, ‘pick-up’, ‘tractor’,‘truck’, ‘van’, and the ‘other’。
标注的格式为:
00000000 580.697942 1009.223279 3.012318 554 605 607 558 1004 996 1016 1021 002 1 0
具体的,每一部分含义为:
00000000(图像ID) 580.697942 1009.223279(图像中心坐标) 3.012318(目标角度) 554 605 607 558 1004 996 1016 1021(bbox四个角坐标) 002(类别) 1(是否完全在图中) 0(是否堵塞)
其中,对于分类任务有价值的标注为图像ID,四个角点坐标以及类别。
二、数据集预处理
为了制作目标分类数据集,首先要将对应的目标截取出来。根据图像ID索引到对应图片,通过bbox的坐标在图片中截取除特定目标区域(上图根据标注截取出的目标为):
代码如下:
def LoadPosition(annopath,filename):
f = open(annopath)
pos = []
for lines in f:
a = list(map(float,lines.split()))
if a[0] == float(filename.split('_')[0]):
b = list(map(int,a[4:12]))
cord = [max(0,min(b[0:4])),max(b[0:4]),max(0,min(b[4:8])), max(b[4:8])]
pos.append(cord)
f.close()
return pos
if __name__ == '__main__':
anno = './annotation.txt'
count = 0
savepath = './coprocess/'
for i in range(1272):
filename = str(i).zfill(8)+'_co.png'
pos = LoadPosition(anno,filename)
re = cv2.imread('./Vehicules1024/'+filename)
for j in pos:
tmp = re[j[2]:j[3],j[0]:j[1]]
cv2.imwrite(savepath + str(count).zfill(5)+'.jpg',tmp)
count += 1
读取标准内类别信息,形成单独的类别文件(这个数据集标注很奇怪,明明只有九个类别,硬是标注出了11,23,31等奇怪的类别号,就把所有类别给转成了0-9之内,方便之后的训练):
def TransLabeltoTxt(path):
f = open(path)
p = open('E:/Vehicle Detection in Aerial Imagery/Vehicules1024/label1.txt','a+')
p.seek(0)
p.truncate()
for lines in f:
a = list(map(float, lines.split()))
if int(a[12]) == 10:
p.writelines(str(0)+'\n')
elif int(a[12]) == 11:
p.writelines(str(6)+'\n')
elif int(a[12]) == 23:
p.writelines(str(8)+'\n')
elif int(a[12]) == 31:
p.writelines(str(3)+'\n')
else:
p.writelines(str(int(a[12])) + '\n')
return "Trans success"
这样就获得了一个包含所有目标图片的文件夹,以及一个0-9的类别txt。这样的数据集就适合目标分类任务啦。