예제 #1
0
파일: labelImg.py 프로젝트: winjia/labelImg
    def loadPascalXMLByFilename(self, xmlPath):
        if self.filename is None:
            return
        if os.path.isfile(xmlPath) is False:
            return

        tVocParseReader = PascalVocReader(xmlPath)
        shapes = tVocParseReader.getShapes()
        self.loadLabels(shapes)
예제 #2
0
    def loadPascalXMLByFilename(self, xmlPath):
        if self.filePath is None:
            return
        if os.path.isfile(xmlPath) is False:
            return

        tVocParseReader = PascalVocReader(xmlPath)
        shapes = tVocParseReader.getShapes()
        self.loadLabels(shapes)
        self.canvas.verified = tVocParseReader.verified
예제 #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)
def convert(image_path, annotation_path):

    save_path = os.path.join(os.path.dirname(annotation_path), "xml_converted")
    if not os.path.exists(save_path): os.makedirs(save_path)

    for file in os.listdir(annotation_path):
        if file.endswith(".xml"):
            annotation_no_xml = os.path.splitext(file)[0]

            imagePath = image_path + "/" + annotation_no_xml + ".jpg"

            image = QImage()
            image.load(imagePath)
            imageShape = [
                image.height(),
                image.width(), 1 if image.isGrayscale() else 3
            ]
            imgFolderName = os.path.basename(image_path)
            imgFileName = os.path.basename(imagePath)

            writer = YOLOWriter(imgFolderName,
                                imgFileName,
                                imageShape,
                                localImgPath=imagePath)

            # Read classes.txt
            classListPath = annotation_path + "/" + "classes.txt"
            classesFile = open(classListPath, 'r')
            classes = classesFile.read().strip('\n').split('\n')
            classesFile.close()

            # Read VOC file
            filePath = annotation_path + "/" + file
            tVocParseReader = PascalVocReader(filePath)
            shapes = tVocParseReader.getShapes()
            num_of_box = len(shapes)

            for i in range(num_of_box):
                label = classes.index(shapes[i][0])
                xmin = shapes[i][1][0][0]
                ymin = shapes[i][1][0][1]
                x_max = shapes[i][1][2][0]
                y_max = shapes[i][1][2][1]

                writer.addBndBox(xmin, ymin, x_max, y_max, label, 0)

            writer.save(targetFile=save_path + "/" + annotation_no_xml +
                        ".txt")
    def test_upper(self):
        dir_name = os.path.abspath(os.path.dirname(__file__))
        libs_path = os.path.join(dir_name, '..', 'libs')
        sys.path.insert(0, libs_path)
        from pascal_voc_io import PascalVocWriter
        from pascal_voc_io import PascalVocReader

        # Test Write/Read
        writer = PascalVocWriter('tests', 'test', (512, 512, 1), localImgPath='tests/test.512.512.bmp')
        difficult = 1
        writer.addBndBox(60, 40, 430, 504, 'person', difficult)
        writer.addBndBox(113, 40, 450, 403, 'face', difficult)
        writer.save('tests/test.xml')

        reader = PascalVocReader('tests/test.xml')
        shapes = reader.getShapes()

        personBndBox = shapes[0]
        face = shapes[1]
        self.assertEqual(personBndBox[0], 'person')
        self.assertEqual(personBndBox[1], [(60, 40), (430, 40), (430, 504), (60, 504)])
        self.assertEqual(face[0], 'face')
        self.assertEqual(face[1], [(113, 40), (450, 40), (450, 403), (113, 403)])
