コード例 #1
0
ファイル: viz_helpers.py プロジェクト: byteyoo/ibeis
def get_query_text(ibs, qres, aid2, truth, **kwargs):
    """ returns title based on the query chip and result """
    text_list = []
    if kwargs.get('show_truth', False):
        truth_str = '*%s*' % get_truth_text(ibs, truth)
        text_list.append(truth_str)
    if kwargs.get('show_rank', True):
        rank_str = 'rank=%s' % str(qres.get_aid_ranks([aid2])[0] + 1)
        text_list.append(rank_str)
    if kwargs.get('show_score', True):
        score = qres.aid2_score[aid2]
        score_str = ('score=' + utool.num_fmt(score))
        if len(text_list) > 0:
            score_str = '\n' + score_str
        text_list.append(score_str)
    if kwargs.get('show_timedelta', False):
        timedelta_str = ('\n' + get_timedelta_str(ibs, qres.qaid, aid2))
        text_list.append(timedelta_str)
    query_text = ', '.join(text_list)
    return query_text
コード例 #2
0
def annotate_matches3(ibs,
                      aid_list,
                      bbox_list,
                      offset_list,
                      name_fm_list,
                      name_fs_list,
                      qreq_=None,
                      **kwargs):
    """
    TODO: use this as the main function.
    """
    # TODO Use this function when you clean show_matches
    in_image = kwargs.get('in_image', False)
    #show_query  = kwargs.get('show_query', True)
    draw_border = kwargs.get('draw_border', True)
    draw_lbl = kwargs.get('draw_lbl', True)
    notitle = kwargs.get('notitle', False)
    # List of annotation scores for each annot in the name

    #printDBG('[viz] annotate_matches3()')
    #truth = ibs.get_match_truth(aid1, aid2)

    #name_equality = (
    #    np.array(ibs.get_annot_nids(aid_list[1:])) == ibs.get_annot_nids(aid_list[0])
    #).tolist()
    #truth = 1 if all(name_equality) else (2 if any(name_equality) else 0)
    #truth_color = vh.get_truth_color(truth)
    ## Build title

    #score         = kwargs.pop('score', None)
    #rawscore      = kwargs.pop('rawscore', None)
    #aid2_raw_rank = kwargs.pop('aid2_raw_rank', None)
    #print(kwargs)
    #title = vh.get_query_text(ibs, None, aid2, truth, qaid=aid1, **kwargs)
    # Build xlbl
    ax = pt.gca()
    ph.set_plotdat(ax, 'viztype', 'multi_match')
    ph.set_plotdat(ax, 'qaid', aid_list[0])
    ph.set_plotdat(ax, 'num_matches', len(aid_list) - 1)
    ph.set_plotdat(ax, 'aid_list', aid_list[1:])
    for count, aid in enumerate(aid_list, start=1):
        ph.set_plotdat(ax, 'aid%d' % (count, ), aid)

    #name_equality = (ibs.get_annot_nids(aid_list[0]) ==
    #                 np.array(ibs.get_annot_nids(aid_list[1:])))
    #truth = 1 if np.all(name_equality) else (2 if np.any(name_equality) else 0)
    truth = get_multitruth(ibs, aid_list)
    if any(ibs.is_aid_unknown(aid_list[1:])) or ibs.is_aid_unknown(
            aid_list[0]):
        truth = ibs.const.TRUTH_UNKNOWN
    truth_color = vh.get_truth_color(truth)

    name_annot_scores = kwargs.get('name_annot_scores', None)
    if len(aid_list) == 2:
        # HACK; generalize to multple annots
        title = vh.get_query_text(ibs,
                                  None,
                                  aid_list[1],
                                  truth,
                                  qaid=aid_list[0],
                                  **kwargs)
        if not notitle:
            pt.set_title(title, ax)

    if draw_lbl:
        # Build labels
        nid_list = ibs.get_annot_nids(aid_list, distinguish_unknowns=False)
        name_list = ibs.get_annot_names(aid_list)
        lbls_list = [[] for _ in range(len(aid_list))]
        if kwargs.get('show_name', False):
            for count, (lbls, name) in enumerate(zip(lbls_list, name_list)):
                lbls.append(ut.repr2((name)))
        if kwargs.get('show_nid', True):
            for count, (lbls, nid) in enumerate(zip(lbls_list, nid_list)):
                # only label the first two images with nids
                LABEL_ALL_NIDS = False
                if count <= 1 or LABEL_ALL_NIDS:
                    #lbls.append(vh.get_nidstrs(nid))
                    lbls.append(('q' if count == 0 else '') +
                                vh.get_nidstrs(nid))
        if kwargs.get('show_aid', True):
            for count, (lbls, aid) in enumerate(zip(lbls_list, aid_list)):
                lbls.append(('q' if count == 0 else '') + vh.get_aidstrs(aid))
        if (kwargs.get('show_annot_score', True)
                and name_annot_scores is not None):
            max_digits = kwargs.get('score_precision', None)
            for (lbls, score) in zip(lbls_list[1:], name_annot_scores):
                lbls.append(ut.num_fmt(score, max_digits=max_digits))
        lbl_list = [' : '.join(lbls) for lbls in lbls_list]
    else:
        lbl_list = [None] * len(aid_list)
    #pt.set_title(title, ax)
    # Plot annotations over images
    if in_image:
        in_image_bbox_list = vh.get_bboxes(ibs, aid_list, offset_list)
        in_image_theta_list = ibs.get_annot_thetas(aid_list)
        # HACK!
        #if show_query:
        #    pt.draw_bbox(bbox1, bbox_color=pt.ORANGE, lbl=lbl1, theta=theta1)
        bbox_color = pt.ORANGE
        bbox_color = truth_color if draw_border else pt.ORANGE
        for bbox, theta, lbl in zip(in_image_bbox_list, in_image_theta_list,
                                    lbl_list):
            pt.draw_bbox(bbox, bbox_color=bbox_color, lbl=lbl, theta=theta)
            pass
    else:
        xy, w, h = pt.get_axis_xy_width_height(ax)
        #theta2 = 0

        #if xywh2 is None:
        #    #xywh2 = (xy[0], xy[1], w, h)
        #    # weird when sidebyside is off y seems to be inverted
        #    xywh2 = (0,  0, w, h)

        #if not show_query and xywh1 is None:
        #    data_config2 = None if qreq_ is None else
        #    qreq_.get_external_data_config2()
        #    kpts2 = ibs.get_annot_kpts([aid2], config2_=data_config2)[0]
        #    #pt.draw_kpts2(kpts2.take(fm.T[1], axis=0))
        #    # Draw any selected matches
        #    #sm_kw = dict(rect=True, colors=pt.BLUE)
        #    pt.plot_fmatch(None, xywh2, None, kpts2, fm, fs=fs, **kwargs)
        #if draw_border:
        #    pt.draw_border(ax, truth_color, 4, offset=offset2)
        if draw_border:
            pt.draw_border(ax, color=truth_color, lw=4)
        if draw_lbl:
            # Custom user lbl for chips 1 and 2
            #if show_query:
            #    (x1, y1, w1, h1) = xywh1
            #    pt.absolute_lbl(x1 + w1, y1, lbl1)
            for bbox, lbl in zip(bbox_list, lbl_list):
                (x, y, w, h) = bbox
                pt.absolute_lbl(x + w, y, lbl)
    # No matches draw a red box
    if True:
        no_matches = name_fm_list is None or all(
            [True if fm is None else len(fm) == 0 for fm in name_fm_list])
        if no_matches:
            xy, w, h = pt.get_axis_xy_width_height(ax)
            #axes_bbox = (xy[0], xy[1], w, h)
            if draw_border:
                pass
