-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpro_peocess.py
More file actions
45 lines (41 loc) · 1.37 KB
/
pro_peocess.py
File metadata and controls
45 lines (41 loc) · 1.37 KB
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
import os
import cv2
import numpy as np
pre = '/home/tangjian/Codes/VOC/images/'
datas = ['test2007', 'train2007', 'train2012']
# check the images size
# max_h, max_w = 0, 0
# for data in datas:
# path = pre + data
# files = os.listdir(path)
# os.chdir(path)
# for file in files:
# if not file.endswith('pkl'):
# img = cv2.imread(file)
# h, w = img.shape[:2]
# if h > max_h: max_h = h
# if w > max_w: max_w = w
# # if h > 512 or w > 512:
# # print('the {} in {} size is so big'.format(file, path))
# # else:
# # print('size is normal')
# print(max_h, max_w)
for data in datas:
path = pre + data
files = os.listdir(path)
os.chdir(path)
for file in files:
if not file.endswith('pkl'):
img = cv2.imread(file)
h, w = img.shape[:2]
if h > 512 or w > 512:
print('the {} in {} size is so big'.format(file, path))
break
else:
# print('size is normal')
ph = 512 - h
pw = 512 - w
img = np.pad(img, ((0, ph), (0, pw), (0, 0)),'mean')
d_path = path.replace('images', 'images512_') + '/' + file
cv2.imwrite(d_path, img)
pass