import cv2
import numpy as np
from matplotlib import pyplot as plt
import os
import json
def create_newpic(oldname, newname):
img = cv2.imread(oldname,cv2.IMREAD_COLOR)
img2 = cv2.flip(img, 1)
cv2.imwrite(newname, img2, [int(cv2.IMWRITE_PNG_COMPRESSION), 9])
mainpath = 'C:/Users/liuta/Desktop/save'
count = 0
for file in os.listdir("./"):
if file.endswith(".json"):
print(file)
with open(file, 'rb') as dict:
load_dict = json.load(dict)
del load_dict['imageData']
for i in range(len(load_dict['shapes'])):
load_dict['shapes'][i]['points'][0][0] = 4096 - load_dict['shapes'][i]['points'][0][0]
load_dict['shapes'][i]['points'][1][0] = 4096 - load_dict['shapes'][i]['points'][1][0]
count += 1
name = str(count) + '_new' + '.json'
old_json_name = file
new_json_name = os.path.join(mainpath, name)
old_picture_name = file_ext = os.path.splitext(file)[0] + '.bmp'
new_picture_name = str(count) + '_new' + '.bmp'
new_picture_name = os.path.join(mainpath, new_picture_name)
with open(new_json_name, 'w') as f:
json.dump(load_dict, f, indent=4)
create_newpic(old_picture_name, new_picture_name)