コード例 #3
0
def get_query_text(ibs, cm, aid2, truth, **kwargs):
    """
    returns title based on the query chip and result

    Args:
        ibs (IBEISController):  wbia controller object
        cm (ChipMatch):  object of feature correspondences and scores
        aid2 (int):  annotation id
        truth (int): 0, 1, 2

    Kwargs:
        qaid, score, rawscore, aid2_raw_rank, show_truth, name_score,
        name_rank, show_name_score, show_name_rank, show_timedelta

    Returns:
        str: query_text

    CommandLine:
        python -m wbia.viz.viz_helpers --exec-get_query_text

    Example:
        >>> # DISABLE_DOCTEST
        >>> from wbia.viz.viz_helpers import *  # NOQA
        >>> import wbia
        >>> cm, qreq_ = wbia.testdata_cm()
        >>> aid2 = cm.get_top_aids()[0]
        >>> truth = 1
        >>> query_text = get_query_text(ibs, cm, aid2, truth)
        >>> result = ('query_text = %s' % (str(query_text),))
        >>> print(result)
    """
    text_list = []
    if cm is not None:
        qaid = cm.qaid
        score = cm.get_annot_scores([aid2])[0]
        rawscore = cm.get_annot_scores([aid2])[0]
        aid2_raw_rank = cm.get_annot_ranks([aid2])[0]
    else:
        qaid = kwargs.get('qaid', None)
        score = kwargs.get('score', None)
        rawscore = kwargs.get('rawscore', None)
        aid2_raw_rank = kwargs.get('aid2_raw_rank', None)
    if kwargs.get('show_truth', False):
        truth_str = '*%s*' % ibs.const.EVIDENCE_DECISION.INT_TO_NICE.get(
            truth, None)
        text_list.append(truth_str)
    if kwargs.get('show_rank', aid2_raw_rank is not None or cm is not None):
        try:
            # aid2_raw_rank = cm.get_annot_ranks([aid2])[0]
            aid2_rank = aid2_raw_rank + 1 if aid2_raw_rank is not None else None
            rank_str = 'rank=%s' % str(aid2_rank)
        except Exception as ex:
            ut.printex(ex)
            # ut.embed()
            raise
        text_list.append(rank_str)
    if kwargs.get('show_rawscore', rawscore is not None or cm is not None):
        rawscore_str = 'rawscore=' + ut.num_fmt(rawscore)
        if len(text_list) > 0:
            rawscore_str = '\n' + rawscore_str
        text_list.append(rawscore_str)
    if kwargs.get('show_score', score is not None or cm is not None):
        score_str = 'score=' + ut.num_fmt(score)
        if len(text_list) > 0:
            score_str = '\n' + score_str
        text_list.append(score_str)
    name_score = kwargs.get('name_score', None)
    name_rank = kwargs.get('name_rank', None)
    if kwargs.get('show_name_score', True):
        if name_score is not None:
            text_list.append('name_score=' + ut.num_fmt(name_score))
    if kwargs.get('show_name_rank', True):
        if name_rank is not None:
            # Make display one based
            text_list.append('name_rank=#%s' % (str(name_rank + 1), ))
    # with ut.embed_on_exception_context:
    if kwargs.get('show_timedelta', True):
        assert qaid is not None, 'qaid cannot be None'
        # TODO: fixme
        if isinstance(aid2, list):
            aid2_ = aid2[0]
        else:
            aid2_ = aid2
        timedelta_str = '\n' + get_timedelta_str(ibs, qaid, aid2_)
        text_list.append(timedelta_str)
    query_text = ', '.join(text_list)
    return query_text
