コード例 #1
0
ファイル: viz.py プロジェクト: Erotemic/hotspotter
def _annotate_kpts(kpts, sel_fx, draw_ell, draw_pts, color=None, nRandKpts=None, rect=False):
    #print('[viz] _annotate_kpts()')
    if color is None:
        color = 'distinct' if sel_fx is None else df2.ORANGE
    ell_args = {
        'ell': draw_ell,
        'pts': draw_pts,
        'rect': rect,
        'ell_alpha': .4,
        'ell_linewidth': 2,
        'ell_color': color,
    }
    if draw_ell and nRandKpts is not None:
        # show a random sample of kpts
        nkpts1 = len(kpts)
        fxs1 = np.arange(nkpts1)
        size = nRandKpts
        replace = False
        p = np.ones(nkpts1)
        p = p / p.sum()
        fxs_randsamp = np.random.choice(fxs1, size, replace, p)
        kpts = kpts[fxs_randsamp]
        # TODO Fix this. This should not set the xlabel
        df2.set_xlabel('displaying %r/%r keypoints' % (nRandKpts, nkpts1))
    elif draw_ell or draw_pts:
        # draw all keypoints
        df2.draw_kpts2(kpts, **ell_args)
    if sel_fx is not None:
        # Draw selected keypoint
        sel_kpts = kpts[sel_fx:sel_fx + 1]
        df2.draw_kpts2(sel_kpts, ell_color=df2.BLUE, arrow=True, rect=True)
コード例 #2
0
def plot_rank_histogram(allres, orgres_type):
    print('[viz] plotting %r rank histogram' % orgres_type)
    ranks = allres.__dict__[orgres_type].ranks
    label = 'P(rank | ' + orgres_type + ' match)'
    title = orgres_type + ' match rankings histogram\n' + allres.title_suffix
    df2.figure(fnum=FIGNUM, doclf=True, title=title)
    df2.draw_histpdf(ranks, label=label)  # FIXME
    df2.set_xlabel('ground truth ranks')
    df2.set_ylabel('frequency')
    df2.legend()
    __dump_or_browse(allres.hs, 'rankviz')
コード例 #3
0
def plot_score_pdf(allres, orgres_type, colorx=0.0, variation_truncate=False):
    print('[viz] plotting ' + orgres_type + ' score pdf')
    title = orgres_type + ' match score frequencies\n' + allres.title_suffix
    scores = allres.__dict__[orgres_type].scores
    print('[viz] len(scores) = %r ' % (len(scores), ))
    label = 'P(score | %r)' % orgres_type
    df2.figure(fnum=FIGNUM, doclf=True, title=title)
    df2.draw_pdf(scores, label=label, colorx=colorx)
    if variation_truncate:
        df2.variation_trunctate(scores)
    #df2.variation_trunctate(false.scores)
    df2.set_xlabel('score')
    df2.set_ylabel('frequency')
    df2.legend()
    __dump_or_browse(allres.hs, 'scoreviz')
コード例 #4
0
def plot_rank_stem(allres, orgres_type='true'):
    print('[viz] plotting rank stem')
    # Visualize rankings with the stem plot
    hs = allres.hs
    title = orgres_type + 'rankings stem plot\n' + allres.title_suffix
    orgres = allres.__dict__[orgres_type]
    df2.figure(fnum=FIGNUM, doclf=True, title=title)
    x_data = orgres.qcxs
    y_data = orgres.ranks
    df2.draw_stems(x_data, y_data)
    slice_num = int(np.ceil(np.log10(len(orgres.qcxs))))
    df2.set_xticks(hs.test_sample_cx[::slice_num])
    df2.set_xlabel('query chip indeX (qcx)')
    df2.set_ylabel('groundtruth chip ranks')
    #df2.set_yticks(list(seen_ranks))
    __dump_or_browse(allres.hs, 'rankviz')
