Esempio n. 1
0
def main():
    source_file('data_utils_init.sh')
    img_step = int(os.environ['IMG_STEP'])

    al_file = sys.argv[1]
    annos = al.parse(al_file)
    img_dirs = sorted(sys.argv[2:])
    images = []
    for img_dir in img_dirs:
        images.extend(sorted(glob.glob(img_dir + '/*jpeg'))[::img_step])

    new_annos = []
    anno_idx = 0
    for image in images:
        image_name = u'/'.join(image.split('/')[-2:])
        if anno_idx == len(annos) or image_name != annos[anno_idx].imageName:
            new_anno = al.Annotation()
            new_anno.imageName = image_name
        else:
            new_anno = annos[anno_idx]
            anno_idx += 1
        new_annos.append(new_anno)

    assert anno_idx == len(annos)
    al.save(sys.argv[1].replace('.al', '.pal'), new_annos)
    if sys.argv[1].find('.al') != -1:
        os.remove(sys.argv[1])
def main():
    source_file('data_utils_init.sh')
    img_step = int(os.environ['IMG_STEP'])

    al_file = sys.argv[1]
    annos = al.parse(al_file)
    img_dirs = sorted(sys.argv[2:])
    images = []
    for img_dir in img_dirs:
        images.extend(sorted(glob.glob(img_dir + '/*jpeg'))[::img_step])

    new_annos = []
    anno_idx = 0
    for image in images:
        image_name = u'/'.join(image.split('/')[-2:])
        if anno_idx == len(annos) or image_name != annos[anno_idx].imageName:
            new_anno = al.Annotation()
            new_anno.imageName = image_name
        else:
            new_anno = annos[anno_idx]
            anno_idx += 1
        new_annos.append(new_anno)

    assert anno_idx == len(annos)
    al.save(sys.argv[1].replace('.al', '.pal'), new_annos)
    if sys.argv[1].find('.al') != -1:
        os.remove(sys.argv[1])
Esempio n. 3
0
def fix_paths(al_file):
    parse = al.parse(al_file)
    for p in parse:
        if len(p.imageName.split('/')) < 2 or len(p.imageName.split('/')[0]) == 0:
            inp = p.imageName.split('/')[-1]
            p.imageName = '_'.join(inp.split('_')[:-1]) + '/' + inp[:inp.find('.jpeg')+5]

    al.save(al_file, parse)
def main():
    """
    This will update a bad al file with a good one, and will overwrite the bad file with the updated images.
    """
    parser = OptionParser()
    parser.add_option('-b', '--bad', dest='bad_file', type='string')
    parser.add_option('-g', '--good', dest='good_file', type='string')
    (opts, _) = parser.parse_args()

    bad = al.parse(opts.bad_file)
    good = al.parse(opts.good_file)

    name2anno = {}
    for g in good:
        name2anno[g.imageName] = g

    fixed = []
    for b in bad:
        fixed.append(name2anno.get(b.imageName, b))

    al.save(opts.bad_file, fixed)
Esempio n. 5
0
def main():
    """
    This will update a bad al file with a good one, and will overwrite the bad file with the updated images.
    """
    parser = OptionParser()
    parser.add_option('-b', '--bad', dest='bad_file', type='string')
    parser.add_option('-g', '--good', dest='good_file', type='string')
    (opts, _) = parser.parse_args()

    bad = al.parse(opts.bad_file)
    good = al.parse(opts.good_file)

    name2anno = {}
    for g in good:
        name2anno[g.imageName] = g

    fixed = []
    for b in bad:
        fixed.append(name2anno.get(b.imageName, b))

    al.save(opts.bad_file, fixed)