-
Notifications
You must be signed in to change notification settings - Fork 15
/
json2lst.py
48 lines (40 loc) · 1.49 KB
/
json2lst.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
import json
import mxnet as mx
from skimage import io
jsonName = 'ownset.json'
directory = 'ownSet/'
with open(jsonName, 'r') as f:
DataSet = json.load(f)
print(DataSet['DataSet'][0]['img_name'])
img_idx = 0
with open('ownSet.lst', 'w+') as f:
for Data in DataSet['DataSet']:
x_min = Data['bbox'][0]
y_min = Data['bbox'][1]
x_max = Data['bbox'][0]+ Data['bbox'][2]
y_max = Data['bbox'][1]+ Data['bbox'][3]
f.write(
str(img_idx) + '\t' + # idx
str(4) + '\t' + str(5) + '\t' + # width of header and width of each object.
str(int(Data['height'])) + '\t' + str(Data['width']) + '\t' + # (width, height)
str(1) + '\t' + # class
str(x_min) + '\t' + str(y_min) + '\t' + str(x_max) + '\t' + str(y_max) + '\t' + # xmin, ymin, xmax, ymax
str(Data['img_name'])+'\n')
img_idx += 1
'''
with open('dataset.lst', 'w+') as f:
for i in range(3):
f.write(
str(i) + '\t' +
# idx
str(4) + '\t' + str(5) + '\t' +
# width of header and width of each object.
str(256) + '\t' + str(256) + '\t' +
# (width, height)
str(1) + '\t' +
# class
str((i / 10)) + '\t' + str((i / 10)) + '\t' + str(((i + 3) / 10)) + '\t' +str(((i + 3) / 10)) + '\t' +
# xmin, ymin, xmax, ymax
str(i) + '.jpg\n'
)
'''