Exemplo n.º 1
0
def look_for_checkpoints(folder, task):
    dirs = [f for f in listdir(folder) if isdir(join(folder, f))]

    for d in dirs:
        # print(join(folder, d))
        if d == task or (d in ['kp', 'ori', 'desc', 'joint']
                         and task == 'all'):
            cp = tf.train.latest_checkpoint(join(folder, d))
            if cp is not None:
                # Load best validation result
                r = loadh5(join(folder, d, 'best_val_loss.h5'))[d]
                s = loadh5(join(folder, d, 'step.h5'))[d]
                print('{0:s} -> {1:.05f} [{2:d}]'.format(
                    join(folder, d), r, s))
        else:
            look_for_checkpoints(join(folder, d), task)
Exemplo n.º 2
0
            lift_dir = v_des_dir
        else:
            print('Error: There is something wrong with the scene name: %s'%scene_name)
            exit(1)
    elif cst.DATA=='hpatches_rot' or cst.DATA=='hpatches_s':
        lift_dir = v_des_dir

        
    img0_fn = os.path.join(cst.DATA_DIR, scene_name,'%d.ppm'%1)
    print('img_fn: %s'%img0_fn)
    img0 = cv2.imread(img0_fn)
    old_size0 = (img0.shape[1], img0.shape[0])
    if args.resize==1:
        img0 = cv2.resize(img0, new_size, interpolation=cv2.INTER_LINEAR)
    lift_out0_fn = os.path.join(lift_dir, scene_name, '%d.h5'%1)
    lift_out0 = loadh5(lift_out0_fn)

    # detection and description
    kp0 = []
    for line in lift_out0['keypoints'][:args.max_num_feat,:]:
        kp = cv2.KeyPoint(x=line[0],y=line[1], _size=2,
                _angle=0, _response=0, _octave=0, _class_id=0)
        kp0.append(kp)
    des0 = lift_out0['descriptors'][:args.max_num_feat,:]

    # draw kp on img
    kp_on_img0 = cv2.cvtColor(img0, cv2.COLOR_BGR2GRAY)
    kp_on_img0 = np.tile(np.expand_dims(kp_on_img0,2), (1,1,3))
    for i,kp in enumerate(kp0):
        pt = (int(round(kp.pt[0])), int(round(kp.pt[1])))
        cv2.circle(kp_on_img0, pt, 1, (0, 255, 0), -1, lineType=16)
Exemplo n.º 3
0
    img_dir = os.path.join(cst.DATA_DIR, scene_name, 'test/image_color')
    img_list = os.listdir(img_dir)

    # get 1st img, (resize it), convert to BW
    img0_fn = os.path.join(cst.DATA_DIR, scene_name, 'test/image_color/',
                           img_list[0])
    root_fn = img_list[0].split(".")[0]
    #print('img_fn: %s'%img0_fn)
    img0 = cv2.imread(img0_fn)
    old_size0 = (img0.shape[1], img0.shape[0])
    if args.resize == 1:
        img0 = cv2.resize(img0, new_size, interpolation=cv2.INTER_LINEAR)

    # raw sift on img 1
    lift_out_fn = os.path.join(lift_dir, scene_name, root_fn + '.h5')
    lift_out = loadh5(lift_out_fn)
    kp0 = []
    for line in lift_out['keypoints'][:args.max_num_feat, :]:
        kp = cv2.KeyPoint(x=line[0],
                          y=line[1],
                          _size=2,
                          _angle=0,
                          _response=0,
                          _octave=0,
                          _class_id=0)
        kp0.append(kp)
    des0 = lift_out['descriptors'][:args.max_num_feat, :]
    print(des0.shape)

    kp_on_img0 = cv2.cvtColor(img0, cv2.COLOR_BGR2GRAY)
    kp_on_img0 = np.tile(np.expand_dims(kp_on_img0, 2), (1, 1, 3))