dms-client/util/json_util.py

45 lines
2.1 KiB
Python
Raw Permalink Normal View History

import json
import os
def write_info(file_name, file_info):
dir = os.path.dirname(file_name)
if not os.path.exists(dir):
os.makedirs(dir)
with open('{}.json'.format(file_name), 'w', encoding='UTF-8') as fp:
json.dump(file_info, fp, indent=4, sort_keys=False)
def read_json(file_path):
with open(file_path, 'r') as f:
data = json.load(f)
return data
report_data = {"project_no": "628740635893760", "img_path": "2000.png",
"create_time": "2021-06-10T11:17:12.202000+00:00", "labels": [
{"shape": "polygon", "name": "a", "line_width": 2, "width": 750.0, "height": 788.0, "comment": "string",
"color": "rgb(255, 0, 123)", "is_match": "False", "score": 0.0,
"point": [{"x": 114.04715127701375, "y": 53.04518664047151}, {"x": 196.2671905697446, "y": 53.04518664047151},
{"x": 196.2671905697446, "y": 149.4106090373281},
{"x": 114.04715127701375, "y": 149.4106090373281}]},
{"shape": "polygon", "name": "a", "line_width": 2, "width": 750.0, "height": 788.0, "comment": "string",
"color": "rgb(255, 0, 123)", "is_match": "False", "score": 0.0,
"point": [{"x": 284.67583497053045, "y": 64.53831041257367}, {"x": 401.3752455795678, "y": 64.53831041257367},
{"x": 401.3752455795678, "y": 266.1100196463654},
{"x": 284.67583497053045, "y": 266.1100196463654}]},
{"shape": "polygon", "name": "a", "line_width": 2, "width": 750.0, "height": 788.0, "comment": "string",
"color": "rgb(255, 0, 123)", "is_match": "False", "score": 0.0,
"point": [{"x": 501.2770137524558, "y": 148.52652259332024}, {"x": 623.2809430255403, "y": 148.52652259332024},
{"x": 623.2809430255403, "y": 320.0392927308448},
{"x": 501.2770137524558, "y": 320.0392927308448}]}]}
if __name__ == "__main__":
path = os.path.abspath(os.path.dirname(__file__))
print(path)
# write_info('', dict(report_data))
# read_json('d://report.json')
# s = '/group1/628740635893760/ori/images/7 (1).png'
# s1 = s.replace('images', 'labels')
# print(s[2])