コード例 #4
0
ファイル: viz_helpers.py プロジェクト: Erotemic/ibeis
def get_query_text(ibs, cm, aid2, truth, **kwargs):
    """
    returns title based on the query chip and result

    Args:
        ibs (IBEISController):  ibeis controller object
        cm (ChipMatch):  object of feature correspondences and scores
        aid2 (int):  annotation id
        truth (int): 0, 1, 2

    Kwargs:
        qaid, score, rawscore, aid2_raw_rank, show_truth, name_score,
        name_rank, show_name_score, show_name_rank, show_timedelta

    Returns:
        str: query_text

    CommandLine:
        python -m ibeis.viz.viz_helpers --exec-get_query_text

    Example:
        >>> # DISABLE_DOCTEST
        >>> from ibeis.viz.viz_helpers import *  # NOQA
        >>> import ibeis
        >>> ibs = ibeis.opendb(defaultdb='testdb1')
        >>> cm = ibs.query_chips([1], [2, 3, 4, 5], cfgdict=dict())[0]
        >>> aid2 = '?'
        >>> truth = '?'
        >>> query_text = get_query_text(ibs, cm, aid2, truth)
        >>> result = ('query_text = %s' % (str(query_text),))
        >>> print(result)
    """
    text_list = []
    if cm is not None:
        qaid = cm.qaid
        score = cm.get_aid_scores([aid2])[0]
        rawscore = cm.get_aid_scores([aid2], rawscore=True)[0]
        aid2_raw_rank = cm.get_aid_ranks([aid2])[0]
    else:
        qaid          = kwargs.get('qaid', None)
        score         = kwargs.get('score', None)
        rawscore      = kwargs.get('rawscore', None)
        aid2_raw_rank = kwargs.get('aid2_raw_rank', None)
    if kwargs.get('show_truth', False):
        truth_str = '*%s*' % get_truth_text(ibs, truth)
        text_list.append(truth_str)
    if kwargs.get('show_rank', aid2_raw_rank is not None or cm is not None):
        try:
            #aid2_raw_rank = cm.get_aid_ranks([aid2])[0]
            aid2_rank = aid2_raw_rank + 1 if aid2_raw_rank is not None else None
            rank_str = 'rank=%s' % str(aid2_rank)
        except Exception as ex:
            ut.printex(ex)
            #ut.embed()
            raise
        text_list.append(rank_str)
    if kwargs.get('show_rawscore', rawscore is not None or cm is not None):
        #rawscore = cm.get_aid_scores([aid2], rawscore=True)[0]
        rawscore_str = ('rawscore=' + ut.num_fmt(rawscore))
        if len(text_list) > 0:
            rawscore_str = '\n' + rawscore_str
        text_list.append(rawscore_str)
    if kwargs.get('show_score', score is not None or cm is not None):
        #score = cm.get_aid_scores([aid2])[0]
        score_str = ('score=' + ut.num_fmt(score))
        if len(text_list) > 0:
            score_str = '\n' + score_str
        text_list.append(score_str)
    name_score = kwargs.get('name_score', None)
    name_rank = kwargs.get('name_rank', None)
    if kwargs.get('show_name_score', True):
        if name_score is not None:
            text_list.append('name_score=' + ut.num_fmt(name_score))
    if kwargs.get('show_name_rank', True):
        if name_rank is not None:
            # Make display one based
            text_list.append('name_rank=#%s' % (str(name_rank + 1),))
    #with ut.embed_on_exception_context:
    if kwargs.get('show_timedelta', True):
        assert qaid is not None, 'qaid cannot be None'
        # TODO: fixme
        if isinstance(aid2, list):
            aid2_ = aid2[0]
        else:
            aid2_ = aid2
        timedelta_str = ('\n' + get_timedelta_str(ibs, qaid, aid2_))
        text_list.append(timedelta_str)
    query_text = ', '.join(text_list)
    return query_text
