예제 #1
0
def parse_multi_file(filen, ret=None, groundtruth=None):
    file = open(filen, "r")
    if ret == None:
        ret = DataSetMulti()
    if drop_neg:
        negs_files = [f[:f.rfind(".")] for f in os.listdir(negs)]
    i = 0
    for line in file:
        line = line.strip().rstrip()
        splited = line.split()
        filename = splited[0]
        # filename = filename[filename.rfind("/")+1:]
        # filename = filename[:filename.rfind(".")]
        if drop_neg:
            if filename in negs_files:
                continue
        height = int(splited[1])
        width = int(splited[2])
        class_id = int(splited[3])
        (confidence, x, y, x2, y2) = tuple([float(a) for a in splited[4:]])
        if hratio != None:
            height = y2 - y
            height2 = height * hratio
            y += (height - height2) / 2.0
            y2 = y + height2
        if wratio != None:
            width = x2 - x
            width2 = width * wratio
            x += (width - width2) / 2.0
            x2 = x + width2
        if whratio != None:
            height = y2 - y
            width = x2 - x
            width2 = height * whratio
            x += (width - width2) / 2.0
            x2 = x + width2
        bb = BoundingBox(x, y, x2, y2, confidence)
        if groundtruth != None:
            img = groundtruth[filename]
            if img == []:
                print "warning: " + filename + " not found in groundtruth."
                continue
            # r = bb.area() / (img.height * img.width)
            # if (min_area_ratio != None and r < min_area_ratio) or \
            #     (max_area_ratio != None and r > max_area_ratio):
            #     print "not adding ratio " + str(r)
            #     continue
        area = bb.area()
        if (min_area == None or area >= min_area) and \
                (max_area == None or area <= max_area):
            ret.add_obj(confidence, filename, bb)
            i = i + 1
    file.close()
    return ret
예제 #2
0
def parse_multi_file(filen, ret = None, groundtruth = None):
    file = open(filen, "r")
    if ret == None:
        ret = DataSetMulti()
    if drop_neg:
        negs_files = [f[:f.rfind(".")] for f in os.listdir(negs)]
    i = 0
    for line in file:
        line = line.strip().rstrip()
        splited = line.split()
        filename = splited[0]
        # filename = filename[filename.rfind("/")+1:]
        # filename = filename[:filename.rfind(".")]
        if drop_neg:
            if filename in negs_files:
                continue
        height = int(splited[1])
        width = int(splited[2])
        class_id = int(splited[3])
        (confidence, x, y, x2, y2) = tuple([float(a) for a in splited[4:]])
        if hratio != None:
            height = y2 - y
            height2 = height * hratio
            y += (height - height2) / 2.0
            y2 = y + height2
        if wratio != None:
            width = x2 - x
            width2 = width * wratio
            x += (width - width2) / 2.0
            x2 = x + width2
        if whratio != None:
            height = y2 - y
            width = x2 - x
            width2 = height * whratio
            x += (width - width2) / 2.0
            x2 = x + width2
        bb = BoundingBox(x, y, x2, y2, confidence)
        if groundtruth != None:
            img = groundtruth[filename]
            if img == []:
                print "warning: " + filename + " not found in groundtruth."
                continue ;
            # r = bb.area() / (img.height * img.width)
            # if (min_area_ratio != None and r < min_area_ratio) or \
            #     (max_area_ratio != None and r > max_area_ratio):
            #     print "not adding ratio " + str(r)
            #     continue            
        area = bb.area()
        if (min_area == None or area >= min_area) and \
                (max_area == None or area <= max_area):
            ret.add_obj(confidence, filename, bb)
            i = i + 1
    file.close()
    return ret
예제 #3
0
def parse(filen, crawl=False):
    file = open(filen, "r")
    ret = DataSet()
    for line in file:
        line = line.strip().rstrip()
        splited = line.split()
        filename = splited[0]
        # filename = filename[filename.rfind("/")+1:]
        # filename = filename[:filename.rfind(".")]
        height = int(splited[1])
        width = int(splited[2])
        class_id = int(splited[3])
        (confidence, x, y, x2, y2) = tuple([float(a) for a in splited[4:]])
        #if confidence > parse_confidence_min: #TODO
        if hratio != None:
            height = y2 - y
            height2 = height * hratio
            y += (height - height2) / 2.0
            y2 = y + height2
        if wratio != None:
            width = x2 - x
            width2 = width * wratio
            x += (width - width2) / 2.0
            x2 = x + width2
        if whratio != None:
            height = y2 - y
            width = x2 - x
            width2 = height * whratio
            x += (width - width2) / 2.0
            x2 = x + width2
        bb = BoundingBox(x, y, x2, y2)
        area = bb.area()
        if (min_area == None or area >= min_area) and \
                (max_area == None or area <= max_area):
            ret.add_obj(filename, bb)
    file.close()
    # print summary
    print 'Dataset ' + str(filen) + ' has ' + str(len(ret)) + ' images and ' \
          + str(ret.get_nobjs()) + ' positive objects.'
    return ret
예제 #4
0
def parse(filen, crawl = False):
    file = open(filen, "r")
    ret = DataSet()
    for line in file:
        line = line.strip().rstrip()
        splited = line.split()
        filename = splited[0]
        # filename = filename[filename.rfind("/")+1:]
        # filename = filename[:filename.rfind(".")]
        height = int(splited[1])
        width = int(splited[2])
        class_id = int(splited[3])
        (confidence, x, y, x2, y2) = tuple([float(a) for a in splited[4:]])
        #if confidence > parse_confidence_min: #TODO
        if hratio != None:
            height = y2 - y
            height2 = height * hratio
            y += (height - height2) / 2.0
            y2 = y + height2
        if wratio != None:
            width = x2 - x
            width2 = width * wratio
            x += (width - width2) / 2.0
            x2 = x + width2
        if whratio != None:
            height = y2 - y
            width = x2 - x
            width2 = height * whratio
            x += (width - width2) / 2.0
            x2 = x + width2
        bb = BoundingBox(x, y, x2, y2)
        area = bb.area()
        if (min_area == None or area >= min_area) and \
                (max_area == None or area <= max_area):
            ret.add_obj(filename, bb)
    file.close()
    # print summary
    print 'Dataset ' + str(filen) + ' has ' + str(len(ret)) + ' images and ' \
          + str(ret.get_nobjs()) + ' positive objects.'
    return ret