import json
# 读取 JSON 文件
file_path = '/mnt/d/GoogleDownload/Image_Video/annotations/train.json'
with open(file_path, 'r') as file:
data = json.load(file)
# 获取并更改id字段
for annotation in data['annotations']:
old_id = annotation['id']
old_image_id = annotation['image_id']
new_id = old_id + 835 # 假设将id加上1000
new_image_id=old_image_id+835
annotation['id'] = new_id
annotation['image_id'] = new_image_id
for image in data['images']:
old_id = image['id']
new_id = old_id + 835
image['id'] = new_id
with open(file_path, 'w') as file:
json.dump(data, file, indent=4)