Beispiel #1
0
 def _on_chip_click(event):
     print_('[inter] clicked chip')
     ax, x, y = event.inaxes, event.xdata, event.ydata
     if ax is None or x is None:
         # The click is not in any axis
         print('... out of axis')
         annote_ptr[0] = (annote_ptr[0] + 1) % 3
         mode = annote_ptr[0]
         draw_ell = mode == 1
         draw_pts = mode == 2
         print('... default kpts view mode=%r' % mode)
         _chip_view(draw_ell=draw_ell, draw_pts=draw_pts)
     else:
         hs_viewtype = ax.__dict__.get('_hs_viewtype', '')
         print_(' hs_viewtype=%r' % hs_viewtype)
         if hs_viewtype == 'chip' and event.key == 'shift':
             print('... masking')
             # TODO: Do better integration of masking
             _chip_view()
             df2.disconnect_callback(fig, 'button_press_event')
             mc = mask_creator.MaskCreator(df2.gca())  # NOQA
         elif hs_viewtype == 'chip':
             kpts = hs.get_kpts(cx)
             if len(kpts) > 0:
                 fx = nearest_point(x, y, kpts)[0]
                 print('... clicked fx=%r' % fx)
                 _select_ith_kpt(fx)
             else:
                 print('... len(kpts) == 0')
         else:
             print('...Unknown viewtype')
     viz.draw()
Beispiel #2
0
 def _ctrlclicked_cx(cx):
     printDBG('ctrl+clicked cx=%r' % cx)
     fnum = FNUMS['special']
     fig = df2.figure(fnum=fnum, docla=True, doclf=True)
     df2.disconnect_callback(fig, 'button_press_event')
     viz_spatial_verification(hs, res.qcx, cx2=cx, fnum=fnum)
     fig.canvas.draw()
     df2.bring_to_front(fig)
Beispiel #3
0
 def _ctrlclicked_cx(cx):
     printDBG('ctrl+clicked cx=%r' % cx)
     fnum = FNUMS['special']
     fig = df2.figure(fnum=fnum, docla=True, doclf=True)
     df2.disconnect_callback(fig, 'button_press_event')
     viz_spatial_verification(hs, res.qcx, cx2=cx, fnum=fnum)
     fig.canvas.draw()
     df2.bring_to_front(fig)
