1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90
| ''' 统计gf2021中目标大小(影响滑动窗口进行切片),统计飞机的目标大小,统计含括飞机的图片尺寸,把 有飞机的图片另存为,同时另存xml,把xml也修改一下,把非飞机的目标丢弃掉。 ''' import os import numpy as np import scipy.misc as misc from xml.dom.minidom import Document import numpy as np import copy, cv2
import json import glob import xml.etree.cElementTree as ET import re from osgeo import gdal, gdalconst
def information_statistics_save(image_path, xml_path): plane_data = np.zeros((10,13)) initialization=np.array([0,10000,10000,10000,-1,-1,-1,10000,10000,10000,-1,-1,-1]) plane_data = plane_data + initialization plane_label = ["Boeing737","Boeing747","Boeing777","C919","A220","A321","A330","A350","ARJ21","other-airplane"] for count, xml in enumerate(glob.glob(xml_path + '/*.xml')): xml = xml.replace('\\', '/') (_, xml_name) = os.path.split(xml) img_name, box , size, difficult_list, tmp_score_list = read_xml_gtbox_and_label(xml) img_name=xml_name.replace('.xml', '.tif') img_path = image_path + '/' + img_name
size = np.float32(size) for box_one_object in box: if box_one_object[8] in plane_label: index_label=plane_label.index(box_one_object[8]) plane_data[index_label,0]=plane_data[index_label,0]+1 box_float=np.float32(box_one_object[0:8]) x_box=box_float[[0,2,4,6]] y_box=box_float[[1,3,5,7]] width = np.max(x_box)-np.min(x_box) height = np.max(y_box)-np.min(y_box) if int(width*100) ==758: print(xml) if width < plane_data[index_label,1]: plane_data[index_label,1]=width if height < plane_data[index_label,2]: plane_data[index_label,2]=height if width/height < plane_data[index_label,3]: plane_data[index_label,3]=width/height if width > plane_data[index_label,4]: plane_data[index_label,4]=width if height > plane_data[index_label,5]: plane_data[index_label,5]=height if width/height > plane_data[index_label,6]: plane_data[index_label,6]=width/height if size[0] < plane_data[index_label,7]: plane_data[index_label,7]=size[0] if size[1] < plane_data[index_label,8]: plane_data[index_label,8]=size[1] if size[2] < plane_data[index_label,9]: plane_data[index_label,9]=size[2] if size[0] > plane_data[index_label,10]: plane_data[index_label,10]=size[0] if size[1] > plane_data[index_label,11]: plane_data[index_label,11]=size[1] if size[2] > plane_data[index_label,12]: plane_data[index_label,12]=size[2] else: print("出现错误")
if not os.path.exists(img_path): print('{} is not exist!'.format(img_path)) continue print(plane_data) np.save("plane_data.npy",plane_data) print('\nStatistics is complete!') return plane_data
if __name__ == "__main__": image_path=r"/emwuser/gzl/gf2021/data/FAIR1M/train/part1_plane/images" xml_path=r"/emwuser/gzl/gf2021/data/FAIR1M/train/part1_plane/labelXmls"
information_statistics_save(image_path,xml_path)
|