修改labelme格式标注的偏移量
from utils import *
def LabelAddOffset(target_path,x_offset,y_offset,save_path):
all_jsons = get_files_path(target_path)
'''
分割标注
'''
for item in all_jsons:
content = readJsonFile(item)
for index, item2 in enumerate(content['shapes']):
for index2 in range(len(content['shapes'][index]['points'])):
content['shapes'][index]['points'][index2][0] = content['shapes'][index]['points'][index2][0] - x_offset
content['shapes'][index]['points'][index2][1] = content['shapes'][index]['points'][index2][1] - y_offset
content['shapes'][index]['points'][index2] = content['shapes'][index]['points'][index2]
makedir(save_path)
with open(os.path.join(save_path,os.path.basename(item)), 'w') as f:
json.dump(content, f, indent=2)
print(content)
if __name__ == '__main__':
LabelAddOffset(r"Marks - 副本 - 副本",-10,10,"E:\dddd");
import tkinter as tk
import tkinter.font as tkFont
from JsonOffset import LabelAddOffset
class App:
def __init__(self, root):
root.title("undefined")
width=531
height=302
screenwidth = root.winfo_screenwidth()
screenheight = root.winfo_screenheight()
alignstr = '%dx%d+%d+%d' % (width, height, (screenwidth - width) / 2, (screenheight - height) / 2)
root.geometry(alignstr)
root.resizable(width=False, height=False)
self.GLineEdit_398=tk.Entry(root)
self.GLineEdit_398["borderwidth"] = "1px"
ft = tkFont.Font(family='Times',size=10)
self.GLineEdit_398["font"] = ft
self.GLineEdit_398["justify"] = "center"
self.GLineEdit_398_content = tk.StringVar()
self.GLineEdit_398["textvariable"] = self.GLineEdit_398_content
self.GLineEdit_398.place(x=140,y=100,width=285,height=30)
self.GLineEdit_787=tk.Entry(root)
self.GLineEdit_787["borderwidth"] = "1px"
ft = tkFont.Font(family='Times',size=10)
self.GLineEdit_787["font"] = ft
self.GLineEdit_787["justify"] = "center"
self.GLineEdit_787_content = tk.StringVar()
self.GLineEdit_787["textvariable"] = self.GLineEdit_787_content
self.GLineEdit_787.place(x=140,y=150,width=285,height=30)
GLabel_796=tk.Label(root)
ft = tkFont.Font(family='Times',size=10)
GLabel_796["font"] = ft
GLabel_796["fg"] = "#333333"
GLabel_796["justify"] = "center"
GLabel_796["text"] = "x"
GLabel_796.place(x=40,y=110,width=70,height=25)
GLabel_592=tk.Label(root)
ft = tkFont.Font(family='Times',size=10)
GLabel_592["font"] = ft
GLabel_592["fg"] = "#333333"
GLabel_592["justify"] = "center"
GLabel_592["text"] = "y"
GLabel_592.place(x=40,y=150,width=70,height=25)
GButton_28=tk.Button(root)
GButton_28["bg"] = "#f0f0f0"
ft = tkFont.Font(family='Times',size=10)
GButton_28["font"] = ft
GButton_28["fg"] = "#000000"
GButton_28["justify"] = "center"
GButton_28["text"] = "生成"
GButton_28.place(x=350,y=210,width=70,height=25)
GButton_28["command"] = self.GButton_28_command
self.GLineEdit_903=tk.Entry(root)
self.GLineEdit_903["borderwidth"] = "1px"
ft = tkFont.Font(family='Times',size=10)
self.GLineEdit_903["font"] = ft
self.GLineEdit_903["justify"] = "center"
self.GLineEdit_903_content = tk.StringVar()
self.GLineEdit_903["textvariable"] = self.GLineEdit_903_content
self.GLineEdit_903.place(x=140,y=30,width=285,height=30)
GLabel_772=tk.Label(root)
ft = tkFont.Font(family='Times',size=10)
GLabel_772["font"] = ft
GLabel_772["fg"] = "#333333"
GLabel_772["justify"] = "center"
GLabel_772["text"] = "源路径"
GLabel_772.place(x=40,y=30,width=70,height=25)
GLabel_955=tk.Label(root)
ft = tkFont.Font(family='Times',size=10)
GLabel_955["font"] = ft
GLabel_955["fg"] = "#333333"
GLabel_955["justify"] = "center"
GLabel_955["text"] = "保存路径"
GLabel_955.place(x=40,y=70,width=70,height=25)
self.GLineEdit_834=tk.Entry(root)
self.GLineEdit_834["borderwidth"] = "1px"
ft = tkFont.Font(family='Times',size=10)
self.GLineEdit_834["font"] = ft
self.GLineEdit_834["fg"] = "#333333"
self.GLineEdit_834["justify"] = "center"
self.GLineEdit_834_content = tk.StringVar()
self.GLineEdit_834["textvariable"] = self.GLineEdit_834_content
self.GLineEdit_834.place(x=140,y=70,width=282,height=30)
def GButton_28_command(self):
x = self.GLineEdit_398_content.get()
y = self.GLineEdit_787_content.get()
sourceDir = self.GLineEdit_903_content.get()
saveDir = self.GLineEdit_834_content.get()
LabelAddOffset(sourceDir,int(x),int(y),saveDir)
print("command")
if __name__ == "__main__":
root = tk.Tk()
app = App(root)
root.mainloop()