コード例 #5
0
ファイル: viz.py プロジェクト: obaiga/hotspotter
def draw_feat_row(rchip,
                  fx,
                  kp,
                  sift,
                  fnum,
                  nRows,
                  nCols,
                  px,
                  prevsift=None,
                  cx=None,
                  info='',
                  type_=None):
    pnum_ = lambda px: (nRows, nCols, px)

    def _draw_patch(**kwargs):
        return extract_patch.draw_keypoint_patch(rchip, kp, sift, **kwargs)

    # Feature strings
    xy_str, acd_str, scale = kp_info(kp)

    # Draw the unwarped selected feature
    ax = _draw_patch(fnum=fnum, pnum=pnum_(px + 1))
    ax._hs_viewtype = 'unwarped'
    ax._hs_cx = cx
    ax._hs_fx = fx
    unwarped_lbl = 'affine feature inv(A) =\n' + acd_str
    df2.set_xlabel(unwarped_lbl, ax)

    # Draw the warped selected feature
    ax = _draw_patch(fnum=fnum, pnum=pnum_(px + 2), warped=True)
    ax._hs_viewtype = 'warped'
    ax._hs_cx = cx
    ax._hs_fx = fx
    warped_lbl = ('warped feature\n' + 'fx=%r scale=%.1f\n' + '%s' +
                  info) % (fx, scale, xy_str)
    df2.set_xlabel(warped_lbl, ax)

    border_color = {
        None: None,
        'query': None,
        'match': df2.BLUE,
        'norm': df2.ORANGE
    }[type_]
    if border_color is not None:
        df2.draw_border(ax, color=border_color)

    # Draw the SIFT representation
    sigtitle = '' if px != 3 else 'sift histogram'
    ax = df2.plot_sift_signature(sift, sigtitle, fnum=fnum, pnum=pnum_(px + 3))
    ax._hs_viewtype = 'histogram'
    if prevsift is not None:
        from hotspotter import algos
        dist_list = ['L1', 'L2', 'hist_isect', 'emd']
        distmap = algos.compute_distances(sift, prevsift, dist_list)
        dist_str = ', '.join(
            ['(%s, %.1E)' % (key, val) for key, val in distmap.iteritems()])
        df2.set_xlabel(dist_str)
    return px + nCols
コード例 #6
0
ファイル: viz.py プロジェクト: obaiga/hotspotter
def _annotate_kpts(kpts,
                   sel_fx,
                   draw_ell,
                   draw_pts,
                   color=None,
                   nRandKpts=None,
                   rect=False):
    #print('[viz] _annotate_kpts()')
    if color is None:
        color = 'distinct' if sel_fx is None else df2.ORANGE
    ell_args = {
        'ell': draw_ell,
        'pts': draw_pts,
        'rect': rect,
        'ell_alpha': .4,
        'ell_linewidth': 2,
        'ell_color': color,
    }
    if draw_ell and nRandKpts is not None:
        # show a random sample of kpts
        nkpts1 = len(kpts)
        fxs1 = np.arange(nkpts1)
        size = nRandKpts
        replace = False
        p = np.ones(nkpts1)
        p = p / p.sum()
        fxs_randsamp = np.random.choice(fxs1, size, replace, p)
        kpts = kpts[fxs_randsamp]
        # TODO Fix this. This should not set the xlabel
        df2.set_xlabel('displaying %r/%r keypoints' % (nRandKpts, nkpts1))
    elif draw_ell or draw_pts:
        # draw all keypoints
        df2.draw_kpts2(kpts, **ell_args)
    if sel_fx is not None:
        # Draw selected keypoint
        sel_kpts = kpts[sel_fx:sel_fx + 1]
        df2.draw_kpts2(sel_kpts, ell_color=df2.BLUE, arrow=True, rect=True)
コード例 #7
0
def plot_score_matrix(allres):
    print('[viz] plotting score matrix')
    score_matrix = allres.score_matrix
    title = 'Score Matrix\n' + allres.title_suffix
    # Find inliers
    #inliers = helpers.find_std_inliers(score_matrix)
    #max_inlier = score_matrix[inliers].max()
    # Trunate above 255
    score_img = np.copy(score_matrix)
    #score_img[score_img < 0] = 0
    #score_img[score_img > 255] = 255
    #dim = 0
    #score_img = helpers.norm_zero_one(score_img, dim=dim)
    # Make colors
    scores = score_img.flatten()
    colors = df2.scores_to_color(scores, logscale=True)
    cmap = df2.scores_to_cmap(scores, colors)
    df2.figure(fnum=FIGNUM, doclf=True, title=title)
    # Show score matrix
    df2.imshow(score_img, fnum=FIGNUM, cmap=cmap)
    # Colorbar
    df2.colorbar(scores, colors)
    df2.set_xlabel('database')
    df2.set_ylabel('queries')
