Exemple #1
0
    def label_filter(self, labels, new_dir):
        flist = []
        for lb in labels:
            stemp = self.find_label(lb)
            for fname in stemp:
                if (fname in flist) == False:
                    flist.append(fname)

        for filename in flist:
            filepath = self.anno_path + '/' + filename + '.xml'
            pr = PR(filepath)
            shapes = pr.getShapes()
            sl = pr.getSources()
            localpath = os.path.join(self.im_path, sl['filename'])

            pw = PW(sl['folder'],
                    sl['filename'],
                    sl['size'],
                    databaseSrc='Unknown',
                    localImgPath=localpath)
            pw.verified = True

            for shape in shapes:
                if shape[0] in labels:
                    label = shape[0]
                    difficult = 0
                    bndbox = shape[1]
                    pw.addBndBox(bndbox[0][0], bndbox[0][1],
                                 bndbox[2][0], bndbox[2][1], label, difficult)

            pw.save(new_dir + '/' + filename + '.xml')
Exemple #2
0
    def del_label(self, label_del):

        flist = os.listdir(self.anno_path)
        for filename in flist:
            filepath = self.anno_path + '/' + filename
            pr = PR(filepath)
            shapes = pr.getShapes()
            sl = pr.getSources()

            localpath = os.path.join(self.im_path, sl['filename'])

            pw = PW(sl['folder'],
                    sl['filename'],
                    sl['size'],
                    databaseSrc='Unknown',
                    localImgPath=localpath)
            pw.verified = True

            for shape in shapes:
                if shape[0] != label_del:
                    label = shape[0]
                    difficult = 0
                    bndbox = shape[1]
                    pw.addBndBox(bndbox[0][0], bndbox[0][1],
                                 bndbox[2][0], bndbox[2][1], label, difficult)

            pw.save(filepath)
Exemple #3
0
    def check_label(self):

        flist = os.listdir(self.anno_path)

        for filename in flist:
            filepath = self.anno_path + '/' + filename
            pr = PR(filepath)
            shapes = pr.getShapes()
            sl = pr.getSources()

            if len(shapes) == 0:
                print(filepath)