forked from LZQ-RSer/RS_Detection
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathjson_to_txt.py
36 lines (34 loc) · 1.03 KB
/
json_to_txt.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
# -*- coding: utf-8 -*-
# @Time : 2021/2/5 22:15
# @Author : lzq
# @Site :
# @File : json_to_txt.py
# @Software: PyCharm Community Edition
import numpy as np
import os
import glob
import json
def json_to_txt(json_file,ourfile):
file = open(outfile,'w')
with open(json_file) as f:
lines = json.load(f)
filename = lines['imagePath']
width = lines['imageWidth']
height = lines['imageHeight']
file.write("%s %s,%s" % (filename, width, height))#注意空格
lines = lines["shapes"]
for line in lines:
list = line['points']
xmin = int(list[0][0])
ymin = int(list[0][1])
xmax = int(list[1][0])
ymax = int(list[1][1])
cla = line['label']
b = (xmin, ymin, xmax, ymax, cla)
file.write(' ' + ",".join([str(a) for a in b]))
file.write('\n')
file.close()
if __name__ == '__main__':
json_file= './test/clip.json'
outfile = './test/clip.json.txt'
json_to_txt(json_file,outfile)