Exemplo n.º 1
0
    def show_page(self, bring_to_front=False):
        """ Plots all subaxes on a page """
        print('[querydec] show_page()')
        self.prepare_page()
        # Variables we will work with to paint a pretty picture
        #ibs = self.ibs
        nRows = self.nRows
        nCols = self.nCols

        #Plot the Comparisions
        for count, c_aid in enumerate(self.comp_aids):
            if c_aid is not None:
                px = nCols + count + 1
                title_suffix = ''
                if self.suggest_aids is not None and c_aid in self.suggest_aids:
                    title_suffix = 'SUGGESTED BY IBEIS'
                self.plot_chip(c_aid, nRows, nCols, px, title_suffix=title_suffix)
            else:
                pt.imshow_null(fnum=self.fnum, pnum=(nRows, nCols, nCols + count + 1), title='NO RESULT')

        #Plot the Query Chip last
        with ut.EmbedOnException():
            query_title = 'Identify This Animal'
            self.plot_chip(self.query_aid, nRows, 1, 1, title_suffix=query_title)

        self.show_hud()
        pt.adjust_subplots_safe(top=0.88, hspace=0.12)
        self.draw()
        self.show()
        if bring_to_front:
            self.bring_to_front()
Exemplo n.º 2
0
    def show_page(self, bring_to_front=False):
        """ Plots all subaxes on a page """
        print('[querydec] show_page()')
        self.prepare_page()
        # Variables we will work with to paint a pretty picture
        #ibs = self.ibs
        nRows = self.nRows
        nCols = self.nCols

        #Plot the Comparisions
        for count, c_aid in enumerate(self.comp_aids):
            if c_aid is not None:
                px = nCols + count + 1
                title_suffix = ''
                if self.suggest_aids is not None and c_aid in self.suggest_aids:
                    title_suffix = 'SUGGESTED BY IBEIS'
                self.plot_chip(c_aid,
                               nRows,
                               nCols,
                               px,
                               title_suffix=title_suffix)
            else:
                pt.imshow_null(fnum=self.fnum,
                               pnum=(nRows, nCols, nCols + count + 1),
                               title='NO RESULT')

        #Plot the Query Chip last
        with ut.EmbedOnException():
            query_title = 'Identify This Animal'
            self.plot_chip(self.query_aid,
                           nRows,
                           1,
                           1,
                           title_suffix=query_title)

        self.show_hud()
        pt.adjust_subplots_safe(top=0.88, hspace=0.12)
        self.draw()
        self.show()
        if bring_to_front:
            self.bring_to_front()
Exemplo n.º 3
0
    def _plot_matches_aids(aid_list, plotx_shift, rowcols):
        """ helper for show_qres to draw many aids """
        _kwshow = dict(draw_ell=annot_mode,
                       draw_pts=False,
                       draw_lines=annot_mode,
                       ell_alpha=.5,
                       all_kpts=all_kpts)
        _kwshow.update(kwargs)
        _kwshow['fnum'] = fnum
        _kwshow['in_image'] = in_image
        if sidebyside:
            # Draw each match side by side the query
            _kwshow['draw_ell'] = annot_mode == 1
            _kwshow['draw_lines'] = annot_mode >= 1
        else:
            #print('annot_mode = %r' % (annot_mode,))
            _kwshow['draw_ell'] = annot_mode == 1
            #_kwshow['draw_pts'] = annot_mode >= 1
            #_kwshow['draw_lines'] = False
            _kwshow['show_query'] = False

        def _show_matches_fn(aid, orank, pnum):
            """ Helper function for drawing matches to one aid """
            aug = 'rank=%r\n' % orank
            _kwshow['pnum'] = pnum
            _kwshow['title_aug'] = aug
            #draw_ell = annot_mode == 1
            #draw_lines = annot_mode >= 1
            # If we already are showing the query dont show it here
            if sidebyside:
                # Draw each match side by side the query
                if viz_name_score:
                    cm.show_single_namematch(qreq_, ibs.get_annot_nids(aid),
                                             **_kwshow)
                else:
                    _kwshow['draw_border'] = False
                    _kwshow['draw_lbl'] = False
                    _kwshow['notitle'] = True
                    _kwshow['vert'] = False
                    cm.show_single_annotmatch(qreq_, aid, **_kwshow)
                    #viz_matches.show_matches(ibs, cm, aid, qreq_=qreq_, **_kwshow)
            else:
                # Draw each match by themselves
                data_config2_ = None if qreq_ is None else qreq_.get_external_data_config2(
                )
                #_kwshow['draw_border'] = kwargs.get('draw_border', True)
                #_kwshow['notitle'] = ut.get_argflag(('--no-title', '--notitle'))
                viz_chip.show_chip(ibs,
                                   aid,
                                   annote=False,
                                   notitle=True,
                                   data_config2_=data_config2_,
                                   **_kwshow)

        if DEBUG_SHOW_QRES:
            print('[show_qres()] Plotting Chips %s:' %
                  vh.get_aidstrs(aid_list))
        if aid_list is None:
            return
        # Do lazy load before show
        #data_config2_ = None if qreq_ is None else qreq_.get_external_data_config2()

        tblhack = getattr(qreq_, 'tablename', None)
        # HACK FOR HUMPBACKS
        # (Also in viz_matches)
        if tblhack == 'vsone' or (qreq_ is not None and not qreq_._isnewreq):
            # precompute
            pass
            #ibs.get_annot_chips(aid_list, config2_=data_config2_, ensure=True)
            #ibs.get_annot_kpts(aid_list, config2_=data_config2_, ensure=True)

        for ox, aid in enumerate(aid_list):
            plotx = ox + plotx_shift + 1
            pnum = (rowcols[0], rowcols[1], plotx)
            oranks = np.where(ranked_aids == aid)[0]
            # This pair has no matches between them.
            if len(oranks) == 0:
                orank = -1
                if aid is None:
                    pt.imshow_null('Failed to find matches\nfor qaid=%r' %
                                   (cm.qaid),
                                   fnum=fnum,
                                   pnum=pnum,
                                   fontsize=18)
                else:
                    _show_matches_fn(aid, orank, pnum)
                #if DEBUG_SHOW_QRES:
                #    print('skipping pnum=%r' % (pnum,))
                continue
            if DEBUG_SHOW_QRES:
                print('pnum=%r' % (pnum, ))
            orank = oranks[0] + 1
            _show_matches_fn(aid, orank, pnum)