Beispiel #4
0
def _show_res(hs, res, **kwargs):
    ''' Displays query chip, groundtruth matches, and top 5 matches'''
    #printDBG('[viz._show_res()] %s ' % helpers.printableVal(locals()))
    #printDBG = print
    in_image = hs.prefs.display_cfg.show_results_in_image
    annote = kwargs.pop('annote', 2)  # this is toggled
    fnum = kwargs.get('fnum', 3)
    figtitle = kwargs.get('figtitle', '')
    topN_cxs = kwargs.get('topN_cxs', [])
    gt_cxs = kwargs.get('gt_cxs', [])
    all_kpts = kwargs.get('all_kpts', False)
    interact = kwargs.get('interact', True)
    show_query = kwargs.get('show_query', False)
    dosquare = kwargs.get('dosquare', False)
    if SHOW_QUERY_OVERRIDE is not None:
        show_query = SHOW_QUERY_OVERRIDE

    max_nCols = 5
    if len(topN_cxs) in [6, 7]:
        max_nCols = 3
    if len(topN_cxs) in [8]:
        max_nCols = 4

    printDBG('========================')
    printDBG('[viz._show_res()]----------------')
    all_gts = hs.get_other_indexed_cxs(res.qcx)
    _tup = tuple(map(len, (topN_cxs, gt_cxs, all_gts)))
    printDBG('[viz._show_res()] #topN=%r #missed_gts=%r/%r' % _tup)
    printDBG('[viz._show_res()] * fnum=%r' % (fnum, ))
    printDBG('[viz._show_res()] * figtitle=%r' % (figtitle, ))
    printDBG('[viz._show_res()] * max_nCols=%r' % (max_nCols, ))
    printDBG('[viz._show_res()] * show_query=%r' % (show_query, ))
    ranked_cxs = res.topN_cxs(hs, N='all')
    # Build a subplot grid
    nQuerySubplts = 1 if show_query else 0
    nGtSubplts = nQuerySubplts + (0 if gt_cxs is None else len(gt_cxs))
    nTopNSubplts = 0 if topN_cxs is None else len(topN_cxs)
    nTopNCols = min(max_nCols, nTopNSubplts)
    nGTCols = min(max_nCols, nGtSubplts)
    nGTCols = max(nGTCols, nTopNCols)
    nTopNCols = nGTCols
    nGtRows = 0 if nGTCols == 0 else int(np.ceil(nGtSubplts / nGTCols))
    nTopNRows = 0 if nTopNCols == 0 else int(np.ceil(nTopNSubplts / nTopNCols))
    nGtCells = nGtRows * nGTCols
    nRows = nTopNRows + nGtRows

    # HACK:
    _color_list = df2.distinct_colors(len(topN_cxs))
    cx2_color = {cx: _color_list[ox] for ox, cx in enumerate(topN_cxs)}

    if IN_IMAGE_OVERRIDE is not None:
        in_image = IN_IMAGE_OVERRIDE

    # Helpers
    def _show_query_fn(plotx_shift, rowcols):
        'helper for viz._show_res'
        plotx = plotx_shift + 1
        pnum = (rowcols[0], rowcols[1], plotx)
        #print('[viz] Plotting Query: pnum=%r' % (pnum,))
        _kwshow = dict(draw_kpts=annote)
        _kwshow.update(kwargs)
        _kwshow['prefix'] = 'q'
        _kwshow['res'] = res
        _kwshow['pnum'] = pnum
        _kwshow['cx2_color'] = cx2_color
        _kwshow['draw_ell'] = annote >= 1
        #_kwshow['in_image'] = in_image
        show_chip(hs, **_kwshow)
        #if in_image:
        #roi1 = hs.cx2_roi(res.qcx)
        #df2.draw_roi(roi1, bbox_color=df2.ORANGE, label='q' + hs.cidstr(res.qcx))

    def _plot_matches_cxs(cx_list, plotx_shift, rowcols):
        def _show_matches_fn(cx, orank, pnum):
            'Helper function for drawing matches to one cx'
            aug = 'rank=%r\n' % orank
            #printDBG('[viz._show_res()] plotting: %r'  % (pnum,))
            _kwshow = dict(draw_ell=annote,
                           draw_pts=False,
                           draw_lines=annote,
                           ell_alpha=.5,
                           all_kpts=all_kpts)
            _kwshow.update(kwargs)
            _kwshow['fnum'] = fnum
            _kwshow['pnum'] = pnum
            _kwshow['title_aug'] = aug
            # If we already are showing the query dont show it here
            if not show_query:
                _kwshow['draw_ell'] = annote == 1
                _kwshow['draw_lines'] = annote >= 1
                res_show_chipres(res, hs, cx, in_image=in_image, **_kwshow)
            else:
                _kwshow['draw_ell'] = annote >= 1
                if annote == 2:
                    # TODO Find a better name
                    _kwshow['color'] = cx2_color[cx]
                    _kwshow['sel_fx2'] = res.cx2_fm[cx][:, 1]
                show_chip(hs, cx, in_image=in_image, **_kwshow)
                annotate_chipres(hs,
                                 res,
                                 cx,
                                 in_image=in_image,
                                 show_query=not show_query)

        'helper for viz._show_res to draw many cxs'
        #printDBG('[viz._show_res()] Plotting Chips %s:' % hs.cidstr(cx_list))
        if cx_list is None:
            return
        for ox, cx in enumerate(cx_list):
            plotx = ox + plotx_shift + 1
            pnum = (rowcols[0], rowcols[1], plotx)
            oranks = np.where(ranked_cxs == cx)[0]
            if len(oranks) == 0:
                orank = -1
                continue
            orank = oranks[0] + 1
            _show_matches_fn(cx, orank, pnum)

    if dosquare:
        # HACK
        nSubplots = nGtSubplts + nTopNSubplts
        nRows, nCols = get_square_row_cols(nSubplots, 3)
        nTopNCols = nGTCols = nCols
        shift_topN = 1
        printDBG('nRows, nCols = (%r, %r)' % (nRows, nCols))
    else:
        shift_topN = nGtCells

    if nGtSubplts == 1:
        nGTCols = 1

    fig = df2.figure(fnum=fnum,
                     pnum=(nRows, nGTCols, 1),
                     docla=True,
                     doclf=True)
    df2.disconnect_callback(fig, 'button_press_event')
    df2.plt.subplot(nRows, nGTCols, 1)
    # Plot Query
    if show_query:
        _show_query_fn(0, (nRows, nGTCols))
    # Plot Ground Truth
    _plot_matches_cxs(gt_cxs, nQuerySubplts, (nRows, nGTCols))
    _plot_matches_cxs(topN_cxs, shift_topN, (nRows, nTopNCols))
    figtitle += ' q%s name=%s' % (hs.cidstr(res.qcx), hs.cx2_name(res.qcx))
    df2.set_figtitle(figtitle, incanvas=not NO_LABEL_OVERRIDE)

    # Result Interaction
    if interact:
        printDBG('[viz._show_res()] starting interaction')

        def _ctrlclicked_cx(cx):
            printDBG('ctrl+clicked cx=%r' % cx)
            fnum = FNUMS['special']
            fig = df2.figure(fnum=fnum, docla=True, doclf=True)
            df2.disconnect_callback(fig, 'button_press_event')
            viz_spatial_verification(hs, res.qcx, cx2=cx, fnum=fnum)
            fig.canvas.draw()
            df2.bring_to_front(fig)

        def _clicked_cx(cx):
            printDBG('clicked cx=%r' % cx)
            fnum = FNUMS['inspect']
            res.interact_chipres(hs, cx, fnum=fnum)
            fig = df2.gcf()
            fig.canvas.draw()
            df2.bring_to_front(fig)

        def _clicked_none():
            # Toggle if the click is not in any axis
            printDBG('clicked none')
            #print(kwargs)
            _show_res(hs, res, annote=(annote + 1) % 3, **kwargs)
            fig.canvas.draw()

        def _on_res_click(event):
            'result interaction mpl event callback slot'
            print('[viz] clicked result')
            if event.xdata is None or event.inaxes is None:
                #print('clicked outside axes')
                return _clicked_none()
            ax = event.inaxes
            hs_viewtype = ax.__dict__.get('_hs_viewtype', '')
            printDBG(event.__dict__)
            printDBG('hs_viewtype=%r' % hs_viewtype)
            # Clicked a specific chipres
            if hs_viewtype.find('chipres') == 0:
                cx = ax.__dict__.get('_hs_cx')
                # Ctrl-Click
                key = '' if event.key is None else event.key
                print('key = %r' % key)
                if key.find('control') == 0:
                    print('[viz] result control clicked')
                    return _ctrlclicked_cx(cx)
                # Left-Click
                else:
                    print('[viz] result clicked')
                    return _clicked_cx(cx)

        df2.connect_callback(fig, 'button_press_event', _on_res_click)
    df2.adjust_subplots_safe()
    printDBG('[viz._show_res()] Finished')
    return fig