コード例 #8
0
ファイル: viz.py プロジェクト: Erotemic/hotspotter
def draw_feat_row(rchip, fx, kp, sift, fnum, nRows, nCols, px, prevsift=None,
                  cx=None, info='', type_=None):
    pnum_ = lambda px: (nRows, nCols, px)

    def _draw_patch(**kwargs):
        return extract_patch.draw_keypoint_patch(rchip, kp, sift, **kwargs)

    # Feature strings
    xy_str, acd_str, scale = kp_info(kp)

    # Draw the unwarped selected feature
    ax = _draw_patch(fnum=fnum, pnum=pnum_(px + 1))
    ax._hs_viewtype = 'unwarped'
    ax._hs_cx = cx
    ax._hs_fx = fx
    unwarped_lbl = 'affine feature inv(A) =\n' + acd_str
    df2.set_xlabel(unwarped_lbl, ax)

    # Draw the warped selected feature
    ax = _draw_patch(fnum=fnum, pnum=pnum_(px + 2), warped=True)
    ax._hs_viewtype = 'warped'
    ax._hs_cx = cx
    ax._hs_fx = fx
    warped_lbl = ('warped feature\n' +
                  'fx=%r scale=%.1f\n' +
                  '%s' + info) % (fx, scale, xy_str)
    df2.set_xlabel(warped_lbl, ax)

    border_color = {None: None,
                    'query': None,
                    'match': df2.BLUE,
                    'norm': df2.ORANGE}[type_]
    if border_color is not None:
        df2.draw_border(ax, color=border_color)

    # Draw the SIFT representation
    sigtitle = '' if px != 3 else 'sift histogram'
    ax = df2.plot_sift_signature(sift, sigtitle, fnum=fnum, pnum=pnum_(px + 3))
    ax._hs_viewtype = 'histogram'
    if prevsift is not None:
        from hotspotter import algos
        dist_list = ['L1', 'L2', 'hist_isect', 'emd']
        distmap = algos.compute_distances(sift, prevsift, dist_list)
        dist_str = ', '.join(['(%s, %.1E)' % (key, val) for key, val in distmap.iteritems()])
        df2.set_xlabel(dist_str)
    return px + nCols
コード例 #9
0
ファイル: viz.py プロジェクト: obaiga/hotspotter
def annotate_chipres(hs,
                     res,
                     cx,
                     showTF=True,
                     showScore=True,
                     title_pref='',
                     title_suff='',
                     show_2nd_gname=True,
                     show_2nd_name=True,
                     show_1st=True,
                     time_appart=True,
                     in_image=False,
                     offset1=(0, 0),
                     offset2=(0, 0),
                     show_query=True,
                     xywh2=None,
                     **kwargs):

    printDBG('[viz] annotate_chipres()')
    #print('Did not expect args: %r' % (kwargs.keys(),))
    qcx = res.qcx
    score = res.cx2_score[cx]
    matched_kpts = np.float32(len(res.cx2_fs[cx]))
    #    print('matched_kpts= %r'%str(matched_kpts))
    # TODO Use this function when you clean show_chipres
    (truestr, falsestr, nonamestr) = ('TRUE', 'FALSE', '???')
    is_true, is_unknown = hs.is_true_match(qcx, cx)
    isgt_str = nonamestr if is_unknown else (truestr if is_true else falsestr)
    match_color = {
        nonamestr: df2.UNKNOWN_PURP,
        truestr: df2.TRUE_GREEN,
        falsestr: df2.FALSE_RED
    }[isgt_str]
    # Build title
    title = '*%s*' % isgt_str if showTF else ''
    if showScore:
        score_str = (' score=' + helpers.num_fmt(score)) % (score)
        score_str += ('   matched_kpts=' +
                      helpers.num_fmt(matched_kpts)) % (matched_kpts)
        title += score_str
    title = title_pref + str(title) + title_suff
    # Build xlabel
    xlabel_ = []

    if 'show_1st':
        xlabel_.append('top_gname=%r' % hs.cx2_gname(qcx))
        xlabel_.append('top_name=%r' % hs.cx2_name(qcx))

    if 'show_2nd_gname':
        xlabel_.append('\n below_gname=%r' % hs.cx2_gname(cx))
    if 'show_2nd_name':
        xlabel_.append('below_name=%r' % hs.cx2_name(cx))

    if 'time_appart':
        xlabel_.append('\n' + hs.get_timedelta_str(qcx, cx))
    xlabel = ', '.join(xlabel_)
    ax = df2.gca()
    ax._hs_viewtype = 'chipres'
    ax._hs_qcx = qcx
    ax._hs_cx = cx
    if NO_LABEL_OVERRIDE:
        title = ''
        xlabel = ''
    df2.set_title(title, ax)
    df2.set_xlabel(xlabel, ax)
    if in_image:
        roi1 = hs.cx2_roi(qcx) + np.array(list(offset1) + [0, 0])
        roi2 = hs.cx2_roi(cx) + np.array(list(offset2) + [0, 0])
        theta1 = hs.cx2_theta(qcx)
        theta2 = hs.cx2_theta(cx)
        # HACK!
        lbl1 = 'q' + hs.cidstr(qcx)
        lbl2 = hs.cidstr(cx)
        if show_query:
            df2.draw_roi(roi1, bbox_color=df2.ORANGE, label=lbl1, theta=theta1)
        df2.draw_roi(roi2, bbox_color=match_color, label=lbl2, theta=theta2)
        # No matches draw a red box
        if len(res.cx2_fm[cx]) == 0:
            df2.draw_boxedX(roi2, theta=theta2)
    else:
        if xywh2 is None:
            xy, w, h = df2._axis_xy_width_height(ax)
            xywh2 = (xy[0], xy[1], w, h)
        df2.draw_border(ax, match_color, 4, offset=offset2)
        # No matches draw a red box
        if len(res.cx2_fm[cx]) == 0:
            df2.draw_boxedX(xywh2)