Exemplo n.º 4
0
def show_qres(ibs, cm, qreq_=None, **kwargs):
    """
    Display Query Result Logic
    Defaults to: query chip, groundtruth matches, and top matches

    Args:
        ibs (ibeis.IBEISController):  ibeis controller object
        cm (ibeis.ChipMatch):  object of feature correspondences and scores

    Kwargs:
        in_image (bool) show result  in image view if True else chip view
        annot_mode (int):
            if annot_mode == 0, then draw lines and ellipse
            elif annot_mode == 1, then dont draw lines or ellipse
            elif annot_mode == 2, then draw only lines
        See: viz_matches.show_name_matches, viz_helpers.get_query_text

    Returns:
        mpl.Figure: fig

    CommandLine:
        ./main.py --query 1 -y --db PZ_MTEST --noshow-qtres

        python -m ibeis.viz.viz_qres --test-show_qres --show

        python -m ibeis.viz.viz_qres --test-show_qres --show --top-aids=10 --db=PZ_MTEST --sidebyside --annot_mode=0 --notitle --no-viz_name_score --qaids=5 --max_nCols=2 --adjust=.01,.01,.01

        python -m ibeis.viz.viz_qres --test-show_qres --show --top-aids=10 --db=PZ_MTEST --sidebyside --annot_mode=0 --notitle --no-viz_name_score --qaids=5 --max_nCols=2 --adjust=.01,.01,.01

    Example:
        >>> # DISABLE_DOCTEST
        >>> from ibeis.viz.viz_qres import *  # NOQA
        >>> import plottool as pt
        >>> ibs, cm, qreq_, kwargs = testdata_show_qres()
        >>> # execute function
        >>> fig = show_qres(ibs, cm, show_query=False, qreq_=qreq_, **kwargs)
        >>> # verify results
        >>> #fig.show()
        >>> pt.show_if_requested()
    """
    #ut.print_dict(kwargs)
    annot_mode = kwargs.get('annot_mode', 1) % 3  # this is toggled
    figtitle = kwargs.get('figtitle', '')
    make_figtitle = kwargs.get('make_figtitle', False)
    aug = kwargs.get('aug', '')
    top_aids = kwargs.get('top_aids', DEFAULT_NTOP)
    gt_aids = kwargs.get('gt_aids', [])
    all_kpts = kwargs.get('all_kpts', False)
    show_query = kwargs.get('show_query', False)
    in_image = kwargs.get('in_image', False)
    sidebyside = kwargs.get('sidebyside', True)
    #name_scoring   = kwargs.get('name_scoring', False)
    viz_name_score = kwargs.get('viz_name_score', qreq_ is not None)
    max_nCols = kwargs.get('max_nCols', None)
    failed_to_match = kwargs.get('failed_to_match', False)

    fnum = pt.ensure_fnum(kwargs.get('fnum', None))

    if ut.VERBOSE and ut.NOT_QUIET:
        print('query_info = ' + ut.obj_str(ibs.get_annot_info(cm.qaid,
                                                              default=True,
                                                              gname=False,
                                                              name=False,
                                                              notes=False,
                                                              exemplar=False),
                                           nl=4))
        print('top_aids_info = ' +
              ut.obj_str(ibs.get_annot_info(top_aids,
                                            default=True,
                                            gname=False,
                                            name=False,
                                            notes=False,
                                            exemplar=False,
                                            reference_aid=cm.qaid),
                         nl=4))

    if make_figtitle is True:
        pass
        #figtitle = cm.make_title(pack=True)
        #figtitle

    fig = pt.figure(fnum=fnum, docla=True, doclf=True)

    if isinstance(top_aids, int):
        #if isinstance(cm, chip_match.ChipMatch):
        top_aids = cm.get_top_aids(top_aids)
        #else:
        #    top_aids = cm.get_top_aids(num=top_aids, name_scoring=name_scoring, ibs=ibs)

    if failed_to_match:
        # HACK to visually indicate failure to match in analysis
        top_aids = [None] + top_aids

    nTop = len(top_aids)

    if max_nCols is None:
        max_nCols = 5
        if nTop in [6, 7]:
            max_nCols = 3
        if nTop in [8]:
            max_nCols = 4

    try:
        assert len(list(set(top_aids).intersection(
            set(gt_aids)))) == 0, ('gts should be missed.  not in top')
    except AssertionError as ex:
        ut.printex(ex, keys=['top_aids', 'gt_aids'])
        raise

    if ut.DEBUG2:
        print(cm.get_inspect_str())

    #--------------------------------------------------
    # Get grid / cell information to build subplot grid
    #--------------------------------------------------
    # Show query or not
    nQuerySubplts = 1 if show_query else 0
    # The top row is given slots for ground truths and querys
    # all aids in gt_aids should not be in top aids
    nGtSubplts = nQuerySubplts + (0 if gt_aids is None else len(gt_aids))
    # The bottom rows are for the top results
    nTopNSubplts = nTop
    nTopNCols = min(max_nCols, nTopNSubplts)
    nGTCols = min(max_nCols, nGtSubplts)
    nGTCols = max(nGTCols, nTopNCols)
    nTopNCols = nGTCols
    # Get number of rows to show groundtruth
    nGtRows = 0 if nGTCols == 0 else int(np.ceil(nGtSubplts / nGTCols))
    # Get number of rows to show results
    nTopNRows = 0 if nTopNCols == 0 else int(np.ceil(nTopNSubplts / nTopNCols))
    nGtCells = nGtRows * nGTCols
    # Total number of rows
    nRows = nTopNRows + nGtRows

    DEBUG_SHOW_QRES = 0

    if DEBUG_SHOW_QRES:
        allgt_aids = ibs.get_annot_groundtruth(cm.qaid)
        nSelGt = len(gt_aids)
        nAllGt = len(allgt_aids)
        print('[show_qres]========================')
        print('[show_qres]----------------')
        print('[show_qres] * annot_mode=%r' % (annot_mode, ))
        print('[show_qres] #nTop=%r #missed_gts=%r/%r' %
              (nTop, nSelGt, nAllGt))
        print('[show_qres] * -----')
        print('[show_qres] * nRows=%r' % (nRows, ))
        print('[show_qres] * nGtSubplts=%r' % (nGtSubplts, ))
        print('[show_qres] * nTopNSubplts=%r' % (nTopNSubplts, ))
        print('[show_qres] * nQuerySubplts=%r' % (nQuerySubplts, ))
        print('[show_qres] * -----')
        print('[show_qres] * nGTCols=%r' % (nGTCols, ))
        print('[show_qres] * -----')
        print('[show_qres] * fnum=%r' % (fnum, ))
        print('[show_qres] * figtitle=%r' % (figtitle, ))
        print('[show_qres] * max_nCols=%r' % (max_nCols, ))
        print('[show_qres] * show_query=%r' % (show_query, ))
        print('[show_qres] * kwargs=%s' % (ut.dict_str(kwargs), ))

    # HACK:
    _color_list = pt.distinct_colors(nTop)
    aid2_color = {aid: _color_list[ox] for ox, aid in enumerate(top_aids)}
    ranked_aids = cm.get_top_aids()

    # Helpers
    def _show_query_fn(plotx_shift, rowcols):
        """ helper for show_qres """
        plotx = plotx_shift + 1
        pnum = (rowcols[0], rowcols[1], plotx)
        #print('[viz] Plotting Query: pnum=%r' % (pnum,))
        _kwshow = dict(draw_kpts=annot_mode)
        _kwshow.update(kwargs)
        _kwshow['prefix'] = 'q'
        _kwshow['pnum'] = pnum
        _kwshow['aid2_color'] = aid2_color
        _kwshow['draw_ell'] = annot_mode >= 1
        viz_chip.show_chip(ibs, cm.qaid, annote=False, qreq_=qreq_, **_kwshow)

    def _plot_matches_aids(aid_list, plotx_shift, rowcols):
        """ helper for show_qres to draw many aids """
        _kwshow = dict(draw_ell=annot_mode,
                       draw_pts=False,
                       draw_lines=annot_mode,
                       ell_alpha=.5,
                       all_kpts=all_kpts)
        _kwshow.update(kwargs)
        _kwshow['fnum'] = fnum
        _kwshow['in_image'] = in_image
        if sidebyside:
            # Draw each match side by side the query
            _kwshow['draw_ell'] = annot_mode == 1
            _kwshow['draw_lines'] = annot_mode >= 1
        else:
            #print('annot_mode = %r' % (annot_mode,))
            _kwshow['draw_ell'] = annot_mode == 1
            #_kwshow['draw_pts'] = annot_mode >= 1
            #_kwshow['draw_lines'] = False
            _kwshow['show_query'] = False

        def _show_matches_fn(aid, orank, pnum):
            """ Helper function for drawing matches to one aid """
            aug = 'rank=%r\n' % orank
            _kwshow['pnum'] = pnum
            _kwshow['title_aug'] = aug
            #draw_ell = annot_mode == 1
            #draw_lines = annot_mode >= 1
            # If we already are showing the query dont show it here
            if sidebyside:
                # Draw each match side by side the query
                if viz_name_score:
                    cm.show_single_namematch(qreq_, ibs.get_annot_nids(aid),
                                             **_kwshow)
                else:
                    _kwshow['draw_border'] = False
                    _kwshow['draw_lbl'] = False
                    _kwshow['notitle'] = True
                    _kwshow['vert'] = False
                    cm.show_single_annotmatch(qreq_, aid, **_kwshow)
                    #viz_matches.show_matches(ibs, cm, aid, qreq_=qreq_, **_kwshow)
            else:
                # Draw each match by themselves
                data_config2_ = None if qreq_ is None else qreq_.get_external_data_config2(
                )
                #_kwshow['draw_border'] = kwargs.get('draw_border', True)
                #_kwshow['notitle'] = ut.get_argflag(('--no-title', '--notitle'))
                viz_chip.show_chip(ibs,
                                   aid,
                                   annote=False,
                                   notitle=True,
                                   data_config2_=data_config2_,
                                   **_kwshow)

        if DEBUG_SHOW_QRES:
            print('[show_qres()] Plotting Chips %s:' %
                  vh.get_aidstrs(aid_list))
        if aid_list is None:
            return
        # Do lazy load before show
        #data_config2_ = None if qreq_ is None else qreq_.get_external_data_config2()

        tblhack = getattr(qreq_, 'tablename', None)
        # HACK FOR HUMPBACKS
        # (Also in viz_matches)
        if tblhack == 'vsone' or (qreq_ is not None and not qreq_._isnewreq):
            # precompute
            pass
            #ibs.get_annot_chips(aid_list, config2_=data_config2_, ensure=True)
            #ibs.get_annot_kpts(aid_list, config2_=data_config2_, ensure=True)

        for ox, aid in enumerate(aid_list):
            plotx = ox + plotx_shift + 1
            pnum = (rowcols[0], rowcols[1], plotx)
            oranks = np.where(ranked_aids == aid)[0]
            # This pair has no matches between them.
            if len(oranks) == 0:
                orank = -1
                if aid is None:
                    pt.imshow_null('Failed to find matches\nfor qaid=%r' %
                                   (cm.qaid),
                                   fnum=fnum,
                                   pnum=pnum,
                                   fontsize=18)
                else:
                    _show_matches_fn(aid, orank, pnum)
                #if DEBUG_SHOW_QRES:
                #    print('skipping pnum=%r' % (pnum,))
                continue
            if DEBUG_SHOW_QRES:
                print('pnum=%r' % (pnum, ))
            orank = oranks[0] + 1
            _show_matches_fn(aid, orank, pnum)

    shift_topN = nGtCells

    if nGtSubplts == 1:
        nGTCols = 1

    if nRows == 0:
        pt.imshow_null('[viz_qres] No matches. nRows=0', fnum=fnum)
    else:
        fig = pt.figure(fnum=fnum,
                        pnum=(nRows, nGTCols, 1),
                        docla=True,
                        doclf=True)
        pt.plt.subplot(nRows, nGTCols, 1)
        # Plot Query
        if show_query:
            _show_query_fn(0, (nRows, nGTCols))
        # Plot Ground Truth (if given)
        _plot_matches_aids(gt_aids, nQuerySubplts, (nRows, nGTCols))
        # Plot Results
        _plot_matches_aids(top_aids, shift_topN, (nRows, nTopNCols))
        figtitle += aug
    if failed_to_match:
        figtitle += '\n No matches found'

    incanvas = kwargs.get('with_figtitle', not vh.NO_LBL_OVERRIDE)
    pt.set_figtitle(figtitle, incanvas=incanvas)

    # Result Interaction
    return fig
