Esempio n. 1
0
def TEST_DELETE_IMAGE(ibs, back):
    gpath_list = grabdata.get_test_gpaths(ndata=None)[0:4]
    gid_list = ibs.add_images(gpath_list)
    bbox_list = [(0, 0, 100, 100)] * len(gid_list)
    name_list = ['a', 'b', 'a', 'd']
    aid_list = ibs.add_annots(gid_list, bbox_list=bbox_list, name_list=name_list)
    gid = gid_list[0]
    assert gid is not None, "gid is None"
    aid_list = ibs.get_image_aids(gid)
    assert len(aid_list) == 1, "Length of aid_list=%r" % (len(aid_list),)
    aid = aid_list[0]
    assert aid is not None, "aid is None"
    cid = ibs.get_annot_cids(aid, ensure=False)
    fid = ibs.get_annot_fids(aid, ensure=False)
    assert cid is None, "cid=%r should be None" % (cid,)
    assert fid is None, "fid=%r should be None" % (fid,)
    cid = ibs.get_annot_cids(aid, ensure=True)
    fid = ibs.get_annot_fids(aid, ensure=True)
    assert cid is not None, "cid should be computed"
    assert fid is not None, "fid should be computed"
    gthumbpath = ibs.get_image_thumbpath(gid)
    athumbpath = ibs.get_annot_chip_thumbpath(aid)
    ibs.delete_images(gid)
    all_gids = ibs.get_valid_gids()
    all_aids = ibs.get_valid_aids()
    all_cids = ibs.get_valid_cids()
    all_fids = ibs.get_valid_fids()
    assert gid not in all_gids, "gid still exists"
    assert aid not in all_aids, "rid %r still exists" % aid
    assert fid not in all_fids, "fid %r still exists" % fid
    assert cid not in all_cids, "cid %r still exists" % cid
    assert not utool.checkpath(gthumbpath), "Thumbnail still exists"
    assert not utool.checkpath(athumbpath), "ANNOTATION Thumbnail still exists"
    return locals()
Esempio n. 2
0
def TEST_DELETE_ANNOTATION(ibs, back):
    gpath_list = grabdata.get_test_gpaths(ndata=None)[0:4]
    gid_list = ibs.add_images(gpath_list)
    bbox_list = [(0, 0, 100, 100)] * len(gid_list)
    name_list = ['a', 'b', 'a', 'd']
    aid_list = ibs.add_annots(gid_list, bbox_list=bbox_list, name_list=name_list)
    aid = aid_list[0]
    assert aid is not None, "aid is None"
    cid = ibs.get_annot_cids(aid, ensure=False)
    fid = ibs.get_annot_fids(aid, ensure=False)
    assert cid is None, "cid should be None"
    assert fid is None, "fid should be None"
    cid = ibs.get_annot_cids(aid, ensure=True)
    fid = ibs.get_annot_fids(aid, ensure=True)
    assert cid is not None, "cid should be computed"
    assert fid is not None, "fid should be computed"
    thumbpath = ibs.get_annot_chip_thumbpath(aid)
    ibs.delete_annots(aid)
    aid_list = ibs.get_valid_aids()
    cid_list = ibs.get_valid_cids()
    fid_list = ibs.get_valid_fids()
    assert aid not in aid_list, "RID still exists"
    assert cid not in cid_list, "CID still exists"
    assert fid not in fid_list, "FID still exists"
    assert not utool.checkpath(thumbpath), "Thumbnail still exists"
    return locals()
Esempio n. 3
0
def MAKE_BIG_DB():
    workdir = sysres.get_workdir()
    dbname = 'testdb_big'
    dbdir  = join(workdir, dbname)
    utool.delete(dbdir)

    main_locals = ibeis.main(dbdir=dbdir, gui=False)
    ibs = main_locals['ibs']    # IBEIS Control
    gpath_list = grabdata.get_test_gpaths(ndata=1)

    imgdir = get_big_imgdir(workdir)
    gname_list = utool.list_images(imgdir, recursive=True)
    gpath_list = [join(imgdir, gname) for gname in gname_list]
    gpath_list = gpath_list

    assert all(map(exists, gpath_list)), 'some images dont exist'

    #nImages = len(gpath_list)
    #with utool.Timer('Add %d Images' % nImages):
    gid_list = ibs.add_images(gpath_list)

    #with utool.Timer('Convert %d Images to annotations' % nImages):
    aid_list = ibsfuncs.use_images_as_annotations(ibs, gid_list)

    #with utool.Timer('Compute %d chips' % nImages):
    cid_list = ibs.add_chips(aid_list)

    #with utool.Timer('Compute %d features' % nImages):
    fid_list = ibs.add_feats(cid_list)

    #with utool.Timer('Getting %d nFeats' % nImages):
    nFeats_list = ibs.get_num_feats(fid_list)

    print('Total number of features in the database: %r' % sum(nFeats_list))
    return locals()