コード例 #10
0
ファイル: viz.py プロジェクト: Erotemic/hotspotter
def annotate_chipres(hs, res, cx, showTF=True, showScore=True, title_pref='',
                     title_suff='', show_gname=False, show_name=True,
                     time_appart=True, in_image=False, offset1=(0, 0),
                     offset2=(0, 0), show_query=True, xywh2=None, **kwargs):
    printDBG('[viz] annotate_chipres()')
    #print('Did not expect args: %r' % (kwargs.keys(),))
    qcx = res.qcx
    score = res.cx2_score[cx]
    # TODO Use this function when you clean show_chipres
    (truestr, falsestr, nonamestr) = ('TRUE', 'FALSE', '???')
    is_true, is_unknown = hs.is_true_match(qcx, cx)
    isgt_str = nonamestr if is_unknown else (truestr if is_true else falsestr)
    match_color = {nonamestr: df2.UNKNOWN_PURP,
                   truestr:   df2.TRUE_GREEN,
                   falsestr:  df2.FALSE_RED}[isgt_str]
    # Build title
    title = '*%s*' % isgt_str if showTF else ''
    if showScore:
        score_str = (' score=' + helpers.num_fmt(score)) % (score)
        title += score_str
    title = title_pref + str(title) + title_suff
    # Build xlabel
    xlabel_ = []
    if 'show_gname':
        xlabel_.append('gname=%r' % hs.cx2_gname(cx))
    if 'show_name':
        xlabel_.append('name=%r' % hs.cx2_name(cx))
    if 'time_appart':
        xlabel_.append('\n' + hs.get_timedelta_str(qcx, cx))
    xlabel = ', '.join(xlabel_)
    ax = df2.gca()
    ax._hs_viewtype = 'chipres'
    ax._hs_qcx = qcx
    ax._hs_cx = cx
    if NO_LABEL_OVERRIDE:
        title = ''
        xlabel = ''
    df2.set_title(title, ax)
    df2.set_xlabel(xlabel, ax)
    if in_image:
        roi1 = hs.cx2_roi(qcx) + np.array(list(offset1) + [0, 0])
        roi2 = hs.cx2_roi(cx) + np.array(list(offset2) + [0, 0])
        theta1 = hs.cx2_theta(qcx)
        theta2 = hs.cx2_theta(cx)
        # HACK!
        lbl1 = 'q' + hs.cidstr(qcx)
        lbl2 = hs.cidstr(cx)
        if show_query:
            df2.draw_roi(roi1, bbox_color=df2.ORANGE, label=lbl1, theta=theta1)
        df2.draw_roi(roi2, bbox_color=match_color, label=lbl2, theta=theta2)
        # No matches draw a red box
        if len(res.cx2_fm[cx]) == 0:
            df2.draw_boxedX(roi2, theta=theta2)
    else:
        if xywh2 is None:
            xy, w, h = df2._axis_xy_width_height(ax)
            xywh2 = (xy[0], xy[1], w, h)
        df2.draw_border(ax, match_color, 4, offset=offset2)
        # No matches draw a red box
        if len(res.cx2_fm[cx]) == 0:
            df2.draw_boxedX(xywh2)