Exemple #1
0
def to_csv(path):

    classNameList = [
        "ascending_stair", "descending_stair", "door", "elevator_door"
    ]

    obj = imageRegionOfInterest(path)
    valid_images = [".jpg", ".gif", ".png", ".tga", ".jpeg"]

    xml_list = []
    for filename in os.listdir(path):
        name, ext = os.path.splitext(filename)
        if ext.lower() not in valid_images:
            continue
        if (not os.path.exists(os.path.join(path, name + ".txt"))):
            continue

        obj.setFileImage(filename)
        print(filename)
        points = obj.loadBoxFromTxt()
        if len(points) > 0:
            obj.loadFromFile()
            for point in points:
                iclass = int(point[4])
                value = (filename, int(obj.image.shape[1]),
                         int(obj.image.shape[0]), classNameList[iclass],
                         int(point[0]), int(point[1]), int(point[2]),
                         int(point[3]))
                xml_list.append(value)

    column_name = [
        'filename', 'width', 'height', 'class', 'xmin', 'ymin', 'xmax', 'ymax'
    ]
    xml_df = pd.DataFrame(xml_list, columns=column_name)
    return xml_df
def run(path, destPath):

    margemArea = 0.2
    finalSquad = 50

    obj = imageRegionOfInterest(path)

    valid_images = [".jpg", ".gif", ".png", ".tga", ".jpeg"]

    qtd = 0
    for filename in os.listdir(path):
        name, ext = os.path.splitext(filename)
        if ext.lower() not in valid_images:
            continue
        if (not os.path.exists(os.path.join(path, name + ".txt"))):
            continue

        obj.setFileImage(filename)
        points = obj.loadBoxFromTxt()

        if len(points) > 0:
            obj.loadFromFile()
            boxNumber = 0
            for point in points:
                name, ext = os.path.splitext(filename)
                if margemArea != 0:
                    obj.extractBoxM(os.path.join(destPath, point[4]),
                                    name + "-" + str(boxNumber) + ext, point,
                                    margemArea, finalSquad)
                else:
                    obj.extractBox(os.path.join(destPath, point[4]),
                                   name + "-" + str(boxNumber) + ext, point)
                boxNumber += 1

        qtd += 1
def run(pathImages, filePath):

    obj = imageRegionOfInterest(pathImages)
    filehandle = open(filePath, "r")
    while True:
        # read a single line
        line = filehandle.readline()
        if not line:
            break

        name = line[0:-1]
        #print(name)

        obj.points.clear()
        qtd = int(filehandle.readline())
        for i in range(qtd):
            box = filehandle.readline().split(' ')
            obj.setFileImage(pathImages + name)
            obj.setTxtFileName()
            obj.loadFromFile()
            x1y1 = (int(box[0]), int(box[1]))
            x2y2 = (int(box[0]) + int(box[2]), int(box[1]) + int(box[3]))
            obj.points.append([x1y1, x2y2, "0"])

        obj.savePoints()
Exemple #4
0
def run(image_path, ann_path, classNameList = ["someclass"]):

    obj = imageRegionOfInterest(image_path)
    valid_images = [".jpg",".gif",".png",".tga",".jpeg"]

    #print(image_path)
    classes_qtd = []
    images_total_qtd = 0
    images_without_classes_qtd = 0

    xml_list = []
    for filename in os.listdir(image_path):
        name, ext = os.path.splitext(filename)
        if ext.lower() not in valid_images:
            continue

        images_total_qtd = images_total_qtd + 1

        xmlFileName = os.path.join(ann_path,name+".xml")

        obj.setFileImage(filename)
        obj.loadFromFile()            
        points = obj.loadBoxFromTxt()     

        #print(image_path, filename, int(obj.image.shape[1]), int(obj.image.shape[0]))

        annotation = root(image_path, filename, int(obj.image.shape[1]), int(obj.image.shape[0]))

        if len(points)>0:
            for point in points:
                annotation.append(instance_to_xml(point, classNameList))
                iclass = int(point[4]) 
                while len(classes_qtd) < iclass+1:
                    classes_qtd.append(0)

                classes_qtd[iclass] = classes_qtd[iclass] + 1
        else:
            images_without_classes_qtd = images_without_classes_qtd + 1


        #print(etree.tostring(annotation, pretty_print=True))
        print(xmlFileName)
        etree.ElementTree(annotation).write(xmlFileName)

    print('Successfully converted to xml PASCAL.')

    print('Total Images: ', images_total_qtd)
    print('Images without classes: ', images_without_classes_qtd)
    print('Classes: ')
    for q in classes_qtd:
        print( q)



    return 