Esempio n. 4
0
def TEST_GUI_IMPORT_IMAGES(ibs, back):
    print('[TEST] GET_TEST_IMAGE_PATHS')
    # The test api returns a list of interesting chip indexes
    mode = 'FILE'
    if mode == 'FILE':
        gpath_list = map(utool.unixpath, grabdata.get_test_gpaths())

        # else:
        #    dir_ = utool.truepath(join(sysres.get_workdir(), 'PZ_MOTHERS/images'))
        #    gpath_list = utool.list_images(dir_, fullpath=True, recursive=True)[::4]
        print('[TEST] IMPORT IMAGES FROM FILE\n * gpath_list=%r' % gpath_list)
        gid_list = back.import_images(gpath_list=gpath_list)
        thumbtup_list = ibs.get_image_thumbtup(gid_list)
        imgpath_list = [tup[1] for tup in thumbtup_list]
        gpath_list2 = ibs.get_image_paths(gid_list)
        for path in gpath_list2:
            assert path in imgpath_list, "Imported Image not in db, path=%r" % path
    elif mode == 'DIR':
        dir_ = grabdata.get_testdata_dir()
        print('[TEST] IMPORT IMAGES FROM DIR\n * dir_=%r' % dir_)
        gid_list = back.import_images(dir_=dir_)
    else:
        raise AssertionError('unknown mode=%r' % mode)

    print('[TEST] * len(gid_list)=%r' % len(gid_list))
    return locals()
Esempio n. 5
0
def TEST_PIL_HASH():
    print('[TEST] GET_TEST_IMAGE_PATHS')
    # The test api returns a list of interesting chip indexes
    gpath_list = grabdata.get_test_gpaths(ndata=None)
    pil_img_list = [Image.open(gpath, 'r') for gpath in gpath_list]
    uuid_list = [preproc_image.get_image_uuid(pil_img) for pil_img in pil_img_list]
    unique_uuid_list = list(set(uuid_list))
    assert len(uuid_list) == len(unique_uuid_list), 'Reinstall PIL, watch for libjpeg'
    return locals()
Esempio n. 6
0
def TEST_ADD_IMAGES(ibs):
    print('[TEST] GET_TEST_IMAGE_PATHS')
    # The test api returns a list of interesting chip indexes
    gpath_list = grabdata.get_test_gpaths(ndata=None)

    print('[TEST] IMPORT IMAGES FROM FILE\ngpath_list=%r' % gpath_list)
    gid_list = ibs.add_images(gpath_list)
    valid_gpaths = list(ibs.get_image_paths(gid_list))
    print('[TEST] valid_gpaths=%r' % valid_gpaths)
    return locals()
Esempio n. 7
0
def TEST_IBS(ibs):
    gpath_list = grabdata.get_test_gpaths(ndata=2)

    print('[TEST] 1.ibs.add_images(gpath_list=%r)' % gpath_list)
    gid_list = ibs.add_images(gpath_list)
    print(' * gid_list=%r' % gid_list)

    print('[TEST] 2. ibs.get_image_paths(gid_list)')
    gpaths_list = ibs.get_image_paths(gid_list)
    print(' * gpaths_list=%r' % gpaths_list)

    print('[TEST] 3. get_image_props')
    uri_list   = ibs.get_image_uris(gid_list)
    path_list  = ibs.get_image_paths(gid_list)
    gsize_list = ibs.get_image_sizes(gid_list)
    time_list  = ibs.get_image_unixtime(gid_list)
    gps_list   = ibs.get_image_gps(gid_list)
    print(' * uri_list=%r' % uri_list)
    print(' * path_list=%r' % path_list)
    print(' * gsize_list=%r' % gsize_list)
    print(' * time_list=%r' % time_list)
    print(' * gps_list=%r' % gps_list)

    print('[TEST] 4. get_image_props')
    mult_cols_list = ibs.db.get('images', ('image_uri', 'image_width', 'image_height'), gid_list)
    print(' * gps_list=%r' % mult_cols_list)

    print('[TEST] 5. add_annots')
    gid = gid_list[0]
    gid_list = [gid, gid]
    bbox_list = [(50, 50, 100, 100), (75, 75, 102, 101)]
    theta_list = [0, 1.1]
    nid_list = None
    name_list = None
    notes_list = None
    aid_list = ibs.add_annots(gid_list, bbox_list, theta_list=theta_list,
                              nid_list=nid_list, name_list=name_list,
                              notes_list=notes_list)
    print(' * aid_list=%r' % aid_list)

    print('[TEST] 6. get_annot_props')
    gid_list    = ibs.get_annot_gids(aid_list)
    bbox_list   = ibs.get_annot_bboxes(aid_list)
    theta_list  = ibs.get_annot_thetas(aid_list)
    aids_list   = ibs.get_image_aids(gid)
    print(' * gid_list=%r' % gid_list)
    print(' * bbox_list=%r' % bbox_list)
    print(' * theta_list=%r' % theta_list)
    print(' * aids_list=%r' % aids_list)
    assert len(bbox_list) == len(theta_list), "len(bbox_list) != len(theta_list)"
    assert len(theta_list) == len(aid_list), "len(theta_list) != len(aid_list)"

    viz.show_image(ibs, gid)
    return locals()
