import json
annotation = {
"version": "4.5.7",
"flags": {},
"shapes": [
{
"label": "car",
"points": [
[
187.14285714285714,
403.14285714285717
],
[
193.99999999999997,
407.42857142857144
],
[
194.85714285714286,
414.0
],
[
188.57142857142856,
419.7142857142857
],
[
180.85714285714283,
416.8571428571429
],
[
179.33910533910532,
409.2655122655123
]
],
"group_id": '',
"shape_type": "polygon",
"flags": {}
}
],
"imagePath": "1-1-1n.jpg",
"imageHeight": 587,
"imageWidth": 1564
}
# 写入json数据
with open('test.json', 'w') as f:
json.dump(annotation, f)
# 读取json数据
with open('test.json', 'r') as f:
data = json.load(f)
print(data['shapes'][0]['points'])
运行结果:
[[187.14285714285714, 403.14285714285717],
[193.99999999999997, 407.42857142857144],
[194.85714285714286, 414.0],
[188.57142857142856, 419.7142857142857],
[180.85714285714283, 416.8571428571429],
[179.33910533910532, 409.2655122655123]]