闲扯淡之机器学习——Python图像标注工具实现

时间过得真快,最近好久没有和大家闲扯淡了,好像,好像你们啊!!最近工作比较忙,一直想写点东西,但是身不由己啊。好不容易抽出一点时间写了一个工具——图像标注工具,这个工具与github上的labelImg很像,坦白承认我的却抄袭labelImg的部分标注方法(臭不要脸的抄袭,赶快滚,有多远滚多远)。我这这一个工具的目的:
1.最近在学习python,所以想练练手;
2.labelImg只能够标注矩形目标区域,局限性比较多,我想写一个更加通用的工具(更加通用可能有点太自大了,写到最好发现,我写的东西也有很多局限性,后面我会不断的迭代);
现在给大家展示一下这个软件的界面:
闲扯淡之机器学习——Python图像标注工具实现_第1张图片
这个界面是初始界面,下面的界面是工作时的界面:
闲扯淡之机器学习——Python图像标注工具实现_第2张图片
散点标注为下图:
闲扯淡之机器学习——Python图像标注工具实现_第3张图片

这里我主要使用python中的tkinter库实现界面(我在网上看到:有人说这个库不好,至于这个库的好坏我不过评论,仁者见仁智者见智吧),标注文件目前仅支持XML。
目前存在的问题:
1.未知的bug(自己测试难免会有问题)
2.离散点标注,目前要求标注四个点;
3.标注文件保存格式仅支持XML;
4.代码书写不规范;
5.仅支持中文;
6.部分弹窗不友好。
针对以上问题,会在后期的版本改正这些问题,改正完2,4,6后,我会将这个工程共享到github。众人拾柴火焰高,求大神帮忙,一起完善改进,谢谢!!
下面贴出一部分代码:

#-*- coding:utf-8 -*-

import codecs
from lxml import etree
from xml.etree import ElementTree
from xml.etree.ElementTree import Element, SubElement


class XMLWrite:

    def __init__(self,folder_path,file_name):
        self.folder_path = folder_path
        self.file_name = file_name
        self.top = Element('Images')
        self.object = None

    def create_object(self,path,object_name = 'objectName',tag_name = 'FilePath'):
        self.object = SubElement(self.top, object_name)
        self.object.set(tag_name, path)

    def set_lable_info(self, lable ,lable_name='LableName'):
        if self.object == None:
            raise Exception('没有创建object对象,create_object方法')
        plate = SubElement(self.object, lable_name)
        plate.text = lable

    def set_object_info(self,tag_name = 'Size',**args):
        if self.object == None:
            raise Exception('没有创建object对象,create_object方法')

        size = SubElement(self.object, tag_name)
        for key in args:
            sub = SubElement(size, key)
            sub.text = str(args[key])

        # width = SubElement(size, 'width')
        # width.text = '500'
        # heigth = SubElement(size, 'heigth')
        # heigth.text = '400'
        # depth = SubElement(size,'width')
        # depth.text = '3'

    def set_position_rect(self,tag_name = 'Position',**args):
        if self.object == None:
            raise Exception('没有创建object对象,create_object方法')
        point = SubElement(self.object, tag_name)

        for key in args:
            sub = SubElement(point, key)
            sub.text = str(args[key])

    def set_position_scat(self, tag_name = 'Position',info = None):
        if self.object == None:
            raise Exception('没有创建object对象,create_object方法')
        point = SubElement(self.object,tag_name)
        for key in info:
            sub = SubElement(point, key)
            sub.set('x',str(info[key][0]))
            sub.set('y', str(info[key][1]))

    '''
    def genXML(self):
        top = Element('Images')

        car = SubElement(top, 'image')
        car.set('car', '1.jpg')

        plate = SubElement(car, 'plate')
        plate.text = '鲁A548A84'

        size = SubElement(car, 'size')
        width = SubElement(size, 'width')
        width.text = '500'
        heigth = SubElement(size, 'heigth')
        heigth.text = '400'
        depth = SubElement(size,'width')
        depth.text = '3'

        point = SubElement(car, 'point')

        lt = SubElement(point,'lt')
        ltx = SubElement(lt,'ltx')
        ltx.text = '100'
        lty = SubElement(lt,'lty')
        lty.text = '100'

        rt = SubElement(point,'rp')
        rpx = SubElement(rt,'rpx')
        rpx.text = '100'
        rpy = SubElement(rt,'rpy')
        rpy.text = '100'

        lb = SubElement(point,'lb')
        lbx = SubElement(lb,'lbx')
        lbx.text = '100'
        lby = SubElement(lb,'lby')
        lby.text = '100'

        rb = SubElement(point,'rb')
        rbx = SubElement(rb,'rbx')
        rbx.text = '100'
        rby = SubElement(rb,'rby')
        rby.text = '100'
        return top
    '''
    def prettify(self, elem):
        """
            Return a pretty-printed XML string for the Element.
        """
        rough_string = ElementTree.tostring(elem, 'utf8')
        root = etree.fromstring(rough_string)
        return etree.tostring(root, pretty_print=True, encoding='utf-8').replace("  ".encode(), "\t".encode())
        # minidom does not support UTF-8
        '''reparsed = minidom.parseString(rough_string)
        return reparsed.toprettyxml(indent="\t", encoding=ENCODE_METHOD)'''


    def 

你可能感兴趣的:(闲扯人工智能,深度学习,机器学习)