Beispiel #5
0
def _show_res(hs, res, **kwargs):
    ''' Displays query chip, groundtruth matches, and top 5 matches'''
    #printDBG('[viz._show_res()] %s ' % helpers.printableVal(locals()))
    #printDBG = print
    in_image = hs.prefs.display_cfg.show_results_in_image
    annote     = kwargs.pop('annote', 2)  # this is toggled
    fnum       = kwargs.get('fnum', 3)
    figtitle   = kwargs.get('figtitle', '')
    topN_cxs   = kwargs.get('topN_cxs', [])
    gt_cxs     = kwargs.get('gt_cxs',   [])
    all_kpts   = kwargs.get('all_kpts', False)
    interact   = kwargs.get('interact', True)
    show_query = kwargs.get('show_query', False)
    dosquare   = kwargs.get('dosquare', False)
    if SHOW_QUERY_OVERRIDE is not None:
        show_query = SHOW_QUERY_OVERRIDE

    max_nCols = 5
    if len(topN_cxs) in [6, 7]:
        max_nCols = 3
    if len(topN_cxs) in [8]:
        max_nCols = 4

    printDBG('========================')
    printDBG('[viz._show_res()]----------------')
    all_gts = hs.get_other_indexed_cxs(res.qcx)
    _tup = tuple(map(len, (topN_cxs, gt_cxs, all_gts)))
    printDBG('[viz._show_res()] #topN=%r #missed_gts=%r/%r' % _tup)
    printDBG('[viz._show_res()] * fnum=%r' % (fnum,))
    printDBG('[viz._show_res()] * figtitle=%r' % (figtitle,))
    printDBG('[viz._show_res()] * max_nCols=%r' % (max_nCols,))
    printDBG('[viz._show_res()] * show_query=%r' % (show_query,))
    ranked_cxs = res.topN_cxs(hs, N='all')
    # Build a subplot grid
    nQuerySubplts = 1 if show_query else 0
    nGtSubplts    = nQuerySubplts + (0 if gt_cxs is None else len(gt_cxs))
    nTopNSubplts  = 0 if topN_cxs is None else len(topN_cxs)
    nTopNCols     = min(max_nCols, nTopNSubplts)
    nGTCols       = min(max_nCols, nGtSubplts)
    nGTCols       = max(nGTCols, nTopNCols)
    nTopNCols     = nGTCols
    nGtRows       = 0 if nGTCols == 0 else int(np.ceil(nGtSubplts / nGTCols))
    nTopNRows     = 0 if nTopNCols == 0 else int(np.ceil(nTopNSubplts / nTopNCols))
    nGtCells      = nGtRows * nGTCols
    nRows         = nTopNRows + nGtRows

    # HACK:
    _color_list = df2.distinct_colors(len(topN_cxs))
    cx2_color = {cx: _color_list[ox] for ox, cx in enumerate(topN_cxs)}

    if IN_IMAGE_OVERRIDE is not None:
        in_image = IN_IMAGE_OVERRIDE

    # Helpers
    def _show_query_fn(plotx_shift, rowcols):
        'helper for viz._show_res'
        plotx = plotx_shift + 1
        pnum = (rowcols[0], rowcols[1], plotx)
        #print('[viz] Plotting Query: pnum=%r' % (pnum,))
        _kwshow = dict(draw_kpts=annote)
        _kwshow.update(kwargs)
        _kwshow['prefix'] = 'q'
        _kwshow['res'] = res
        _kwshow['pnum'] = pnum
        _kwshow['cx2_color'] = cx2_color
        _kwshow['draw_ell'] = annote >= 1
        #_kwshow['in_image'] = in_image
        show_chip(hs, **_kwshow)
        #if in_image:
            #roi1 = hs.cx2_roi(res.qcx)
            #df2.draw_roi(roi1, bbox_color=df2.ORANGE, label='q' + hs.cidstr(res.qcx))

    def _plot_matches_cxs(cx_list, plotx_shift, rowcols):

        def _show_matches_fn(cx, orank, pnum):
            'Helper function for drawing matches to one cx'
            aug = 'rank=%r\n' % orank
            #printDBG('[viz._show_res()] plotting: %r'  % (pnum,))
            _kwshow  = dict(draw_ell=annote, draw_pts=False, draw_lines=annote,
                            ell_alpha=.5, all_kpts=all_kpts)
            _kwshow.update(kwargs)
            _kwshow['fnum'] = fnum
            _kwshow['pnum'] = pnum
            _kwshow['title_aug'] = aug
            # If we already are showing the query dont show it here
            if not show_query:
                _kwshow['draw_ell'] = annote == 1
                _kwshow['draw_lines'] = annote >= 1
                res_show_chipres(res, hs, cx, in_image=in_image, **_kwshow)
            else:
                _kwshow['draw_ell'] = annote >= 1
                if annote == 2:
                    # TODO Find a better name
                    _kwshow['color'] = cx2_color[cx]
                    _kwshow['sel_fx2'] = res.cx2_fm[cx][:, 1]
                show_chip(hs, cx, in_image=in_image, **_kwshow)
                annotate_chipres(hs, res, cx, in_image=in_image, show_query=not show_query)

        'helper for viz._show_res to draw many cxs'
        #printDBG('[viz._show_res()] Plotting Chips %s:' % hs.cidstr(cx_list))
        if cx_list is None:
            return
        for ox, cx in enumerate(cx_list):
            plotx = ox + plotx_shift + 1
            pnum = (rowcols[0], rowcols[1], plotx)
            oranks = np.where(ranked_cxs == cx)[0]
            if len(oranks) == 0:
                orank = -1
                continue
            orank = oranks[0] + 1
            _show_matches_fn(cx, orank, pnum)

    if dosquare:
        # HACK
        nSubplots = nGtSubplts + nTopNSubplts
        nRows, nCols = get_square_row_cols(nSubplots, 3)
        nTopNCols = nGTCols = nCols
        shift_topN = 1
        printDBG('nRows, nCols = (%r, %r)' % (nRows, nCols))
    else:
        shift_topN = nGtCells

    if nGtSubplts == 1:
        nGTCols = 1

    fig = df2.figure(fnum=fnum, pnum=(nRows, nGTCols, 1), docla=True, doclf=True)
    df2.disconnect_callback(fig, 'button_press_event')
    df2.plt.subplot(nRows, nGTCols, 1)
    # Plot Query
    if show_query:
        _show_query_fn(0, (nRows, nGTCols))
    # Plot Ground Truth
    _plot_matches_cxs(gt_cxs, nQuerySubplts, (nRows, nGTCols))
    _plot_matches_cxs(topN_cxs, shift_topN, (nRows, nTopNCols))
    figtitle += ' q%s name=%s' % (hs.cidstr(res.qcx), hs.cx2_name(res.qcx))
    df2.set_figtitle(figtitle, incanvas=not NO_LABEL_OVERRIDE)

    # Result Interaction
    if interact:
        printDBG('[viz._show_res()] starting interaction')

        def _ctrlclicked_cx(cx):
            printDBG('ctrl+clicked cx=%r' % cx)
            fnum = FNUMS['special']
            fig = df2.figure(fnum=fnum, docla=True, doclf=True)
            df2.disconnect_callback(fig, 'button_press_event')
            viz_spatial_verification(hs, res.qcx, cx2=cx, fnum=fnum)
            fig.canvas.draw()
            df2.bring_to_front(fig)

        def _clicked_cx(cx):
            printDBG('clicked cx=%r' % cx)
            fnum = FNUMS['inspect']
            res.interact_chipres(hs, cx, fnum=fnum)
            fig = df2.gcf()
            fig.canvas.draw()
            df2.bring_to_front(fig)

        def _clicked_none():
            # Toggle if the click is not in any axis
            printDBG('clicked none')
            #print(kwargs)
            _show_res(hs, res, annote=(annote + 1) % 3, **kwargs)
            fig.canvas.draw()

        def _on_res_click(event):
            'result interaction mpl event callback slot'
            print('[viz] clicked result')
            if event.xdata is None or event.inaxes is None:
                #print('clicked outside axes')
                return _clicked_none()
            ax = event.inaxes
            hs_viewtype = ax.__dict__.get('_hs_viewtype', '')
            printDBG(event.__dict__)
            printDBG('hs_viewtype=%r' % hs_viewtype)
            # Clicked a specific chipres
            if hs_viewtype.find('chipres') == 0:
                cx = ax.__dict__.get('_hs_cx')
                # Ctrl-Click
                key = '' if event.key is None else event.key
                print('key = %r' % key)
                if key.find('control') == 0:
                    print('[viz] result control clicked')
                    return _ctrlclicked_cx(cx)
                # Left-Click
                else:
                    print('[viz] result clicked')
                    return _clicked_cx(cx)

        df2.connect_callback(fig, 'button_press_event', _on_res_click)
    df2.adjust_subplots_safe()
    printDBG('[viz._show_res()] Finished')
    return fig
Beispiel #6
0
def begin_interaction(type_, fnum):
    print('[inter] starting %s interaction' % type_)
    fig = df2.figure(fnum=fnum, docla=True, doclf=True)
    ax = df2.gca()
    df2.disconnect_callback(fig, 'button_press_event', axes=[ax])
    return fig
Beispiel #7
0
 def _sv_view(cx):
     fnum = viz.FNUMS['special']
     fig = df2.figure(fnum=fnum, docla=True, doclf=True)
     df2.disconnect_callback(fig, 'button_press_event')
     viz.viz_spatial_verification(hs, res.qcx, cx2=cx, fnum=fnum)
     viz.draw()