예제 #6
0
파일: test_io.py 프로젝트: cdicle/labelImg
    def test_upper(self):
        dir_name = os.path.abspath(os.path.dirname(__file__))
        libs_path = os.path.join(dir_name, '..', 'libs')
        sys.path.insert(0, libs_path)
        from pascal_voc_io import PascalVocWriter
        from pascal_voc_io import PascalVocReader

        # Test Write/Read
        writer = PascalVocWriter('tests', 'test', (512, 512, 1), localImgPath='tests/test.bmp')
        difficult = 1
        writer.addBndBox(60, 40, 430, 504, 'person', difficult)
        writer.addBndBox(113, 40, 450, 403, 'face', difficult)
        writer.save('tests/test.xml')

        reader = PascalVocReader('tests/test.xml')
        shapes = reader.getShapes()

        personBndBox = shapes[0]
        face = shapes[1]
        self.assertEqual(personBndBox[0], 'person')
        self.assertEqual(personBndBox[1], [(60, 40), (430, 40), (430, 504), (60, 504)])
        self.assertEqual(face[0], 'face')
        self.assertEqual(face[1], [(113, 40), (450, 40), (450, 403), (113, 403)])
예제 #7
0
        imgFolderName = os.path.basename(imgFolderPath)
        imgFileName = os.path.basename(imagePath)

        writer = YOLOWriter(imgFolderName,
                            imgFileName,
                            imageShape,
                            localImgPath=imagePath)

        # Read classes.txt
        classListPath = imgFolderPath + "/" + "classes.txt"
        classesFile = open(classListPath, 'r')
        classes = classesFile.read().strip('\n').split('\n')
        classesFile.close()

        # Read VOC file
        filePath = imgFolderPath + "/" + file
        tVocParseReader = PascalVocReader(filePath)
        shapes = tVocParseReader.getShapes()
        num_of_box = len(shapes)

        for i in range(num_of_box):
            label = classes.index(shapes[i][0])
            xmin = shapes[i][1][0][0]
            ymin = shapes[i][1][0][1]
            x_max = shapes[i][1][2][0]
            y_max = shapes[i][1][2][1]

            writer.addBndBox(xmin, ymin, x_max, y_max, label, 0)

        writer.save(targetFile=imgFolderPath + "/" + annotation_no_xml +
                    ".txt")
예제 #8
0
from unittest import TestCase

import sys
import os
dir_name = os.path.abspath(os.path.dirname(__file__))
libs_path = os.path.join(dir_name, '..', 'libs')
sys.path.insert(0, libs_path)
from pascal_voc_io import PascalVocWriter
from pascal_voc_io import PascalVocReader

# Test Write/Read
writer = PascalVocWriter('tests',
                         'test', (512, 512, 1),
                         localImgPath='tests/test.bmp')
difficult = 1
writer.addBndBox(60, 40, 430, 504, 'person', difficult)
writer.addBndBox(113, 40, 450, 403, 'face', difficult)
writer.save('tests/test.xml')

reader = PascalVocReader('tests/test.xml')
shapes = reader.getShapes()
예제 #9
0
        _, _= im_detect(net, im)

    im_names = os.listdir(input_dir+"/img")

    for im_name in im_names:
        print '~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~'
        print "auto label {0}".format(im_name)
        im_file = os.path.join(input_dir, 'img', im_name)

        label_file = os.path.join(input_dir, 'annotation', im_name)
        index = label_file.rindex('.')
        label_file = label_file[:index] + ".xml"
        if os.path.isfile(label_file):
            tmp_reader = PascalVocReader(label_file)
            size = tmp_reader.getSize()
            tmp_writer = PascalVocWriter(input_dir, im_name, size)
            shapes = tmp_reader.getShapes()
            for i in shapes:
                tmp_writer.addBndBox(i[1][0][0], i[1][0][1], i[1][2][0], i[1][2][1], i[0])
            print "load {0} labels from {1}".format(len(shapes), label_file)
        else:
            print "can not find label file {0}".format(label_file)
            size = cv2.imread(im_file).shape
            tmp_writer = PascalVocWriter(input_dir, im_name, size)
        
        n = auto_label(net, im_file, tmp_writer)
        
        tmp_writer.save(output_dir + '/' + os.path.basename(label_file))
        print "auto label {0} labels".format(n)
    plt.show()