def test(hs, qcx):
    fx2_scale = sv2.keypoint_scale(hs.feats.cx2_kpts[qcx])
    fx = fx2_scale.argsort()[::-1][40]
    rchip = hs.get_chip(qcx)
    kp = hs.feats.cx2_kpts[qcx][fx]
    # Show full image and keypoint
    df2.figure(fignum=9000, doclf=True)
    df2.imshow(rchip, plotnum=(1,3,1))
    df2.draw_kpts2([kp], ell_color=(1,0,0), pts=True)
    # Show cropped image and keypoint
    patch, subkp = get_patch(rchip, kp)
    df2.imshow(patch, plotnum=(1,3,2))
    df2.draw_kpts2([subkp], ell_color=(1,0,0), pts=True)
    # Show warped image and keypoint
    wpatch, wkp = get_warped_patch(rchip, kp)
    df2.imshow(wpatch, plotnum=(1,3,3))
    df2.draw_kpts2([wkp], ell_color=(1,0,0), pts=True)
    #
    df2.set_figtitle('warp test')
Beispiel #2
0
    def measure_feat_pairs(allres, orgtype='top_true'):
        print('Measure ' + orgtype + ' pairs')
        orgres = allres.__dict__[orgtype]
        entropy_list = []
        scale_list = []
        score_list = []
        lbl = 'Measuring ' + orgtype + ' pair '
        fmt_str = helpers.make_progress_fmt_str(len(orgres), lbl)
        rank_skips = []
        gt_skips = []
        for ix, (qcx, cx, score, rank) in enumerate(orgres.iter()):
            helpers.print_(fmt_str % (ix + 1,))
            # Skip low ranks
            if rank > 5:
                rank_skips.append(qcx)
                continue
            other_cxs = hs.get_other_indexed_cxs(qcx)
            # Skip no groundtruth
            if len(other_cxs) == 0:
                gt_skips.append(qcx)
                continue
            res = qcx2_res[qcx]
            # Get matching feature indexes
            fm = res.cx2_fm[cx]
            # Get their scores
            fs = res.cx2_fs[cx]
            # Get matching descriptors
            printDBG('\nfm.shape=%r' % (fm.shape,))
            desc1 = cx2_desc[qcx][fm[:, 0]]
            desc2 = cx2_desc[cx][fm[:, 1]]
            # Get matching keypoints
            kpts1 = cx2_kpts[qcx][fm[:, 0]]
            kpts2 = cx2_kpts[cx][fm[:, 1]]
            # Get their scale
            scale1_m = sv2.keypoint_scale(kpts1)
            scale2_m = sv2.keypoint_scale(kpts2)
            # Get their entropy
            entropy1 = descriptor_entropy(desc1, bw_factor=1)
            entropy2 = descriptor_entropy(desc2, bw_factor=1)
            # Append to results
            entropy_tup = np.array(zip(entropy1, entropy2))
            scale_tup   = np.array(zip(scale1_m, scale2_m))
            entropy_tup = entropy_tup.reshape(len(entropy_tup), 2)
            scale_tup   = scale_tup.reshape(len(scale_tup), 2)
            entropy_list.append(entropy_tup)
            scale_list.append(scale_tup)
            score_list.append(fs)
        print('Skipped %d total.' % (len(rank_skips) + len(gt_skips),))
        print('Skipped %d for rank > 5, %d for no gt' % (len(rank_skips), len(gt_skips),))
        print(np.unique(map(len, entropy_list)))

        def evstack(tup):
            return np.vstack(tup) if len(tup) > 0 else np.empty((0, 2))

        def ehstack(tup):
            return np.hstack(tup) if len(tup) > 0 else np.empty((0, 2))

        entropy_pairs = evstack(entropy_list)
        scale_pairs   = evstack(scale_list)
        scores        = ehstack(score_list)
        print('\n * Measured %d pairs' % len(entropy_pairs))
        return entropy_pairs, scale_pairs, scores
Beispiel #3
0
    def measure_feat_pairs(allres, orgtype='top_true'):
        print('Measure ' + orgtype + ' pairs')
        orgres = allres.__dict__[orgtype]
        entropy_list = []
        scale_list = []
        score_list = []
        lbl = 'Measuring ' + orgtype + ' pair '
        fmt_str = helpers.make_progress_fmt_str(len(orgres), lbl)
        rank_skips = []
        gt_skips = []
        for ix, (qcx, cx, score, rank) in enumerate(orgres.iter()):
            helpers.print_(fmt_str % (ix + 1, ))
            # Skip low ranks
            if rank > 5:
                rank_skips.append(qcx)
                continue
            other_cxs = hs.get_other_indexed_cxs(qcx)
            # Skip no groundtruth
            if len(other_cxs) == 0:
                gt_skips.append(qcx)
                continue
            res = qcx2_res[qcx]
            # Get matching feature indexes
            fm = res.cx2_fm[cx]
            # Get their scores
            fs = res.cx2_fs[cx]
            # Get matching descriptors
            printDBG('\nfm.shape=%r' % (fm.shape, ))
            desc1 = cx2_desc[qcx][fm[:, 0]]
            desc2 = cx2_desc[cx][fm[:, 1]]
            # Get matching keypoints
            kpts1 = cx2_kpts[qcx][fm[:, 0]]
            kpts2 = cx2_kpts[cx][fm[:, 1]]
            # Get their scale
            scale1_m = sv2.keypoint_scale(kpts1)
            scale2_m = sv2.keypoint_scale(kpts2)
            # Get their entropy
            entropy1 = descriptor_entropy(desc1, bw_factor=1)
            entropy2 = descriptor_entropy(desc2, bw_factor=1)
            # Append to results
            entropy_tup = np.array(zip(entropy1, entropy2))
            scale_tup = np.array(zip(scale1_m, scale2_m))
            entropy_tup = entropy_tup.reshape(len(entropy_tup), 2)
            scale_tup = scale_tup.reshape(len(scale_tup), 2)
            entropy_list.append(entropy_tup)
            scale_list.append(scale_tup)
            score_list.append(fs)
        print('Skipped %d total.' % (len(rank_skips) + len(gt_skips), ))
        print('Skipped %d for rank > 5, %d for no gt' % (
            len(rank_skips),
            len(gt_skips),
        ))
        print(np.unique(map(len, entropy_list)))

        def evstack(tup):
            return np.vstack(tup) if len(tup) > 0 else np.empty((0, 2))

        def ehstack(tup):
            return np.hstack(tup) if len(tup) > 0 else np.empty((0, 2))

        entropy_pairs = evstack(entropy_list)
        scale_pairs = evstack(scale_list)
        scores = ehstack(score_list)
        print('\n * Measured %d pairs' % len(entropy_pairs))
        return entropy_pairs, scale_pairs, scores