Esempio n. 8
0
def TEST_DELETE_FEATURE(ibs, back):
    gpath_list = grabdata.get_test_gpaths(ndata=None)[0:4]
    gid_list = ibs.add_images(gpath_list)
    bbox_list = [(0, 0, 100, 100)] * len(gid_list)
    name_list = ['a', 'b', 'a', 'd']
    aid_list = ibs.add_annots(gid_list, bbox_list=bbox_list, name_list=name_list)
    cid_list = ibs.add_annot_chips(aid_list)
    assert len(cid_list) != 0, "No chips added"
    fid_list = ibs.add_chip_feat(cid_list)
    assert len(fid_list) != 0, "No features added"
    fid = fid_list[0]
    ibs.delete_features(fid)
    fid_list = ibs.get_valid_fids()
    assert fid not in fid_list, "FID not deleted"
    return locals()
def TEST_DELETE_IMAGE_THUMBTUPS(ibs, back):
    gpath_list = grabdata.get_test_gpaths(ndata=None)[0:4]
    gid_list = ibs.add_images(gpath_list)
    bbox_list = [(0, 0, 100, 100)]*len(gid_list)
    name_list = ['a', 'b', 'a', 'd']
    aid_list = ibs.add_annots(gid_list, bbox_list=bbox_list, name_list=name_list)
    assert len(aid_list) !=0, "No annotations added"
    thumbpath_list = ibs.get_image_thumbpath(gid_list)
    gpath_list = ibs.get_image_paths(gid_list)
    ibs.delete_image_thumbtups(gid_list)
    assert utool.is_list(thumbpath_list), "thumbpath_list is not a list"
    assert utool.is_list(gpath_list), "gpath_list is not a list"
    for path in thumbpath_list:
        assert not utool.checkpath(path), "Thumbnail not deleted"
    for path in gpath_list:
        utool.assertpath(path)
    return locals()
def TEST_DELETE_ANNOTATION_CHIPS(ibs, back):
    gpath_list = grabdata.get_test_gpaths(ndata=None)[0:4]
    gid_list = ibs.add_images(gpath_list)
    bbox_list = [(0, 0, 100, 100)] * len(gid_list)
    name_list = ['a', 'b', 'a', 'd']
    aid_list = ibs.add_annots(gid_list, bbox_list=bbox_list, name_list=name_list)
    assert len(aid_list) != 0, "No annotations"
    aid = aid_list[0]
    gid = ibs.get_annot_gids(aid)
    assert gid is not None, "gid for aid=%r is None" % (aid,)
    gthumbpath = ibs.get_image_thumbpath(gid)
    annotation_thumbpath = ibs.get_annot_chip_thumbpath(aid)
    ibs.delete_annot_chips(aid)
    aid_list = ibs.get_valid_aids()
    assert aid in aid_list, "Error: Annotation deleted"
    assert not utool.checkpath(gthumbpath), "Image Thumbnail not deleted"
    assert not utool.checkpath(annotation_thumbpath), "Roi Thumbnail not deleted"
    return locals()
Esempio n. 11
0
def TEST_DELETE_CHIPS(ibs, back):
    gpath_list = grabdata.get_test_gpaths(ndata=None)[0:4]
    gid_list = ibs.add_images(gpath_list)
    bbox_list = [(0, 0, 100, 100)] * len(gid_list)
    name_list = ['a', 'b', 'a', 'd']
    aid_list = ibs.add_annots(gid_list, bbox_list=bbox_list, name_list=name_list)
    cid_list = ibs.add_annot_chips(aid_list)
    cid = cid_list[0]
    _fid = ibs.get_chip_feat_rowid(cid, ensure=False)
    assert _fid is None, "_fid=%r should be None" % (_fid,)
    _fid = ibs.get_chip_feat_rowid(cid, ensure=True)
    assert _fid is not None, "_fid=%r should be computed" % (_fid,)
    ibs.delete_chips(cid)
    cid_list = ibs.get_valid_cids()
    assert cid not in cid_list, "CID not deleted"
    all_fids = ibs.get_valid_fids()
    assert _fid not in all_fids, "FID not deleted"
    return locals()
