修改labelme格式标注的偏移量

修改labelme格式标注的偏移量

from utils import *



# all_jsons = get_files_path(r"E:\50994-烧伤\50994-烧伤\烧伤\DefaultImageSet\01-实例分割2\Marks - 副本 - 副本")
#
#
# '''
# 分割标注
# '''
# for item in all_jsons:
#     content = readJsonFile(item)
#     for index, item2 in enumerate(content['shapes']):
#         print(item2["label"])
#
#         if content['shapes'][index]['label'] == "SS":
#             content['shapes'][index]['group_id']
#             for index2 in range(len(content['shapes'][index]['points'])):
#                 print(index2)
#                 content['shapes'][index]['points'][index2][0] = content['shapes'][index]['points'][index2][0] - 425
#                 content['shapes'][index]['points'][index2][1] = content['shapes'][index]['points'][index2][1] - 172
#                 content['shapes'][index]['points'][index2]= content['shapes'][index]['points'][index2]
#
#
#         # 改id
#         # content['shapes'][index]['group_id'] = 3
#         # 改名称
#         # content['shapes'][index]['label'] = "LY2"
#
#     with open(item, 'w') as f:
#         json.dump(content, f, indent=2)
#     print(content)

def LabelAddOffset(target_path,x_offset,y_offset,save_path):
    all_jsons = get_files_path(target_path)

    '''
    分割标注
    '''
    # 遍历所有json
    for item in all_jsons:
        # 读取json
        content = readJsonFile(item)
        # 遍历shapes,遍历每个标注
        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)
        # 保存json
        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):
        #setting title
        root.title("undefined")
        #setting window size
        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
        x = self.GLineEdit_398_content.get()
        # print(input_dir1)
        # y
        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()

  • 12
    点赞
  • 9
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值