def baseline_vsone_ratio_matcher_(kpts1, vecs1, kpts2, vecs2, dlen_sqrd2, cfgdict={}): r""" Args: vecs1 (ndarray[uint8_t, ndim=2]): SIFT descriptors vecs2 (ndarray[uint8_t, ndim=2]): SIFT descriptors kpts1 (ndarray[float32_t, ndim=2]): keypoints kpts2 (ndarray[float32_t, ndim=2]): keypoints Ignore: %pylab qt4 import plottool as pt pt.imshow(rchip1) pt.draw_kpts2(kpts1) pt.show_chipmatch2(rchip1, rchip2, kpts1, kpts2, fm=fm, fs=fs) pt.show_chipmatch2(rchip1, rchip2, kpts1, kpts2, fm=fm, fs=fs) """ #import vtool as vt sver_xy_thresh = cfgdict.get('sver_xy_thresh', .01) ratio_thresh = cfgdict.get('ratio_thresh', .625) #ratio_thresh = .99 # GET NEAREST NEIGHBORS fx2_to_fx1, fx2_to_dist = assign_nearest_neighbors(vecs1, vecs2, K=2) assigntup = matching.assign_unconstrained_matches(fx2_to_fx1, fx2_to_dist) fx2_match, fx1_match, fx1_norm, match_dist, norm_dist = assigntup fm_ORIG = np.vstack((fx1_match, fx2_match)).T fs_ORIG = 1 - np.divide(match_dist, norm_dist) # APPLY RATIO TEST fm_RAT, fs_RAT, fm_norm_RAT = matching.ratio_test(fx2_match, fx1_match, fx1_norm, match_dist, norm_dist, ratio_thresh) # SPATIAL VERIFICATION FILTER #with ut.EmbedOnException(): match_weights = np.ones(len(fm_RAT)) svtup = sver.spatially_verify_kpts(kpts1, kpts2, fm_RAT, sver_xy_thresh, dlen_sqrd2, match_weights=match_weights) if svtup is not None: (homog_inliers, homog_errors, H_RAT) = svtup[0:3] else: H_RAT = np.eye(3) homog_inliers = [] fm_SV = fm_RAT[homog_inliers] fs_SV = fs_RAT[homog_inliers] fm_norm_SV = fm_norm_RAT[homog_inliers] base_tup = (fm_ORIG, fs_ORIG, fm_RAT, fs_RAT, fm_SV, fs_SV, H_RAT) base_meta = (fm_norm_RAT, fm_norm_SV) return base_tup, base_meta
def spatially_constrianed_matcher_(kpts1, vecs1, kpts2, vecs2, dlen_sqrd2, H_RAT, cfgdict={}): # import vtool as vt # match_xy_thresh = .1 # sver_xy_thresh = .01 # ratio_thresh2 = .8 # Observation, scores don't change above K=7 # on easy test case # search_K = 7 # 3 search_K = cfgdict.get("search_K", 7) ratio_thresh2 = cfgdict.get("ratio_thresh2", 0.8) sver_xy_thresh2 = cfgdict.get("sver_xy_thresh2", 0.01) normalizer_mode = cfgdict.get("normalizer_mode", "far") match_xy_thresh = cfgdict.get("match_xy_thresh", 0.1) # ASSIGN CANDIDATES # Get candidate nearest neighbors fx2_to_fx1, fx2_to_dist = assign_nearest_neighbors(vecs1, vecs2, K=search_K) # COMPUTE CONSTRAINTS # normalizer_mode = 'far' constrain_tup = spatially_constrain_matches( dlen_sqrd2, kpts1, kpts2, H_RAT, fx2_to_fx1, fx2_to_dist, match_xy_thresh, normalizer_mode=normalizer_mode ) (fm_SC, fm_norm_SC, match_dist, norm_dist) = constrain_tup fx2_match = fm_SC.T[1] fx1_match = fm_SC.T[1] fx1_norm = fm_norm_SC.T[1] fm_SCR, fs_SCR, fm_norm_SCR = matching.ratio_test( fx2_match, fx1_match, fx1_norm, match_dist, norm_dist, ratio_thresh2 ) fs_SC = 1 - np.divide(match_dist, norm_dist) # NOQA # fm_SCR, fs_SCR, fm_norm_SCR = ratio_test2(match_dist, norm_dist, fm_SC, # fm_norm_SC, ratio_thresh2) # Another round of verification match_weights = np.ones(len(fm_SCR)) svtup = sver.spatially_verify_kpts(kpts1, kpts2, fm_SCR, sver_xy_thresh2, dlen_sqrd2, match_weights=match_weights) if svtup is not None: (homog_inliers, homog_errors, H_SCR) = svtup[0:3] else: H_SCR = np.eye(3) homog_inliers = [] fm_SCRSV = fm_SCR[homog_inliers] fs_SCRSV = fs_SCR[homog_inliers] fm_norm_SVSCR = fm_norm_SCR[homog_inliers] nexttup = (fm_SC, fs_SC, fm_SCR, fs_SCR, fm_SCRSV, fs_SCRSV, H_SCR) next_meta = (fm_norm_SC, fm_norm_SCR, fm_norm_SVSCR) return nexttup, next_meta
def baseline_vsone_ratio_matcher_(kpts1, vecs1, kpts2, vecs2, dlen_sqrd2, cfgdict={}): r""" Args: vecs1 (ndarray[uint8_t, ndim=2]): SIFT descriptors vecs2 (ndarray[uint8_t, ndim=2]): SIFT descriptors kpts1 (ndarray[float32_t, ndim=2]): keypoints kpts2 (ndarray[float32_t, ndim=2]): keypoints Ignore: %pylab qt4 import plottool as pt pt.imshow(rchip1) pt.draw_kpts2(kpts1) pt.show_chipmatch2(rchip1, rchip2, kpts1, kpts2, fm=fm, fs=fs) pt.show_chipmatch2(rchip1, rchip2, kpts1, kpts2, fm=fm, fs=fs) """ # import vtool as vt sver_xy_thresh = cfgdict.get("sver_xy_thresh", 0.01) ratio_thresh = cfgdict.get("ratio_thresh", 0.625) # ratio_thresh = .99 # GET NEAREST NEIGHBORS fx2_to_fx1, fx2_to_dist = assign_nearest_neighbors(vecs1, vecs2, K=2) assigntup = matching.assign_unconstrained_matches(fx2_to_fx1, fx2_to_dist) fx2_match, fx1_match, fx1_norm, match_dist, norm_dist = assigntup fm_ORIG = np.vstack((fx1_match, fx2_match)).T fs_ORIG = 1 - np.divide(match_dist, norm_dist) # APPLY RATIO TEST fm_RAT, fs_RAT, fm_norm_RAT = matching.ratio_test( fx2_match, fx1_match, fx1_norm, match_dist, norm_dist, ratio_thresh ) # SPATIAL VERIFICATION FILTER # with ut.EmbedOnException(): match_weights = np.ones(len(fm_RAT)) svtup = sver.spatially_verify_kpts(kpts1, kpts2, fm_RAT, sver_xy_thresh, dlen_sqrd2, match_weights=match_weights) if svtup is not None: (homog_inliers, homog_errors, H_RAT) = svtup[0:3] else: H_RAT = np.eye(3) homog_inliers = [] fm_SV = fm_RAT[homog_inliers] fs_SV = fs_RAT[homog_inliers] fm_norm_SV = fm_norm_RAT[homog_inliers] base_tup = (fm_ORIG, fs_ORIG, fm_RAT, fs_RAT, fm_SV, fs_SV, H_RAT) base_meta = (fm_norm_RAT, fm_norm_SV) return base_tup, base_meta
def spatially_constrianed_matcher_(kpts1, vecs1, kpts2, vecs2, dlen_sqrd2, H_RAT, cfgdict={}): #import vtool as vt #match_xy_thresh = .1 #sver_xy_thresh = .01 #ratio_thresh2 = .8 # Observation, scores don't change above K=7 # on easy test case #search_K = 7 # 3 search_K = cfgdict.get('search_K', 7) ratio_thresh2 = cfgdict.get('ratio_thresh2', .8) sver_xy_thresh2 = cfgdict.get('sver_xy_thresh2', .01) normalizer_mode = cfgdict.get('normalizer_mode', 'far') match_xy_thresh = cfgdict.get('match_xy_thresh', .1) # ASSIGN CANDIDATES # Get candidate nearest neighbors fx2_to_fx1, fx2_to_dist = assign_nearest_neighbors(vecs1, vecs2, K=search_K) # COMPUTE CONSTRAINTS #normalizer_mode = 'far' constrain_tup = spatially_constrain_matches( dlen_sqrd2, kpts1, kpts2, H_RAT, fx2_to_fx1, fx2_to_dist, match_xy_thresh, normalizer_mode=normalizer_mode) (fm_SC, fm_norm_SC, match_dist, norm_dist) = constrain_tup fx2_match = fm_SC.T[1] fx1_match = fm_SC.T[1] fx1_norm = fm_norm_SC.T[1] fm_SCR, fs_SCR, fm_norm_SCR = matching.ratio_test(fx2_match, fx1_match, fx1_norm, match_dist, norm_dist, ratio_thresh2) fs_SC = 1 - np.divide(match_dist, norm_dist) # NOQA #fm_SCR, fs_SCR, fm_norm_SCR = ratio_test2(match_dist, norm_dist, fm_SC, # fm_norm_SC, ratio_thresh2) # Another round of verification match_weights = np.ones(len(fm_SCR)) svtup = sver.spatially_verify_kpts(kpts1, kpts2, fm_SCR, sver_xy_thresh2, dlen_sqrd2, match_weights=match_weights) if svtup is not None: (homog_inliers, homog_errors, H_SCR) = svtup[0:3] else: H_SCR = np.eye(3) homog_inliers = [] fm_SCRSV = fm_SCR[homog_inliers] fs_SCRSV = fs_SCR[homog_inliers] fm_norm_SVSCR = fm_norm_SCR[homog_inliers] nexttup = (fm_SC, fs_SC, fm_SCR, fs_SCR, fm_SCRSV, fs_SCRSV, H_SCR) next_meta = (fm_norm_SC, fm_norm_SCR, fm_norm_SVSCR) return nexttup, next_meta