Esempio n. 12
0
def TEST_PARALLEL():
    gpath_list = grabdata.get_test_gpaths(ndata=10, names=['zebra', 'lena', 'jeff'])
    args_list  = [(gpath,) for gpath in gpath_list]

    @utool.argv_flag_dec
    def print_test_results(result_list):
        for kpts, desc in result_list:
            print('[test] kpts.shape=(%4d, %d), desc.sum=%8d' % (kpts.shape[0],
                                                                 kpts.shape[1],
                                                                 desc.sum()))

    hesaff_kwargs = {
        'scale_min': -1,
        'scale_max': -1,
        'nogravity_hack': False
    }

    with utool.Timer('c++ parallel'):
        kpts_list, desc_list = pyhesaff.detect_kpts_list(gpath_list, **hesaff_kwargs)

    # Run parallel tasks
    @utool.indent_func('[test_task]')
    def run_parallel_task(num_procs=None):
        print('run_parallel_task. num_procs=%r' % None)
        if num_procs is not None:
            util_parallel.close_pool()
            util_parallel.init_pool(num_procs)
        else:
            num_procs = util_parallel.get_default_numprocs()
        msg = 'processing tasks in %s' % ('serial' if num_procs == 1 else
                                          str(num_procs) + '-parallel')
        with utool.Timer(msg):
            result_list = util_parallel.process(pyhesaff.detect_kpts, args_list, hesaff_kwargs)
        print_test_results(result_list)
        return result_list
    run_parallel_task()

    # Compare to serial if needed
    @utool.argv_flag_dec
    def compare_serial():
        print('compare_serial')
        run_parallel_task(1)
    compare_serial()
    return locals()
Esempio n. 13
0
def make_testdb0():
    main_locals = ibeis.main(dbdir=TESTDB0, gui=False, allow_newdir=True)
    ibs = main_locals['ibs']
    assert ibs is not None, str(main_locals)
    gpath_list = map(utool.unixpath, grabdata.get_test_gpaths())
    #print('[RESET] gpath_list=%r' % gpath_list)
    gid_list = ibs.add_images(gpath_list)  # NOQA
    valid_gids = ibs.get_valid_gids()
    valid_aids = ibs.get_valid_aids()
    try:
        assert len(valid_aids) == 0, 'there are more than 0 annotations in an empty database!'
    except Exception as ex:
        utool.printex(ex, key_list=['valid_aids'])
        raise
    gid_list = valid_gids[0:1]
    bbox_list = [(0, 0, 100, 100)]
    aid = ibs.add_annots(gid_list, bbox_list=bbox_list)[0]
    #print('[RESET] NEW RID=%r' % aid)
    aids = ibs.get_image_aids(gid_list)[0]
    try:
        assert aid in aids, ('bad annotation adder: aid = %r, aids = %r' % (aid, aids))
    except Exception as ex:
        utool.printex(ex, key_list=['aid', 'aids'])
        raise
Esempio n. 14
0
        assert bbox_list[0] == (50, 50, 100, 100)
    except AssertionError as ex:
        utool.printex(ex, key_list=['bbox_list', 'aid_list'])
        raise
    back.reselect_annotation(bbox=[51, 52, 103, 104])
    assert ibs.get_annot_bboxes(aid_list[0]) == (51, 52, 103, 104)

    back.compute_encounters()

    unixtime_list = [100, 23, 24]
    ibs.set_image_unixtime(gid_list, unixtime_list)

    back.compute_encounters()

    # Change some ANNOTATIONs

    #add_annot(gid_list[2], None)  # user selection
    #add_annot(None, [42, 42, 8, 8])  # back selection
    # I'm not sure how I want to integrate that IPython stuff
    return locals()

if __name__ == '__main__':
    multiprocessing.freeze_support()  # For windows
    main_locals = ibeis.main(defaultdb='testdb0', gui=True)
    gpath_list = grabdata.get_test_gpaths(names=['lena', 'zebra', 'jeff'])
    ibs  = main_locals['ibs']   # IBEIS Control
    back = main_locals['back']  # IBEIS GUI backend
    test_locals = utool.run_test(TEST_GUI_ALL, ibs, back, gpath_list)
    execstr = utool.execstr_dict(test_locals, 'test_locals')
    exec(execstr)