Exemplo n.º 5
0
    def _plot_matches_aids(aid_list, plotx_shift, rowcols):
        """ helper for show_qres to draw many aids """
        _kwshow  = dict(draw_ell=annot_mode, draw_pts=False, draw_lines=annot_mode,
                        ell_alpha=.5, all_kpts=all_kpts)
        _kwshow.update(kwargs)
        _kwshow['fnum'] = fnum
        _kwshow['in_image'] = in_image
        if sidebyside:
            # Draw each match side by side the query
            _kwshow['draw_ell'] = annot_mode == 1
            _kwshow['draw_lines'] = annot_mode >= 1
        else:
            #print('annot_mode = %r' % (annot_mode,))
            _kwshow['draw_ell'] = annot_mode == 1
            #_kwshow['draw_pts'] = annot_mode >= 1
            #_kwshow['draw_lines'] = False
            _kwshow['show_query'] = False
        def _show_matches_fn(aid, orank, pnum):
            """ Helper function for drawing matches to one aid """
            aug = 'rank=%r\n' % orank
            _kwshow['pnum'] = pnum
            _kwshow['title_aug'] = aug
            #draw_ell = annot_mode == 1
            #draw_lines = annot_mode >= 1
            # If we already are showing the query dont show it here
            if sidebyside:
                # Draw each match side by side the query
                if viz_name_score:
                    cm.show_single_namematch(qreq_, ibs.get_annot_nids(aid), **_kwshow)
                else:
                    _kwshow['draw_border'] = False
                    _kwshow['draw_lbl'] = False
                    _kwshow['notitle'] = True
                    _kwshow['vert'] = False
                    cm.show_single_annotmatch(qreq_, aid, **_kwshow)
                    #viz_matches.show_matches(ibs, cm, aid, qreq_=qreq_, **_kwshow)
            else:
                # Draw each match by themselves
                data_config2_ = None if qreq_ is None else qreq_.get_external_data_config2()
                #_kwshow['draw_border'] = kwargs.get('draw_border', True)
                #_kwshow['notitle'] = ut.get_argflag(('--no-title', '--notitle'))
                viz_chip.show_chip(ibs, aid, annote=False, notitle=True,
                                   data_config2_=data_config2_, **_kwshow)

        if DEBUG_SHOW_QRES:
            print('[show_qres()] Plotting Chips %s:' % vh.get_aidstrs(aid_list))
        if aid_list is None:
            return
        # Do lazy load before show
        #data_config2_ = None if qreq_ is None else qreq_.get_external_data_config2()

        tblhack = getattr(qreq_, 'tablename', None)
        # HACK FOR HUMPBACKS
        # (Also in viz_matches)
        if tblhack == 'vsone' or (qreq_ is not None and not qreq_._isnewreq):
            # precompute
            pass
            #ibs.get_annot_chips(aid_list, config2_=data_config2_, ensure=True)
            #ibs.get_annot_kpts(aid_list, config2_=data_config2_, ensure=True)

        for ox, aid in enumerate(aid_list):
            plotx = ox + plotx_shift + 1
            pnum = (rowcols[0], rowcols[1], plotx)
            oranks = np.where(ranked_aids == aid)[0]
            # This pair has no matches between them.
            if len(oranks) == 0:
                orank = -1
                if aid is None:
                    pt.imshow_null('Failed to find matches\nfor qaid=%r' % (cm.qaid), fnum=fnum, pnum=pnum, fontsize=18)
                else:
                    _show_matches_fn(aid, orank, pnum)
                #if DEBUG_SHOW_QRES:
                #    print('skipping pnum=%r' % (pnum,))
                continue
            if DEBUG_SHOW_QRES:
                print('pnum=%r' % (pnum,))
            orank = oranks[0] + 1
            _show_matches_fn(aid, orank, pnum)