コード例 #5
0
ファイル: viz_matches.py プロジェクト: Erotemic/ibeis
def annotate_matches3(ibs, aid_list, bbox_list, offset_list, name_fm_list,
                      name_fs_list, qreq_=None, **kwargs):
    """
    TODO: use this as the main function.
    """
    # TODO Use this function when you clean show_matches
    in_image    = kwargs.get('in_image', False)
    #show_query  = kwargs.get('show_query', True)
    draw_border = kwargs.get('draw_border', True)
    draw_lbl    = kwargs.get('draw_lbl', True)
    notitle     = kwargs.get('notitle', False)
    # List of annotation scores for each annot in the name

    #printDBG('[viz] annotate_matches3()')
    #truth = ibs.get_match_truth(aid1, aid2)

    #name_equality = (
    #    np.array(ibs.get_annot_nids(aid_list[1:])) == ibs.get_annot_nids(aid_list[0])
    #).tolist()
    #truth = 1 if all(name_equality) else (2 if any(name_equality) else 0)
    #truth_color = vh.get_truth_color(truth)
    ## Build title

    #score         = kwargs.pop('score', None)
    #rawscore      = kwargs.pop('rawscore', None)
    #aid2_raw_rank = kwargs.pop('aid2_raw_rank', None)
    #print(kwargs)
    #title = vh.get_query_text(ibs, None, aid2, truth, qaid=aid1, **kwargs)
    # Build xlbl
    ax = pt.gca()
    ph.set_plotdat(ax, 'viztype', 'multi_match')
    ph.set_plotdat(ax, 'qaid', aid_list[0])
    ph.set_plotdat(ax, 'num_matches', len(aid_list) - 1)
    ph.set_plotdat(ax, 'aid_list', aid_list[1:])
    for count, aid in enumerate(aid_list, start=1):
        ph.set_plotdat(ax, 'aid%d' % (count,), aid)

    #name_equality = (ibs.get_annot_nids(aid_list[0]) ==
    #                 np.array(ibs.get_annot_nids(aid_list[1:])))
    #truth = 1 if np.all(name_equality) else (2 if np.any(name_equality) else 0)
    truth = get_multitruth(ibs, aid_list)
    if any(ibs.is_aid_unknown(aid_list[1:])) or ibs.is_aid_unknown(aid_list[0]):
        truth = ibs.const.TRUTH_UNKNOWN
    truth_color = vh.get_truth_color(truth)

    name_annot_scores = kwargs.get('name_annot_scores', None)
    if len(aid_list) == 2:
        # HACK; generalize to multple annots
        title = vh.get_query_text(ibs, None, aid_list[1], truth, qaid=aid_list[0], **kwargs)
        if not notitle:
            pt.set_title(title, ax)

    if draw_lbl:
        # Build labels
        nid_list = ibs.get_annot_nids(aid_list, distinguish_unknowns=False)
        name_list = ibs.get_annot_names(aid_list)
        lbls_list = [[] for _ in range(len(aid_list))]
        if kwargs.get('show_name', False):
            for count, (lbls, name) in enumerate(zip(lbls_list, name_list)):
                lbls.append(ut.repr2((name)))
        if kwargs.get('show_nid', True):
            for count, (lbls, nid) in enumerate(zip(lbls_list, nid_list)):
                # only label the first two images with nids
                LABEL_ALL_NIDS = False
                if count <= 1 or LABEL_ALL_NIDS:
                    #lbls.append(vh.get_nidstrs(nid))
                    lbls.append(('q' if count == 0 else '') + vh.get_nidstrs(nid))
        if kwargs.get('show_aid', True):
            for count, (lbls, aid) in enumerate(zip(lbls_list, aid_list)):
                lbls.append(('q' if count == 0 else '') + vh.get_aidstrs(aid))
        if (kwargs.get('show_annot_score', True) and
              name_annot_scores is not None):
            max_digits = kwargs.get('score_precision', None)
            for (lbls, score) in zip(lbls_list[1:], name_annot_scores):
                lbls.append(ut.num_fmt(score, max_digits=max_digits))
        lbl_list = [' : '.join(lbls) for lbls in lbls_list]
    else:
        lbl_list = [None] * len(aid_list)
    #pt.set_title(title, ax)
    # Plot annotations over images
    if in_image:
        in_image_bbox_list = vh.get_bboxes(ibs, aid_list, offset_list)
        in_image_theta_list = ibs.get_annot_thetas(aid_list)
        # HACK!
        #if show_query:
        #    pt.draw_bbox(bbox1, bbox_color=pt.ORANGE, lbl=lbl1, theta=theta1)
        bbox_color = pt.ORANGE
        bbox_color = truth_color if draw_border else pt.ORANGE
        for bbox, theta, lbl in zip(in_image_bbox_list, in_image_theta_list,
                                    lbl_list):
            pt.draw_bbox(bbox, bbox_color=bbox_color, lbl=lbl, theta=theta)
            pass
    else:
        xy, w, h = pt.get_axis_xy_width_height(ax)
        #theta2 = 0

        #if xywh2 is None:
        #    #xywh2 = (xy[0], xy[1], w, h)
        #    # weird when sidebyside is off y seems to be inverted
        #    xywh2 = (0,  0, w, h)

        #if not show_query and xywh1 is None:
        #    data_config2 = None if qreq_ is None else
        #    qreq_.get_external_data_config2()
        #    kpts2 = ibs.get_annot_kpts([aid2], config2_=data_config2)[0]
        #    #pt.draw_kpts2(kpts2.take(fm.T[1], axis=0))
        #    # Draw any selected matches
        #    #sm_kw = dict(rect=True, colors=pt.BLUE)
        #    pt.plot_fmatch(None, xywh2, None, kpts2, fm, fs=fs, **kwargs)
        #if draw_border:
        #    pt.draw_border(ax, truth_color, 4, offset=offset2)
        if draw_border:
            pt.draw_border(ax, color=truth_color, lw=4)
        if draw_lbl:
            # Custom user lbl for chips 1 and 2
            #if show_query:
            #    (x1, y1, w1, h1) = xywh1
            #    pt.absolute_lbl(x1 + w1, y1, lbl1)
            for bbox, lbl in zip(bbox_list, lbl_list):
                (x, y, w, h) = bbox
                pt.absolute_lbl(x + w, y, lbl)
    # No matches draw a red box
    if True:
        no_matches = name_fm_list is None or all([True if fm is None else len(fm) == 0 for fm in name_fm_list])
        if no_matches:
            xy, w, h = pt.get_axis_xy_width_height(ax)
            #axes_bbox = (xy[0], xy[1], w, h)
            if draw_border:
                pass