forked from LZQ-RSer/RS_Detection
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathStatistics_wh.py
80 lines (75 loc) · 2.52 KB
/
Statistics_wh.py
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
# -*- coding: utf-8 -*-
# @Time : 2021/2/7 22:48
# @Author : lzq
# @Site :
# @File : Statistics.py
# @Software: PyCharm Community Edition
import numpy as np
import os
from PIL import Image,ImageFont, ImageDraw
Image.MAX_IMAGE_PIXELS = None
import glob
import tqdm
import cv2
import matplotlib.pyplot as plt
import pandas as pd
def read_txt(str_text):
"""
自定义解析方法
:param str_text:
:return:
"""
list = []
with open(str_text) as f:
line = f.readline()
while line:
# 消除空行
if line.isspace():
line = f.readline()
continue
#消除换行
if '\n' in line:
line = line.strip("\n")
#消除不需要的行
if line[0] in ["i","g"]:
line = f.readline()
continue
list.append(line)
line = f.readline()
return list
def get_image_wh(lines):
print('all images numbers:',len(lines))
#宽高数据
w_dict={}
h_dict = {}
i=0
for line in lines:
lin = line.split(' ')
h, w = lin[1].split(',')
h = int(h)
w = int(w)
w_dict.update({i:w})
h_dict.update({i:h})
i+=1
##(1)绘制图像长宽分布
plt.scatter(list(w_dict.values()), list(h_dict.values()))
plt.title("image w h")
plt.xlabel("w")
plt.ylabel('h')
plt.show()
if __name__ == '__main__':
############################################
#类别
############################################
"""
大型车辆(large vehicle)、游泳池(swimming pool)、直升机(helicopter)、桥梁(bridge)、飞机(plane)、船舶(ship)、足球场(soccer ball field)、篮球场(basketball court)、机场(airport)、
集装箱起重机(container-crane)、田径场(ground track field)、小汽车(small vehicle)、码头(harbor)、棒球场(baseball diamond)、网球场(tennis court)、转盘(roundabout)、储存罐(storage tank)、直升机场(helipad)
"""
class_name = ["large-vehicle", "swimming-pool", "helicopter", "bridge", "plane", "ship", "soccer-ball-field",
"basketball-court", "airport","container-crane", "ground-track-field", "small-vehicle", "harbor",
"baseball-diamond", "tennis-court","roundabout", "storage-tank", "helipad"]
print("all class is:",len(class_name))
class_name_dict = dict(zip(range(len(class_name)), class_name))
outfile = './test/all.txt'
boxs = read_txt(outfile)
get_image_wh(boxs)