def searchFolder(image_path, ann_path, classNameList, searchSubdir):

    global valid_images
    global classes_qtd
    global images_total_qtd
    global images_without_classes_qtd
    global xml_list

    print("Folder", image_path)

    obj = imageRegionOfInterest(image_path)
    for filename in os.listdir(image_path):
        if searchSubdir and os.path.isdir(os.path.join(image_path, filename)):
            searchFolder(os.path.join(image_path, filename), ann_path,
                         classNameList, searchSubdir)

        name, ext = os.path.splitext(filename)
        if ext.lower() not in valid_images:
            continue

        images_total_qtd = images_total_qtd + 1

        xmlFileName = os.path.join(ann_path, name + ".xml")

        obj.setFileImage(filename)
        obj.loadFromFile()
        points = obj.loadBoxFromTxt()

        #print(image_path, filename, int(obj.image.shape[1]), int(obj.image.shape[0]))

        annotation = root(image_path, filename, int(obj.image.shape[1]),
                          int(obj.image.shape[0]))

        if len(points) > 0:
            for point in points:
                annotation.append(instance_to_xml(point, classNameList))
                iclass = int(point[4])
                while len(classes_qtd) < iclass + 1:
                    classes_qtd.append(0)

                classes_qtd[iclass] = classes_qtd[iclass] + 1
        else:
            images_without_classes_qtd = images_without_classes_qtd + 1

        #print(etree.tostring(annotation, pretty_print=True))
        print(xmlFileName)
        createFolder(os.path.dirname(xmlFileName))
        etree.ElementTree(annotation).write(xmlFileName)

    return
Exemple #6
0
def searchFolder(image_path, classNameList, searchSubdir):

    global valid_images
    global classes_qtd
    global images_total_qtd
    global images_without_classes_qtd
    global xml_list

    print("Folder", image_path)

    obj = imageRegionOfInterest(image_path)
    for filename in os.listdir(image_path):
        if searchSubdir and os.path.isdir(os.path.join(image_path, filename)):
            searchFolder(os.path.join(image_path, filename), classNameList, searchSubdir)

        name, ext = os.path.splitext(filename)
        if ext.lower() not in valid_images:
            continue

        print(filename)
        images_total_qtd = images_total_qtd + 1

        obj.setFileImage(filename)
        points = obj.loadBoxFromTxt()     

        if len(points)>0:
            for point in points:
                iclass = int(point[4]) 
                while len(classes_qtd) < iclass+1:
                    classes_qtd.append(0)

                classes_qtd[iclass] = classes_qtd[iclass] + 1
        else:
            images_without_classes_qtd = images_without_classes_qtd + 1

    return 
def run(path, isFirstEmpty=False, classNumber="0", classNameList=None):

    valid_images = [".jpg", ".gif", ".png", ".tga", ".jpeg"]

    fileNames = []
    firstEmpty = -1
    qtd = 0
    for filename in os.listdir(path):
        name, ext = os.path.splitext(filename)
        if ext.lower() not in valid_images:
            continue
        fileNames.append(filename)
        if (firstEmpty == -1
                and not os.path.exists(os.path.join(path, name + ".txt"))):
            firstEmpty = qtd
        qtd += 1

    obj = imageRegionOfInterest(path)

    obj.isSavePoints = True
    obj.pathToSave = path
    obj.classNumber = classNumber
    obj.classNameList = classNameList

    print("Total", qtd)
    print("Labeled", firstEmpty)

    index = 0
    if (isFirstEmpty and firstEmpty != -1):
        index = firstEmpty

    while index < len(fileNames):

        if index < 0:
            index = 0
        if index == len(fileNames):
            index = len(fileNames) - 1

        filename = fileNames[index]

        print(str(index) + " " + filename)

        obj.loadImage(filename)

        wait = 10
        # keep looping until the 'q' key is pressed
        while True:

            key = cv2.waitKey(33) & 0xFF
            #if key != 255:
            #    print("Key "+str(key))

            # refresh
            if key == ord("r"):
                print('refresh')
                obj.refresh()

            # save
            elif key == ord("s"):
                print('savePoints')
                obj.savePoints()

            # change Class Number
            elif key >= ord("0") and key <= ord("9"):
                print('change Class to ' + chr(key))
                obj.classNumber = chr(key)
                obj.RefreshSelectedClass()

            # change Class 0  (' key is left side 1 key)
            elif key == ord("'"):
                print('change Class to 0')
                obj.classNumber = "0"
                obj.RefreshSelectedClass()

            # next image or spacebar
            elif key == ord("n") or key == 32:
                print('next image')
                obj.savePoints()
                index += 1
                break

            # previus image
            elif key == ord("p"):
                print('previus image')
                obj.savePoints()
                index -= 1
                break

            # box to left
            elif key == ord("g"):
                print('box to left')
                obj.moveLastBox(-1, 0)
            # box to right
            elif key == ord("h"):
                print('box to right')
                obj.moveLastBox(1, 0)

            # box to up
            elif key == ord("y"):
                print('box to up')
                obj.moveLastBox(0, -1)
            # box to down
            elif key == ord("b"):
                print('box to down')
                obj.moveLastBox(0, 1)

            # copy last bounding boxes
            elif key == ord("c"):
                print('copy last bounding boxes')
                obj.copyLastBoundingBoxes()

            # shift last bounding box
            elif key == ord("x"):
                print('shift last bounding box')
                obj.shiftLastBoundingBox()

            # quit
            elif key == ord("q") or key == 27 or cv2.getWindowProperty(
                    filename, 1) + wait == -1:
                print('quit')
                if len(obj.points) > 0:
                    obj.savePoints()
                return

            wait = wait - 1 if wait > 0 else wait