Exemplo n.º 6
0
def show_qres(ibs, cm, qreq_=None, **kwargs):
    """
    Display Query Result Logic
    Defaults to: query chip, groundtruth matches, and top matches

    Args:
        ibs (ibeis.IBEISController):  ibeis controller object
        cm (ibeis.ChipMatch):  object of feature correspondences and scores

    Kwargs:
        in_image (bool) show result  in image view if True else chip view
        annot_mode (int):
            if annot_mode == 0, then draw lines and ellipse
            elif annot_mode == 1, then dont draw lines or ellipse
            elif annot_mode == 2, then draw only lines
        See: viz_matches.show_name_matches, viz_helpers.get_query_text

    Returns:
        mpl.Figure: fig

    CommandLine:
        ./main.py --query 1 -y --db PZ_MTEST --noshow-qtres

        python -m ibeis.viz.viz_qres --test-show_qres --show

        python -m ibeis.viz.viz_qres --test-show_qres --show --top-aids=10 --db=PZ_MTEST --sidebyside --annot_mode=0 --notitle --no-viz_name_score --qaids=5 --max_nCols=2 --adjust=.01,.01,.01

        python -m ibeis.viz.viz_qres --test-show_qres --show --top-aids=10 --db=PZ_MTEST --sidebyside --annot_mode=0 --notitle --no-viz_name_score --qaids=5 --max_nCols=2 --adjust=.01,.01,.01

    Example:
        >>> # DISABLE_DOCTEST
        >>> from ibeis.viz.viz_qres import *  # NOQA
        >>> import plottool as pt
        >>> ibs, cm, qreq_, kwargs = testdata_show_qres()
        >>> # execute function
        >>> fig = show_qres(ibs, cm, show_query=False, qreq_=qreq_, **kwargs)
        >>> # verify results
        >>> #fig.show()
        >>> pt.show_if_requested()
    """
    #ut.print_dict(kwargs)
    annot_mode     = kwargs.get('annot_mode', 1) % 3  # this is toggled
    figtitle       = kwargs.get('figtitle', '')
    make_figtitle  = kwargs.get('make_figtitle', False)
    aug            = kwargs.get('aug', '')
    top_aids       = kwargs.get('top_aids', DEFAULT_NTOP)
    gt_aids        = kwargs.get('gt_aids',   [])
    all_kpts       = kwargs.get('all_kpts', False)
    show_query     = kwargs.get('show_query', False)
    in_image       = kwargs.get('in_image', False)
    sidebyside     = kwargs.get('sidebyside', True)
    #name_scoring   = kwargs.get('name_scoring', False)
    viz_name_score = kwargs.get('viz_name_score', qreq_ is not None)
    max_nCols      = kwargs.get('max_nCols', None)
    failed_to_match = kwargs.get('failed_to_match', False)

    fnum = pt.ensure_fnum(kwargs.get('fnum', None))

    if ut.VERBOSE and ut.NOT_QUIET:
        print('query_info = ' + ut.obj_str(
            ibs.get_annot_info(cm.qaid, default=True, gname=False, name=False, notes=False,
                               exemplar=False), nl=4))
        print('top_aids_info = ' + ut.obj_str(
            ibs.get_annot_info(top_aids, default=True, gname=False, name=False, notes=False,
                               exemplar=False, reference_aid=cm.qaid), nl=4))

    if make_figtitle is True:
        pass
        #figtitle = cm.make_title(pack=True)
        #figtitle

    fig = pt.figure(fnum=fnum, docla=True, doclf=True)

    if isinstance(top_aids, int):
        #if isinstance(cm, chip_match.ChipMatch):
        top_aids = cm.get_top_aids(top_aids)
        #else:
        #    top_aids = cm.get_top_aids(num=top_aids, name_scoring=name_scoring, ibs=ibs)

    if failed_to_match:
        # HACK to visually indicate failure to match in analysis
        top_aids = [None] + top_aids

    nTop = len(top_aids)

    if max_nCols is None:
        max_nCols = 5
        if nTop in [6, 7]:
            max_nCols = 3
        if nTop in [8]:
            max_nCols = 4

    try:
        assert len(list(set(top_aids).intersection(set(gt_aids)))) == 0, (
            'gts should be missed.  not in top')
    except AssertionError as ex:
        ut.printex(ex, keys=['top_aids', 'gt_aids'])
        raise

    if ut.DEBUG2:
        print(cm.get_inspect_str())

    #--------------------------------------------------
    # Get grid / cell information to build subplot grid
    #--------------------------------------------------
    # Show query or not
    nQuerySubplts = 1 if show_query else 0
    # The top row is given slots for ground truths and querys
    # all aids in gt_aids should not be in top aids
    nGtSubplts    = nQuerySubplts + (0 if gt_aids is None else len(gt_aids))
    # The bottom rows are for the top results
    nTopNSubplts  = nTop
    nTopNCols     = min(max_nCols, nTopNSubplts)
    nGTCols       = min(max_nCols, nGtSubplts)
    nGTCols       = max(nGTCols, nTopNCols)
    nTopNCols     = nGTCols
    # Get number of rows to show groundtruth
    nGtRows       = 0 if nGTCols   == 0 else int(np.ceil(nGtSubplts   / nGTCols))
    # Get number of rows to show results
    nTopNRows     = 0 if nTopNCols == 0 else int(np.ceil(nTopNSubplts / nTopNCols))
    nGtCells      = nGtRows * nGTCols
    # Total number of rows
    nRows         = nTopNRows + nGtRows

    DEBUG_SHOW_QRES = 0

    if DEBUG_SHOW_QRES:
        allgt_aids = ibs.get_annot_groundtruth(cm.qaid)
        nSelGt = len(gt_aids)
        nAllGt = len(allgt_aids)
        print('[show_qres]========================')
        print('[show_qres]----------------')
        print('[show_qres] * annot_mode=%r' % (annot_mode,))
        print('[show_qres] #nTop=%r #missed_gts=%r/%r' % (nTop, nSelGt, nAllGt))
        print('[show_qres] * -----')
        print('[show_qres] * nRows=%r' % (nRows,))
        print('[show_qres] * nGtSubplts=%r' % (nGtSubplts,))
        print('[show_qres] * nTopNSubplts=%r' % (nTopNSubplts,))
        print('[show_qres] * nQuerySubplts=%r' % (nQuerySubplts,))
        print('[show_qres] * -----')
        print('[show_qres] * nGTCols=%r' % (nGTCols,))
        print('[show_qres] * -----')
        print('[show_qres] * fnum=%r' % (fnum,))
        print('[show_qres] * figtitle=%r' % (figtitle,))
        print('[show_qres] * max_nCols=%r' % (max_nCols,))
        print('[show_qres] * show_query=%r' % (show_query,))
        print('[show_qres] * kwargs=%s' % (ut.dict_str(kwargs),))

    # HACK:
    _color_list = pt.distinct_colors(nTop)
    aid2_color = {aid: _color_list[ox] for ox, aid in enumerate(top_aids)}
    ranked_aids = cm.get_top_aids()

    # Helpers
    def _show_query_fn(plotx_shift, rowcols):
        """ helper for show_qres """
        plotx = plotx_shift + 1
        pnum = (rowcols[0], rowcols[1], plotx)
        #print('[viz] Plotting Query: pnum=%r' % (pnum,))
        _kwshow = dict(draw_kpts=annot_mode)
        _kwshow.update(kwargs)
        _kwshow['prefix'] = 'q'
        _kwshow['pnum'] = pnum
        _kwshow['aid2_color'] = aid2_color
        _kwshow['draw_ell'] = annot_mode >= 1
        viz_chip.show_chip(ibs, cm.qaid, annote=False, qreq_=qreq_, **_kwshow)

    def _plot_matches_aids(aid_list, plotx_shift, rowcols):
        """ helper for show_qres to draw many aids """
        _kwshow  = dict(draw_ell=annot_mode, draw_pts=False, draw_lines=annot_mode,
                        ell_alpha=.5, all_kpts=all_kpts)
        _kwshow.update(kwargs)
        _kwshow['fnum'] = fnum
        _kwshow['in_image'] = in_image
        if sidebyside:
            # Draw each match side by side the query
            _kwshow['draw_ell'] = annot_mode == 1
            _kwshow['draw_lines'] = annot_mode >= 1
        else:
            #print('annot_mode = %r' % (annot_mode,))
            _kwshow['draw_ell'] = annot_mode == 1
            #_kwshow['draw_pts'] = annot_mode >= 1
            #_kwshow['draw_lines'] = False
            _kwshow['show_query'] = False
        def _show_matches_fn(aid, orank, pnum):
            """ Helper function for drawing matches to one aid """
            aug = 'rank=%r\n' % orank
            _kwshow['pnum'] = pnum
            _kwshow['title_aug'] = aug
            #draw_ell = annot_mode == 1
            #draw_lines = annot_mode >= 1
            # If we already are showing the query dont show it here
            if sidebyside:
                # Draw each match side by side the query
                if viz_name_score:
                    cm.show_single_namematch(qreq_, ibs.get_annot_nids(aid), **_kwshow)
                else:
                    _kwshow['draw_border'] = False
                    _kwshow['draw_lbl'] = False
                    _kwshow['notitle'] = True
                    _kwshow['vert'] = False
                    cm.show_single_annotmatch(qreq_, aid, **_kwshow)
                    #viz_matches.show_matches(ibs, cm, aid, qreq_=qreq_, **_kwshow)
            else:
                # Draw each match by themselves
                data_config2_ = None if qreq_ is None else qreq_.get_external_data_config2()
                #_kwshow['draw_border'] = kwargs.get('draw_border', True)
                #_kwshow['notitle'] = ut.get_argflag(('--no-title', '--notitle'))
                viz_chip.show_chip(ibs, aid, annote=False, notitle=True,
                                   data_config2_=data_config2_, **_kwshow)

        if DEBUG_SHOW_QRES:
            print('[show_qres()] Plotting Chips %s:' % vh.get_aidstrs(aid_list))
        if aid_list is None:
            return
        # Do lazy load before show
        #data_config2_ = None if qreq_ is None else qreq_.get_external_data_config2()

        tblhack = getattr(qreq_, 'tablename', None)
        # HACK FOR HUMPBACKS
        # (Also in viz_matches)
        if tblhack == 'vsone' or (qreq_ is not None and not qreq_._isnewreq):
            # precompute
            pass
            #ibs.get_annot_chips(aid_list, config2_=data_config2_, ensure=True)
            #ibs.get_annot_kpts(aid_list, config2_=data_config2_, ensure=True)

        for ox, aid in enumerate(aid_list):
            plotx = ox + plotx_shift + 1
            pnum = (rowcols[0], rowcols[1], plotx)
            oranks = np.where(ranked_aids == aid)[0]
            # This pair has no matches between them.
            if len(oranks) == 0:
                orank = -1
                if aid is None:
                    pt.imshow_null('Failed to find matches\nfor qaid=%r' % (cm.qaid), fnum=fnum, pnum=pnum, fontsize=18)
                else:
                    _show_matches_fn(aid, orank, pnum)
                #if DEBUG_SHOW_QRES:
                #    print('skipping pnum=%r' % (pnum,))
                continue
            if DEBUG_SHOW_QRES:
                print('pnum=%r' % (pnum,))
            orank = oranks[0] + 1
            _show_matches_fn(aid, orank, pnum)

    shift_topN = nGtCells

    if nGtSubplts == 1:
        nGTCols = 1

    if nRows == 0:
        pt.imshow_null('[viz_qres] No matches. nRows=0', fnum=fnum)
    else:
        fig = pt.figure(fnum=fnum, pnum=(nRows, nGTCols, 1), docla=True, doclf=True)
        pt.plt.subplot(nRows, nGTCols, 1)
        # Plot Query
        if show_query:
            _show_query_fn(0, (nRows, nGTCols))
        # Plot Ground Truth (if given)
        _plot_matches_aids(gt_aids, nQuerySubplts, (nRows, nGTCols))
        # Plot Results
        _plot_matches_aids(top_aids, shift_topN, (nRows, nTopNCols))
        figtitle += aug
    if failed_to_match:
        figtitle += '\n No matches found'

    incanvas = kwargs.get('with_figtitle', not vh.NO_LBL_OVERRIDE)
    pt.set_figtitle(figtitle, incanvas=incanvas)

    # Result Interaction
    return fig
