(directory,
                     isGT,
                     bbFormat,
                     coordType,
                     allBoundingBoxes=None,
                     allClasses=None,
                     imgSize=(0, 0))
return allBoundingBoxes, allClasses
Read txt files containing bounding boxes (ground truth and detections).
Read txt files containing bounding boxes (ground truth and detections).
Read txt files containing bounding boxes ( ground truth and detections ) .
def getBoundingBoxes(directory,
                     isGT,
                     bbFormat,
                     coordType,
                     allBoundingBoxes=None,
                     allClasses=None,
                     imgSize=(0, 0)):
    """Read txt files containing bounding boxes (ground truth and detections)."""
    if allBoundingBoxes is None:
        allBoundingBoxes = BoundingBoxes()
    if allClasses is None:
        allClasses = []
    # Read ground truths
    os.chdir(directory)
    files = glob.glob("*.txt")
    files.sort()
    # Read GT detections from txt file
    # Each line of the files in the groundtruths folder represents a ground truth bounding box
    # (bounding boxes that a detector should detect)
    # Each value of each line is  "class_id, x, y, width, height" respectively
    # Class_id represents the class of the bounding box
    # x, y represents the most top-left coordinates of the bounding box
    # x2, y2 represents the most bottom-right coordinates of the bounding box
    for f in files:
        nameOfImage = f.replace(".txt", "")
        fh1 = open(f, "r")
        for line in fh1:
            line = line.replace("\n", "")
            if line.replace(' ', '') == '':
                continue
            splitLine = line.split(" ")
            if isGT:
                # idClass = int(splitLine[0]) #class
                idClass = (splitLine[0])  # class
                x = float(splitLine[1])
                y = float(splitLine[2])
                w = float(splitLine[3])
                h = float(splitLine[4])
                bb = BoundingBox(nameOfImage,
                                 idClass,
                                 x,
                                 y,
                                 w,
                                 h,
                                 coordType,
                                 imgSize,
                                 BBType.GroundTruth,
                                 format=bbFormat)
            else:
                # idClass = int(splitLine[0]) #class
                idClass = (splitLine[0])  # class
                confidence = float(splitLine[1])
                x = float(splitLine[2])
                y = float(splitLine[3])
                w = float(splitLine[4])
                h = float(splitLine[5])
                bb = BoundingBox(nameOfImage,
                                 idClass,
                                 x,
                                 y,
                                 w,
                                 h,
                                 coordType,
                                 imgSize,
                                 BBType.Detected,
                                 confidence,
                                 format=bbFormat)
            allBoundingBoxes.addBoundingBox(bb)
            if idClass not in allClasses:
                allClasses.append(idClass)
        fh1.close()
    return allBoundingBoxes, allClasses
def getBoundingBoxes ( directory , isGT , bbFormat , coordType , allBoundingBoxes = None , allClasses = None , imgSize = ( 0 , 0 ) ) : if allBoundingBoxes is None : allBoundingBoxes = BoundingBoxes ( ) if allClasses is None : allClasses = [ ] # Read ground truths os . chdir ( directory ) files = glob . glob ( "*.txt" ) files . sort ( ) # Read GT detections from txt file # Each line of the files in the groundtruths folder represents a ground truth bounding box # (bounding boxes that a detector should detect) # Each value of each line is  "class_id, x, y, width, height" respectively # Class_id represents the class of the bounding box # x, y represents the most top-left coordinates of the bounding box # x2, y2 represents the most bottom-right coordinates of the bounding box for f in files : nameOfImage = f . replace ( ".txt" , "" ) fh1 = open ( f , "r" ) for line in fh1 : line = line . replace ( "\n" , "" ) if line . replace ( ' ' , '' ) == '' : continue splitLine = line . split ( " " ) if isGT : # idClass = int(splitLine[0]) #class idClass = ( splitLine [ 0 ] ) # class x = float ( splitLine [ 1 ] ) y = float ( splitLine [ 2 ] ) w = float ( splitLine [ 3 ] ) h = float ( splitLine [ 4 ] ) bb = BoundingBox ( nameOfImage , idClass , x , y , w , h , coordType , imgSize , BBType . GroundTruth , format = bbFormat ) else : # idClass = int(splitLine[0]) #class idClass = ( splitLine [ 0 ] ) # class confidence = float ( splitLine [ 1 ] ) x = float ( splitLine [ 2 ] ) y = float ( splitLine [ 3 ] ) w = float ( splitLine [ 4 ] ) h = float ( splitLine [ 5 ] ) bb = BoundingBox ( nameOfImage , idClass , x , y , w , h , coordType , imgSize , BBType . Detected , confidence , format = bbFormat ) allBoundingBoxes . addBoundingBox ( bb ) if idClass not in allClasses : allClasses . append ( idClass ) fh1 . close ( ) return allBoundingBoxes , allClasses