Exemplo n.º 7
0
def show_multi_images(ibs, gid_list, fnum=None, **kwargs):
    r"""
    Args:
        ibs (IBEISController):  ibeis controller object
        gid_list (list):
        fnum (int):  figure number(default = None)

    CommandLine:
        python -m ibeis.viz.viz_image --test-show_multi_images --db NNP_Master3 --gids=7409,7448,4670,7497,7496,7464,7446,7442 --show
        python -m ibeis.viz.viz_image --test-show_multi_images --db NNP_Master3 --gids=1,2,3 --show

    Ignore:
        >>> # print to 8 gids sorted by num aids
        >>> import ibeis
        >>> ibs = ibeis.opendb('NNP_Master3')
        >>> gid_list = ibs.get_valid_gids()
        >>> aids_list = ibs.get_image_aids(gid_list)
        >>> index_list = ut.list_argsort(list(map(len, aids_list)))[::-1]
        >>> gid_list = ut.take(gid_list, index_list[0:8])
        >>> print(','.join(map(str, gid_list)))

    Example:
        >>> # DISABLE_DOCTEST
        >>> from ibeis.viz.viz_image import *  # NOQA
        >>> import ibeis
        >>> ibs = ibeis.opendb(defaultdb='testdb1')
        >>> gid_list = ut.get_argval('--gids', list, default=[1, 2])
        >>> fnum = None
        >>> result = show_multi_images(ibs, gid_list, fnum, draw_lbls=False, notitle=True, sel_aids='all')
        >>> print(result)
        >>> ut.show_if_requested()
    """
    fnum = pt.ensure_fnum(fnum)
    nGids = len(gid_list)
    if nGids == 0:
        fig = pt.figure(fnum=fnum, pnum=(1, 1, 1), **kwargs)
        pt.imshow_null(fnum=fnum, **kwargs)
        return fig
    # Trigger computation of all chips in parallel
    #ibsfuncs.ensure_annotation_data(ibs, aid_list, chips=(not in_image or annote), feats=annote)

    rc = ut.get_argval('--rc', type_=list, default=None)
    if rc is None:
        nRows, nCols = ph.get_square_row_cols(nGids)
    else:
        nRows, nCols = rc
    #notitle = ut.get_argflag('--notitle')
    #draw_lbls = not ut.get_argflag('--no-draw_lbls')
    #show_chip_kw = dict(annote=annote, in_image=in_image, notitle=notitle, draw_lbls=draw_lbls)
    #print('[viz_name] * r=%r, c=%r' % (nRows, nCols))
    #gs2 = gridspec.GridSpec(nRows, nCols)
    pnum_ = pt.get_pnum_func(nRows, nCols)
    fig = pt.figure(fnum=fnum, pnum=pnum_(0), **kwargs)
    fig.clf()
    for px, gid in enumerate(gid_list):
        print(pnum_(px))
        _fig, _ax1 = show_image(ibs, gid, fnum=fnum, pnum=pnum_(px), **kwargs)
        #ax = pt.gca()
        #if aid in sel_aids:
        #    pt.draw_border(ax, pt.GREEN, 4)
        #if ut.get_argflag('--numlbl') and not DOBOTH:
        #    ax.set_xlabel('(' + str(px + 1) + ')')
        #plot_aid3(ibs, aid)
    pass