Beispiel #1
0
def ishow_sver(ibs, aid1, aid2, chipmatch_FILT=None, aid2_svtup=None, fnum=None, **kwargs):
    fig = ih.begin_interaction('sver', fnum)
    mode_ptr = [2]
    if chipmatch_FILT is None or aid2_svtup is None:
        chipmatch_FILT, aid2_svtup = viz._compute_svvars(ibs, aid1)

    def _sv_view(**kwargs):
        kwargs['show_assign'] = kwargs.get('show_assign', False)
        viz.show_sver(ibs, aid1, aid2, chipmatch_FILT, aid2_svtup, fnum=fnum, **kwargs)

    def _on_sv_click(event):
        print_('[inter] clicked sv')
        ax = event.inaxes
        if ih.clicked_outside_axis(event):
            print('... out of axis')
            mode_ptr[0] = (mode_ptr[0] + 1) % 3
            kwargs['show_kpts']  = mode_ptr[0] == 2
            kwargs['show_lines'] = mode_ptr[0] >= 1
            _sv_view(**kwargs)
        else:
            viztype = vh.get_ibsdat(ax, 'viztype')
            print_('[ic] viztype=%r' % viztype)
            if viztype in ['homogblend', 'affblend', 'source', 'dest']:
                pass
            else:
                print('...Unknown viztype: %r' % viztype)
        viz.draw()

    _sv_view()
    viz.draw()
    ih.connect_callback(fig, 'button_press_event', _on_sv_click)
Beispiel #2
0
def ishow_sver(ibs, aid1, aid2, chipmatch_FILT=None, aid2_svtup=None, fnum=None, **kwargs):
    fig = ih.begin_interaction('sver', fnum)
    mode_ptr = [2]
    if chipmatch_FILT is None or aid2_svtup is None:
        chipmatch_FILT, aid2_svtup = viz._compute_svvars(ibs, aid1)

    def _sv_view(**kwargs):
        kwargs['show_assign'] = kwargs.get('show_assign', False)
        viz.show_sver(ibs, aid1, aid2, chipmatch_FILT, aid2_svtup, fnum=fnum, **kwargs)

    def _on_sv_click(event):
        print_('[inter] clicked sv')
        ax = event.inaxes
        if ih.clicked_outside_axis(event):
            print('... out of axis')
            mode_ptr[0] = (mode_ptr[0] + 1) % 3
            kwargs['show_kpts']  = mode_ptr[0] == 2
            kwargs['show_lines'] = mode_ptr[0] >= 1
            _sv_view(**kwargs)
        else:
            viztype = vh.get_ibsdat(ax, 'viztype')
            print_('[ic] viztype=%r' % viztype)
            if viztype in ['homogblend', 'affblend', 'source', 'dest']:
                pass
            else:
                print('...Unknown viztype: %r' % viztype)
        viz.draw()

    _sv_view()
    viz.draw()
    ih.connect_callback(fig, 'button_press_event', _on_sv_click)
Beispiel #3
0
def iselect_bbox(ibs, gid, fnum=1,
                 figtitle='Image View - Select ANNOTATION (click two points)',
                 **kwargs):
    #from matplotlib.backend_bases import mplDeprecation
    print('[*interact] select_bbox(gid=%r, fnum=%r)' % (gid, fnum))
    print('[*interact] Define a Rectanglular ANNOTATION by clicking two points.')
    # Show the image
    fig = ih.begin_interaction('select_bbox', fnum)
    fig_presenter.bring_to_front(fig)
    viz.show_image(ibs, gid, **kwargs)
    try:
        viz.draw()
        fig = df2.gcf()
        pts = fig.ginput(2)
        print('[*guitools] ginput(2) = %r' % (pts,))
        [(x1, y1), (x2, y2)] = pts
        xm = min(x1, x2)
        xM = max(x1, x2)
        ym = min(y1, y2)
        yM = max(y1, y2)
        bbox = tuple(map(int, map(round, (xm, ym, xM - xm, yM - ym))))
        # Reconnect the old button press events
        print('[*interact] bbox = %r ' % (bbox,))
        return bbox
    except Exception as ex:
        print('<!!!>')
        print('[*interact] Caught: %s %s' % (type(ex), ex))
        print('[*interact] ANNOTATION selection Failed:')
        print('</!!!>')
        raise
Beispiel #4
0
def iselect_bbox(ibs, gid, fnum=1,
                 figtitle='Image View - Select ANNOTATION (click two points)',
                 **kwargs):
    #from matplotlib.backend_bases import mplDeprecation
    print('[*interact] select_bbox(gid=%r, fnum=%r)' % (gid, fnum))
    print('[*interact] Define a Rectanglular ANNOTATION by clicking two points.')
    # Show the image
    fig = ih.begin_interaction('select_bbox', fnum)
    fig_presenter.bring_to_front(fig)
    viz.show_image(ibs, gid, **kwargs)
    try:
        viz.draw()
        fig = df2.gcf()
        pts = fig.ginput(2)
        print('[*guitools] ginput(2) = %r' % (pts,))
        [(x1, y1), (x2, y2)] = pts
        xm = min(x1, x2)
        xM = max(x1, x2)
        ym = min(y1, y2)
        yM = max(y1, y2)
        bbox = tuple(map(int, map(round, (xm, ym, xM - xm, yM - ym))))
        # Reconnect the old button press events
        print('[*interact] bbox = %r ' % (bbox,))
        return bbox
    except Exception as ex:
        print('<!!!>')
        print('[*interact] Caught: %s %s' % (type(ex), ex))
        print('[*interact] ANNOTATION selection Failed:')
        print('</!!!>')
        raise
Beispiel #5
0
    def show_page(self):
        if self.fig is None:
            raise AssertionError('fig is None, did you run interction.start()?')
        import plottool as pt
        fig = ih.begin_interaction('expandable', self.fnum)
        if not any(self.pnum_list) and self.nRows is None and self.nRows is None:
            # Hack if no pnum was given
            self.nRows, self.nCols = pt.get_num_rc(len(self.pnum_list),
                                                   nRows=self.nRows,
                                                   nCols=self.nCols)
            nSubplots = len(self.func_list)
            pnum_ = pt.make_pnum_nextgen(self.nRows, self.nCols, nSubplots=nSubplots)
            self.pnum_list = [pnum_() for _ in self.pnum_list]

        for index, (pnum, func) in enumerate(zip(self.pnum_list, self.func_list)):
            if check_if_subinteract(func):
                # Hack
                interclass = func
                interclass.static_plot(fnum=self.fnum, pnum=pnum)
            elif hasattr(func, 'plot'):
                inter = func
                inter.plot(fnum=self.fnum, pnum=pnum)
            else:
                func(fnum=self.fnum, pnum=pnum)
            ax = pt.gca()
            pt.set_plotdat(ax, 'plot_func', func)
            pt.set_plotdat(ax, 'expandable_index', index)
        #if self.interactive is None or self.interactive:
        #    ih.connect_callback(fig, 'button_press_event', self.onclick)
        self.connect_callbacks()
        self.fig = fig
        return fig
Beispiel #6
0
def ishow_image(ibs, gid, sel_aids=[], fnum=None, select_callback=None,
                **kwargs):
    if ut.VERBOSE:
        print(ut.get_caller_name(range(9)))
        print('[interact_image] gid=%r fnum=%r' % (gid, fnum,))
    if fnum is None:
        fnum = df2.next_fnum()
    # TODO: change to class based structure
    self = ut.DynStruct()
    self.fnum = fnum

    fig = ih.begin_interaction('image', fnum)
    #printDBG(utool.func_str(interact_image, [], locals()))
    kwargs['draw_lbls'] = kwargs.get('draw_lbls', True)

    def _image_view(sel_aids=sel_aids, **_kwargs):
        try:
            viz.show_image(ibs, gid, sel_aids=sel_aids, fnum=self.fnum, **_kwargs)
            df2.set_figtitle('Image View')
        except TypeError as ex:
            ut.printex(ex, ut.dict_str(_kwargs))
            raise

    # Create callback wrapper
    def _on_image_click(event):
        printDBG('[inter] clicked image')
        if ih.clicked_outside_axis(event):
            # Toggle draw lbls
            kwargs['draw_lbls'] = not kwargs.get('draw_lbls', True)
            _image_view(**kwargs)
        else:
            ax          = event.inaxes
            viztype     = vh.get_ibsdat(ax, 'viztype')
            annotation_centers = vh.get_ibsdat(ax, 'annotation_centers', default=[])
            printDBG(' annotation_centers=%r' % annotation_centers)
            printDBG(' viztype=%r' % viztype)
            if len(annotation_centers) == 0:
                print(' ...no chips exist to click')
                return
            x, y = event.xdata, event.ydata
            # Find ANNOTATION center nearest to the clicked point
            aid_list = vh.get_ibsdat(ax, 'aid_list', default=[])
            centx, _dist = ut.nearest_point(x, y, annotation_centers)
            aid = aid_list[centx]
            print(' ...clicked aid=%r' % aid)
            if select_callback is not None:
                # HACK, should just implement this correctly here
                select_callback(gid, sel_aids=[aid], fnum=self.fnum)
            else:
                _image_view(sel_aids=[aid])

        viz.draw()

    _image_view(**kwargs)
    viz.draw()
    ih.connect_callback(fig, 'button_press_event', _on_image_click)
Beispiel #7
0
 def show_page(self, *args):
     """
     Hack: this function should probably not be defined, but it is for
     convinience of a developer.
     Override this or create static plot function
     (preferably override)
     """
     self._ensure_running()
     if self.debug:
         print('[pt.a] show page')
     self.fig = ih.begin_interaction(self.interaction_name, self.fnum)
     if hasattr(self, 'plot'):
         self.plot(self.fnum, (1, 1, 1))
     else:
         self.static_plot(self.fnum, (1, 1, 1))
     self.connect_callbacks()
 def show_page(self, *args):
     """
     Hack: this function should probably not be defined, but it is for
     convinience of a developer.
     Override this or create static plot function
     (preferably override)
     """
     self._ensure_running()
     if self.debug:
         print('[pt.a] show page')
     self.fig = ih.begin_interaction(self.interaction_name, self.fnum)
     if hasattr(self, 'plot'):
         self.plot(self.fnum, (1, 1, 1))
     else:
         self.static_plot(self.fnum, (1, 1, 1))
     self.connect_callbacks()
Beispiel #9
0
def ishow_image(ibs, gid, sel_aids=[], fnum=1, select_callback=None,
                **kwargs):
    fig = ih.begin_interaction('image', fnum)
    #printDBG(utool.func_str(interact_image, [], locals()))
    kwargs['draw_lbls'] = kwargs.get('draw_lbls', True)

    def _image_view(sel_aids=sel_aids, **_kwargs):
        try:
            viz.show_image(ibs, gid, sel_aids=sel_aids, fnum=fnum, **_kwargs)
            df2.set_figtitle('Image View')
        except TypeError as ex:
            utool.printex(ex, utool.dict_str(_kwargs))
            raise

    # Create callback wrapper
    def _on_image_click(event):
        printDBG('[inter] clicked image')
        if ih.clicked_outside_axis(event):
            # Toggle draw lbls
            kwargs['draw_lbls'] = not kwargs.get('draw_lbls', True)
            _image_view(**kwargs)
        else:
            ax          = event.inaxes
            viztype     = vh.get_ibsdat(ax, 'viztype')
            annotation_centers = vh.get_ibsdat(ax, 'annotation_centers', default=[])
            printDBG(' annotation_centers=%r' % annotation_centers)
            printDBG(' viztype=%r' % viztype)
            if len(annotation_centers) == 0:
                print(' ...no chips exist to click')
                return
            x, y = event.xdata, event.ydata
            # Find ANNOTATION center nearest to the clicked point
            aid_list = vh.get_ibsdat(ax, 'aid_list', default=[])
            centx, _dist = utool.nearest_point(x, y, annotation_centers)
            aid = aid_list[centx]
            print(' ...clicked aid=%r' % aid)
            if select_callback is not None:
                select_callback(gid, sel_aids=[aid])
            else:
                _image_view(sel_aids=[aid])

        viz.draw()

    _image_view(**kwargs)
    viz.draw()
    ih.connect_callback(fig, 'button_press_event', _on_image_click)
Beispiel #10
0
def ishow_matches(ibs, qres, aid=None, fnum=4, figtitle='Inspect Query Result',
                  same_fig=True, **kwargs):
    """ Plots a chip result and sets up callbacks for interaction. """
    fig = ih.begin_interaction('matches', fnum)
    qaid = qres.qaid
    if aid is None:
        aid = qres.get_top_aids(num=1)[0]
    rchip1, rchip2 = ibs.get_annot_chips([qaid, aid])
    fm = qres.aid2_fm[aid]
    mx = kwargs.pop('mx', None)
    xywh2_ptr = [None]
    annote_ptr = [kwargs.pop('mode', 0)]
    last_state = LastState()
    last_state.same_fig = same_fig
    last_state.last_fx = 0

    # Draw default
    def _chipmatch_view(pnum=(1, 1, 1), **kwargs):
        mode = annote_ptr[0]  # drawing mode draw: with/without lines/feats
        draw_ell = mode >= 1
        draw_lines = mode == 2
        annote_ptr[0] = (annote_ptr[0] + 1) % 3
        df2.figure(fnum=fnum, docla=True, doclf=True)
        # TODO RENAME This to remove qres and rectify with show_matches
        tup = viz.show_matches(ibs, qres, aid, fnum=fnum, pnum=pnum,
                               draw_lines=draw_lines, draw_ell=draw_ell,
                               colorbar_=True, **kwargs)
        ax, xywh1, xywh2 = tup
        xywh2_ptr[0] = xywh2

        df2.set_figtitle(figtitle + ' ' + vh.get_vsstr(qaid, aid))

    # Draw clicked selection
    def _select_ith_match(mx, qaid, aid):
        #----------------------
        # Get info for the _select_ith_match plot
        annote_ptr[0] = 1
        # Get the mx-th feature match
        aid1, aid2 = qaid, aid
        fx1, fx2 = fm[mx]
        fscore2  = qres.aid2_fs[aid2][mx]
        fk2      = qres.aid2_fk[aid2][mx]
        kpts1, kpts2 = ibs.get_annot_kpts([aid1, aid2])
        desc1, desc2 = ibs.get_annot_desc([aid1, aid2])
        kp1, kp2     = kpts1[fx1], kpts2[fx2]
        sift1, sift2 = desc1[fx1], desc2[fx2]
        info1 = '\nquery'
        info2 = '\nk=%r fscore=%r' % (fk2, fscore2)
        last_state.last_fx = fx1

        # Extracted keypoints to draw
        extracted_list = [(rchip1, kp1, sift1, fx1, aid1, info1),
                          (rchip2, kp2, sift2, fx2, aid2, info2)]
        # Normalizng Keypoint
        if hasattr(qres, 'filt2_meta') and 'lnbnn' in qres.filt2_meta:
            qfx2_norm = qres.filt2_meta['lnbnn']
            # Normalizing chip and feature
            (aid3, fx3, normk) = qfx2_norm[fx1]
            rchip3 = ibs.get_annot_chips(aid3)
            kp3 = ibs.get_annot_kpts(aid3)[fx3]
            sift3 = ibs.get_annot_desc(aid3)[fx3]
            info3 = '\nnorm %s k=%r' % (vh.get_aidstrs(aid3), normk)
            extracted_list.append((rchip3, kp3, sift3, fx3, aid3, info3))
        else:
            print('WARNING: meta doesnt exist')

        #----------------------
        # Draw the _select_ith_match plot
        nRows, nCols = len(extracted_list) + same_fig, 3
        # Draw matching chips and features
        sel_fm = np.array([(fx1, fx2)])
        pnum1 = (nRows, 1, 1) if same_fig else (1, 1, 1)
        _chipmatch_view(pnum1, vert=False, ell_alpha=.4, ell_linewidth=1.8,
                        colors=df2.BLUE, sel_fm=sel_fm, **kwargs)
        # Draw selected feature matches
        px = nCols * same_fig  # plot offset
        prevsift = None
        if not same_fig:
            fnum2 = fnum + len(viz.FNUMS)
            fig2 = df2.figure(fnum=fnum2, docla=True, doclf=True)
        else:
            fnum2 = fnum
        for (rchip, kp, sift, fx, aid, info) in extracted_list:
            px = draw_feat_row(rchip, fx, kp, sift, fnum2, nRows, nCols, px,
                               prevsift=prevsift, aid=aid, info=info)
            prevsift = sift
        if not same_fig:
            ih.connect_callback(fig2, 'button_press_event', _click_matches_click)
            df2.set_figtitle(figtitle + vh.get_vsstr(qaid, aid))

    # Draw ctrl clicked selection
    def _sv_view(aid):
        fnum = viz.FNUMS['special']
        fig = df2.figure(fnum=fnum, docla=True, doclf=True)
        ih.disconnect_callback(fig, 'button_press_event')
        viz.show_sv(ibs, qres.qaid, aid2=aid, fnum=fnum)
        viz.draw()

    # Callback
    def _click_matches_click(event):
        print_('[inter] clicked matches')
        if event is None:
            return
        button = event.button
        is_right_click = button == 3
        if is_right_click:
            return
        (x, y, ax) = (event.xdata, event.ydata, event.inaxes)
        # Out of axes click
        if None in [x, y, ax]:
            print('... out of axis')
            _chipmatch_view()
            viz.draw()
            return
        viztype = vh.get_ibsdat(ax, 'viztype', '')
        print_('[ir] viztype=%r ' % viztype)
        key = '' if event.key is None else event.key
        print_('key=%r ' % key)
        ctrl_down = key.find('control') == 0
        # Click in match axes
        if viztype == 'matches' and ctrl_down:
            # Ctrl-Click
            print('.. control click')
            return _sv_view(aid)
        elif viztype == 'matches':
            if len(fm) == 0:
                print('[inter] no feature matches to click')
            else:
                # Normal Click
                # Select nearest feature match to the click
                kpts1, kpts2 = ibs.get_annot_kpts([qaid, aid])
                kpts1_m = kpts1[fm[:, 0]]
                kpts2_m = kpts2[fm[:, 1]]
                x2, y2, w2, h2 = xywh2_ptr[0]
                _mx1, _dist1 = utool.nearest_point(x, y, kpts1_m)
                _mx2, _dist2 = utool.nearest_point(x - x2, y - y2, kpts2_m)
                mx = _mx1 if _dist1 < _dist2 else _mx2
                print('... clicked mx=%r' % mx)
                _select_ith_match(mx, qaid, aid)
        elif viztype in ['warped', 'unwarped']:
            hs_aid = ax.__dict__.get('_hs_aid', None)
            hs_fx = ax.__dict__.get('_hs_fx', None)
            if hs_aid is not None and viztype == 'unwarped':
                ishow_chip(ibs, hs_aid, fx=hs_fx, fnum=df2.next_fnum())
            elif hs_aid is not None and viztype == 'warped':
                viz.show_keypoint_gradient_orientations(ibs, hs_aid, hs_fx, fnum=df2.next_fnum())
        else:
            print('...Unknown viztype: %r' % viztype)
        viz.draw()

    if mx is None:
        _chipmatch_view()
    else:
        _select_ith_match(mx, qaid, aid)

    def toggle_samefig():
        # FIXME: Do not do recursive calls
        ishow_matches(ibs, qres, aid=aid, fnum=fnum, figtitle=figtitle, same_fig=not same_fig, **kwargs)

    def query_last_feature():
        viz.show_nearest_descriptors(ibs, qaid, last_state.last_fx, df2.next_fnum())
        fig3 = df2.gcf()
        ih.connect_callback(fig3, 'button_press_event', _click_matches_click)
        df2.update()

    toggle_samefig_key = 'Toggle same_fig (currently %r)' % same_fig

    opt2_callback = [
        (toggle_samefig_key, toggle_samefig),
        ('query last feature', query_last_feature),
        ('cancel', lambda: print('cancel')), ]
    guitool.connect_context_menu(fig.canvas, opt2_callback)
    ih.connect_callback(fig, 'button_press_event', _click_matches_click)
    viz.draw()
    return fig
def ishow_keypoints(chip,
                    kpts,
                    desc,
                    fnum=0,
                    figtitle=None,
                    nodraw=False,
                    **kwargs):
    """
    TODO: Depricate in favor of the class

    CommandLine:
        python -m plottool.interact_keypoints --test-ishow_keypoints --show
        python -m plottool.interact_keypoints --test-ishow_keypoints --show --fname zebra.png

    Example:
        >>> # DISABLE_DOCTEST
        >>> from plottool.interact_keypoints import *  # NOQA
        >>> import numpy as np
        >>> import plottool as pt
        >>> import utool as ut
        >>> import pyhesaff
        >>> import vtool as vt
        >>> kpts, vecs, imgBGR = pt.viz_keypoints.testdata_kpts()
        >>> ut.quit_if_noshow()
        >>> #pt.interact_keypoints.ishow_keypoints(imgBGR, kpts, vecs, ori=True, ell_alpha=.4, color='distinct')
        >>> pt.interact_keypoints.ishow_keypoints(imgBGR, kpts, vecs, ori=True, ell_alpha=.4)
        >>> pt.show_if_requested()
    """
    if isinstance(chip, six.string_types):
        import vtool as vt
        chip = vt.imread(chip)
    fig = ih.begin_interaction('keypoint', fnum)
    annote_ptr = [1]

    self = ut.DynStruct()  # MOVE TO A CLASS INTERACTION
    self.kpts = kpts
    vecs = desc
    self.vecs = vecs

    def _select_ith_kpt(fx):
        print('[interact] viewing ith=%r keypoint' % fx)
        # Get the fx-th keypiont
        kp, sift = kpts[fx], vecs[fx]
        # Draw the image with keypoint fx highlighted
        _viz_keypoints(fnum, (2, 1, 1), sel_fx=fx,
                       **kwargs)  # MAYBE: remove kwargs
        # Draw the selected feature
        nRows, nCols, px = (2, 3, 3)
        draw_feat_row(chip, fx, kp, sift, fnum, nRows, nCols, px, None)

    def _viz_keypoints(fnum, pnum=(1, 1, 1), **kwargs):
        df2.figure(fnum=fnum, docla=True, doclf=True)
        show_keypoints(chip, kpts, fnum=fnum, pnum=pnum, **kwargs)
        if figtitle is not None:
            df2.set_figtitle(figtitle)

    def _on_keypoints_click(event):
        print('[viz] clicked keypoint view')
        if event is None or event.xdata is None or event.inaxes is None:
            annote_ptr[0] = (annote_ptr[0] + 1) % 3
            mode = annote_ptr[0]
            ell = mode == 1
            pts = mode == 2
            print('... default kpts view mode=%r' % mode)
            _viz_keypoints(fnum, ell=ell, pts=pts,
                           **kwargs)  # MAYBE: remove kwargs
        else:
            ax = event.inaxes
            viztype = ph.get_plotdat(ax, 'viztype', None)
            print('[ik] viztype=%r' % viztype)
            if viztype == 'keypoints':
                kpts = ph.get_plotdat(ax, 'kpts', [])
                if len(kpts) == 0:
                    print('...nokpts')
                else:
                    print('...nearest')
                    x, y = event.xdata, event.ydata
                    fx = ut.nearest_point(x, y, kpts)[0]
                    _select_ith_kpt(fx)
            elif viztype == 'warped':
                hs_fx = ph.get_plotdat(ax, 'fx', None)
                #kpts = ph.get_plotdat(ax, 'kpts', [])
                if hs_fx is not None:
                    # Ugly. Interactions should be changed to classes.
                    kp = self.kpts[hs_fx]  # FIXME
                    sift = self.vecs[hs_fx]
                    df2.draw_keypoint_gradient_orientations(
                        chip, kp, sift=sift, mode='vec', fnum=df2.next_fnum())
            elif viztype.startswith('colorbar'):
                pass
                # Hack to get a specific scoring feature
                #sortx = self.fs.argsort()
                #idx = np.clip(int(np.round(y * len(sortx))), 0, len(sortx) - 1)
                #mx = sortx[idx]
                #(fx1, fx2) = self.fm[mx]
                #(fx1, fx2) = self.fm[mx]
                #print('... selected score at rank idx=%r' % (idx,))
                #print('... selected score with fs=%r' % (self.fs[mx],))
                #print('... resolved to mx=%r' % mx)
                #print('... fx1, fx2 = %r, %r' % (fx1, fx2,))
                #self.select_ith_match(mx)
            else:
                print('...unhandled')
        ph.draw()

    # Draw without keypoints the first time
    _viz_keypoints(fnum, **kwargs)  # MAYBE: remove kwargs
    ih.connect_callback(fig, 'button_press_event', _on_keypoints_click)
    if not nodraw:
        ph.draw()
Beispiel #12
0
def ishow_name(ibs,
               nid,
               sel_aids=[],
               select_aid_callback=None,
               fnum=5,
               dodraw=True,
               **kwargs):
    r"""
    Args:
        ibs (IBEISController):  ibeis controller object
        nid (?):
        sel_aids (list):
        select_aid_callback (None):
        fnum (int):  figure number

    CommandLine:
        python -m ibeis.viz.interact.interact_name --test-ishow_name --show

    Example:
        >>> # DISABLE_DOCTEST
        >>> from ibeis.viz.interact.interact_name import *  # NOQA
        >>> import ibeis
        >>> # build test data
        >>> ibs = ibeis.opendb('testdb1')
        >>> nid = ut.get_argval('--nid', int, default=1)
        >>> sel_aids = []
        >>> select_aid_callback = None
        >>> fnum = 5
        >>> dodraw = ut.show_was_requested()
        >>> # execute function
        >>> result = ishow_name(ibs, nid, sel_aids, select_aid_callback, fnum, dodraw)
        >>> # verify results
        >>> pt.show_if_requested()
        >>> print(result)
    """
    if fnum is None:
        fnum = pt.next_fnum()
    fig = ih.begin_interaction('name', fnum)

    def _on_name_click(event):
        ax = event.inaxes
        if ih.clicked_inside_axis(event):
            viztype = vh.get_ibsdat(ax, 'viztype')
            if viztype == 'chip':
                aid = vh.get_ibsdat(ax, 'aid')
                print('... aid=%r' % aid)
                if event.button == 3:  # right-click
                    import guitool
                    from ibeis.viz.interact import interact_chip
                    height = fig.canvas.geometry().height()
                    qpoint = guitool.newQPoint(event.x, height - event.y)
                    refresh_func = functools.partial(viz.show_name,
                                                     ibs,
                                                     nid,
                                                     fnum=fnum,
                                                     sel_aids=sel_aids)
                    interact_chip.show_annot_context_menu(
                        ibs,
                        aid,
                        fig.canvas,
                        qpoint,
                        refresh_func=refresh_func,
                        with_interact_name=False)
                else:
                    viz.show_name(ibs,
                                  nid,
                                  fnum=fnum,
                                  sel_aids=[aid],
                                  in_image=True)
                    if select_aid_callback is not None:
                        select_aid_callback(aid)
        viz.draw()

    viz.show_name(ibs, nid, fnum=fnum, sel_aids=sel_aids, in_image=True)
    if dodraw:
        viz.draw()
    ih.connect_callback(fig, 'button_press_event', _on_name_click)
    pass
Beispiel #13
0
    def start_new_viz(simp, nRows, nCols, fnum=None):
        import plottool as pt
        rchip1, rchip2, kpts1, vecs1, kpts2, vecs2, dlen_sqrd2 = simp.testtup
        fm_ORIG, fs_ORIG, fm_RAT, fs_RAT, fm_SV, fs_SV, H_RAT = simp.basetup
        fm_SC, fs_SC, fm_SCR, fs_SCR, fm_SCRSV, fs_SCRSV, H_SCR = simp.nexttup
        fm_norm_RAT, fm_norm_SV = simp.base_meta
        fm_norm_SC, fm_norm_SCR, fm_norm_SVSCR = simp.next_meta

        locals_ = ut.delete_dict_keys(locals(), ['title'])

        keytitle_tups = [
            ('ORIG', 'initial neighbors'),
            ('RAT', 'ratio filtered'),
            ('SV', 'ratio filtered + SV'),
            ('SC', 'spatially constrained'),
            ('SCR', 'spatially constrained + ratio'),
            ('SCRSV', 'spatially constrained + SV'),
        ]
        keytitle_dict = dict(keytitle_tups)
        key_list = ut.get_list_column(keytitle_tups, 0)
        matchtup_dict = {
            key: (locals_['fm_' + key], locals_['fs_' + key])
            for key in key_list
        }
        normtup_dict = {
            key: locals_.get('fm_norm_' + key, None)
            for key in key_list
        }

        next_pnum = pt.make_pnum_nextgen(nRows=nRows, nCols=nCols)
        if fnum is None:
            fnum = pt.next_fnum()
        INTERACTIVE = True
        if INTERACTIVE:
            from plottool import interact_helpers as ih
            fig = ih.begin_interaction('qres', fnum)
            ih.connect_callback(fig, 'button_press_event',
                                on_single_match_clicked)
        else:
            pt.figure(fnum=fnum, doclf=True, docla=True)

        def show_matches_(key, **kwargs):
            assert key in key_list, 'unknown key=%r' % (key, )
            showkw = locals_.copy()
            pnum = next_pnum()
            showkw['pnum'] = pnum
            showkw['fnum'] = fnum
            showkw.update(kwargs)
            _fm, _fs = matchtup_dict[key]
            title = keytitle_dict[key]
            if kwargs.get('coverage'):
                from vtool import coverage_kpts
                kpts2, rchip2 = ut.dict_get(locals_, ('kpts2', 'rchip2'))
                kpts2_m = kpts2.take(_fm.T[1], axis=0)
                chipshape2 = rchip2.shape
                chipsize2 = chipshape2[0:2][::-1]
                coverage_mask = coverage_kpts.make_kpts_coverage_mask(
                    kpts2_m,
                    chipsize2,
                    fx2_score=_fs,
                    resize=True,
                    return_patch=False)
                pt.imshow(coverage_mask * 255, pnum=pnum, fnum=fnum)
            else:
                if kwargs.get('norm', False):
                    _fm = normtup_dict[key]
                    assert _fm is not None, key
                    showkw['cmap'] = 'cool'
                    title += ' normalizers'
                show_matches(_fm, _fs, title=title, key=key, **showkw)

        # state hack
        #show_matches_.next_pnum = next_pnum
        return show_matches_
Beispiel #14
0
def ishow_chip(ibs, aid, fnum=2, fx=None, dodraw=True, config2_=None,
               ischild=False, **kwargs):
    r"""

    # TODO:
        split into two interactions
        interact chip and interact chip features

    Args:
        ibs (IBEISController):  ibeis controller object
        aid (int):  annotation id
        fnum (int):  figure number
        fx (None):

    CommandLine:
        python -m ibeis.viz.interact.interact_chip --test-ishow_chip --show
        python -m ibeis.viz.interact.interact_chip --test-ishow_chip --show --aid 2

    Example:
        >>> # DISABLE_DOCTEST
        >>> from ibeis.viz.interact.interact_chip import *  # NOQA
        >>> import ibeis
        >>> # build test data
        >>> ibs = ibeis.opendb('testdb1')
        >>> aid = ut.get_argval('--aid', type_=int, default=1)
        >>> fnum = 2
        >>> fx = None
        >>> # execute function
        >>> dodraw = ut.show_was_requested()
        >>> result = ishow_chip(ibs, aid, fnum, fx, dodraw)
        >>> # verify results
        >>> pt.show_if_requested()
        >>> print(result)
    """
    fnum = pt.ensure_fnum(fnum)
    vh.ibsfuncs.assert_valid_aids(ibs, (aid,))
    # TODO: Reconcile this with interact keypoints.
    # Preferably this will call that but it will set some fancy callbacks
    if not ischild:
        fig = ih.begin_interaction('chip', fnum)
    else:
        fig = pt.gcf()
        #fig = pt.figure(fnum=fnum, pnum=pnum)

    # Get chip info (make sure get_chips is called first)
    #mode_ptr = [1]
    mode_ptr = [0]

    def _select_fxth_kpt(fx):
        # Get the fx-th keypiont
        chip = ibs.get_annot_chips(aid, config2_=config2_)
        kp = ibs.get_annot_kpts(aid, config2_=config2_)[fx]
        sift = ibs.get_annot_vecs(aid, config2_=config2_)[fx]
        # Draw chip + keypoints + highlighted plots
        _chip_view(pnum=(2, 1, 1), sel_fx=fx)
        #ishow_chip(ibs, aid, fnum=None, fx=fx, config2_=config2_, **kwargs)
        # Draw the selected feature plots
        nRows, nCols, px = (2, 3, 3)
        draw_feat_row(chip, fx, kp, sift, fnum, nRows, nCols, px, None)

    def _chip_view(mode=0, pnum=(1, 1, 1), **kwargs):
        print('... _chip_view mode=%r' % mode_ptr[0])
        kwargs['ell'] = mode_ptr[0] == 1
        kwargs['pts'] = mode_ptr[0]  == 2

        if not ischild:
            df2.figure(fnum=fnum, pnum=pnum, docla=True, doclf=True)
        # Toggle no keypoints view
        viz.show_chip(ibs, aid, fnum=fnum, pnum=pnum, config2_=config2_,
                      **kwargs)
        df2.set_figtitle('Chip View')

    def _on_chip_click(event):
        print('[inter] clicked chip')
        ax, x, y = event.inaxes, event.xdata, event.ydata
        if ih.clicked_outside_axis(event):
            if not ischild:
                print('... out of axis')
                mode_ptr[0] = (mode_ptr[0] + 1) % 3
                _chip_view(**kwargs)
        else:
            if event.button == 3:   # right-click
                import guitool
                #from ibeis.viz.interact import interact_chip
                height = fig.canvas.geometry().height()
                qpoint = guitool.newQPoint(event.x, height - event.y)
                refresh_func = partial(_chip_view, **kwargs)

                callback_list = build_annot_context_options(
                    ibs, aid, refresh_func=refresh_func,
                    with_interact_chip=False,
                    config2_=config2_)
                qwin = fig.canvas
                guitool.popup_menu(qwin, qpoint, callback_list)
                #interact_chip.show_annot_context_menu(
                #    ibs, aid, fig.canvas, qpoint, refresh_func=refresh_func,
                #    with_interact_chip=False, config2_=config2_)
            else:
                viztype = vh.get_ibsdat(ax, 'viztype')
                print('[ic] viztype=%r' % viztype)
                if viztype == 'chip' and event.key == 'shift':
                    _chip_view(**kwargs)
                    ih.disconnect_callback(fig, 'button_press_event')
                elif viztype == 'chip':
                    kpts = ibs.get_annot_kpts(aid, config2_=config2_)
                    if len(kpts) > 0:
                        fx = vt.nearest_point(
                            x, y, kpts, conflict_mode='next')[0]
                        print('... clicked fx=%r' % fx)
                        _select_fxth_kpt(fx)
                    else:
                        print('... len(kpts) == 0')
                elif viztype in ['warped', 'unwarped']:
                    fx = vh.get_ibsdat(ax, 'fx')
                    if fx is not None and viztype == 'warped':
                        viz.show_keypoint_gradient_orientations(
                            ibs, aid, fx, fnum=df2.next_fnum())
                else:
                    print('...Unknown viztype: %r' % viztype)

        viz.draw()

    # Draw without keypoints the first time
    if fx is not None:
        _select_fxth_kpt(fx)
    else:
        _chip_view(**kwargs)
    if dodraw:
        viz.draw()

    if not ischild:
        ih.connect_callback(fig, 'button_press_event', _on_chip_click)
Beispiel #15
0
def ishow_chip(ibs, aid, fnum=2, fx=None, dodraw=True, config2_=None,
               ischild=False, **kwargs):
    r"""

    # TODO:
        split into two interactions
        interact chip and interact chip features

    Args:
        ibs (IBEISController):  ibeis controller object
        aid (int):  annotation id
        fnum (int):  figure number
        fx (None):

    CommandLine:
        python -m ibeis.viz.interact.interact_chip --test-ishow_chip --show
        python -m ibeis.viz.interact.interact_chip --test-ishow_chip --show --aid 2

    Example:
        >>> # DISABLE_DOCTEST
        >>> from ibeis.viz.interact.interact_chip import *  # NOQA
        >>> import ibeis
        >>> # build test data
        >>> ibs = ibeis.opendb('testdb1')
        >>> aid = ut.get_argval('--aid', type_=int, default=1)
        >>> fnum = 2
        >>> fx = None
        >>> # execute function
        >>> dodraw = ut.show_was_requested()
        >>> result = ishow_chip(ibs, aid, fnum, fx, dodraw)
        >>> # verify results
        >>> pt.show_if_requested()
        >>> print(result)
    """
    fnum = pt.ensure_fnum(fnum)
    vh.ibsfuncs.assert_valid_aids(ibs, (aid,))
    # TODO: Reconcile this with interact keypoints.
    # Preferably this will call that but it will set some fancy callbacks
    if not ischild:
        fig = ih.begin_interaction('chip', fnum)
    else:
        fig = pt.gcf()
        #fig = pt.figure(fnum=fnum, pnum=pnum)

    # Get chip info (make sure get_chips is called first)
    #mode_ptr = [1]
    mode_ptr = [0]

    def _select_fxth_kpt(fx):
        # Get the fx-th keypiont
        chip = ibs.get_annot_chips(aid, config2_=config2_)
        kp = ibs.get_annot_kpts(aid, config2_=config2_)[fx]
        sift = ibs.get_annot_vecs(aid, config2_=config2_)[fx]
        # Draw chip + keypoints + highlighted plots
        _chip_view(pnum=(2, 1, 1), sel_fx=fx)
        #ishow_chip(ibs, aid, fnum=None, fx=fx, config2_=config2_, **kwargs)
        # Draw the selected feature plots
        nRows, nCols, px = (2, 3, 3)
        draw_feat_row(chip, fx, kp, sift, fnum, nRows, nCols, px, None)

    def _chip_view(mode=0, pnum=(1, 1, 1), **kwargs):
        print('... _chip_view mode=%r' % mode_ptr[0])
        kwargs['ell'] = mode_ptr[0] == 1
        kwargs['pts'] = mode_ptr[0]  == 2

        if not ischild:
            df2.figure(fnum=fnum, pnum=pnum, docla=True, doclf=True)
        # Toggle no keypoints view
        viz.show_chip(ibs, aid, fnum=fnum, pnum=pnum, config2_=config2_,
                      **kwargs)
        df2.set_figtitle('Chip View')

    def _on_chip_click(event):
        print('[inter] clicked chip')
        ax, x, y = event.inaxes, event.xdata, event.ydata
        if ih.clicked_outside_axis(event):
            if not ischild:
                print('... out of axis')
                mode_ptr[0] = (mode_ptr[0] + 1) % 3
                _chip_view(**kwargs)
        else:
            if event.button == 3:   # right-click
                import guitool
                #from ibeis.viz.interact import interact_chip
                height = fig.canvas.geometry().height()
                qpoint = guitool.newQPoint(event.x, height - event.y)
                refresh_func = partial(_chip_view, **kwargs)

                callback_list = build_annot_context_options(
                    ibs, aid, refresh_func=refresh_func,
                    with_interact_chip=False,
                    config2_=config2_)
                qwin = fig.canvas
                guitool.popup_menu(qwin, qpoint, callback_list)
                #interact_chip.show_annot_context_menu(
                #    ibs, aid, fig.canvas, qpoint, refresh_func=refresh_func,
                #    with_interact_chip=False, config2_=config2_)
            else:
                viztype = vh.get_ibsdat(ax, 'viztype')
                print('[ic] viztype=%r' % viztype)
                if viztype == 'chip' and event.key == 'shift':
                    _chip_view(**kwargs)
                    ih.disconnect_callback(fig, 'button_press_event')
                elif viztype == 'chip':
                    kpts = ibs.get_annot_kpts(aid, config2_=config2_)
                    if len(kpts) > 0:
                        fx = vt.nearest_point(
                            x, y, kpts, conflict_mode='next')[0]
                        print('... clicked fx=%r' % fx)
                        _select_fxth_kpt(fx)
                    else:
                        print('... len(kpts) == 0')
                elif viztype in ['warped', 'unwarped']:
                    fx = vh.get_ibsdat(ax, 'fx')
                    if fx is not None and viztype == 'warped':
                        viz.show_keypoint_gradient_orientations(
                            ibs, aid, fx, fnum=df2.next_fnum())
                else:
                    print('...Unknown viztype: %r' % viztype)

        viz.draw()

    # Draw without keypoints the first time
    if fx is not None:
        _select_fxth_kpt(fx)
    else:
        _chip_view(**kwargs)
    if dodraw:
        viz.draw()

    if not ischild:
        ih.connect_callback(fig, 'button_press_event', _on_chip_click)
Beispiel #16
0
    def __init__(self, ibs, cm, aid2=None, fnum=None,
                 figtitle='Match Interaction', same_fig=True,
                 qreq_=None, **kwargs):
        self.qres = cm

        self.ibs = ibs
        self.cm = cm
        self.qreq_ = qreq_
        self.fnum = pt.ensure_fnum(fnum)
        # Unpack Args
        if aid2 is None:
            index = 0
            # FIXME: no sortself
            cm.sortself()
            self.rank = index
        else:
            index = cm.daid2_idx.get(aid2, None)
            # TODO: rank?
            self.rank = None
        if index is not None:
            self.qaid  = self.cm.qaid
            self.daid  = self.cm.daid_list[index]
            self.fm    = self.cm.fm_list[index]
            self.fk    = self.cm.fk_list[index]
            self.fsv   = self.cm.fsv_list[index]
            if self.cm.fs_list is None:
                fs_list = self.cm.get_fsv_prod_list()
            else:
                fs_list = self.cm.fs_list
            self.fs    = None if fs_list is None else fs_list[index]
            self.score = None if self.cm.score_list is None else self.cm.score_list[index]
            self.H1    = None if self.cm.H_list is None else cm.H_list[index]
        else:
            self.qaid  = self.cm.qaid
            self.daid  = aid2
            self.fm    = np.empty((0, 2), dtype=hstypes.FM_DTYPE)
            self.fk    = np.empty(0, dtype=hstypes.FK_DTYPE)
            self.fsv   = np.empty((0, 2), dtype=hstypes.FS_DTYPE)
            self.fs    = np.empty(0, dtype=hstypes.FS_DTYPE)
            self.score = None
            self.H1    = None

        # Read properties
        self.query_config2_ = (None if self.qreq_ is None else
                               self.qreq_.get_external_query_config2())
        self.data_config2_ = (None if self.qreq_ is None else
                              self.qreq_.get_external_data_config2())
        self.rchip1 = vh.get_chips(ibs, [self.qaid], config2_=self.query_config2_)[0]
        self.rchip2 = vh.get_chips(ibs, [self.daid], config2_=self.data_config2_)[0]
        # Begin Interaction
        # call doclf docla and make figure
        self.fig = ih.begin_interaction('matches', self.fnum)
        self.xywh2_ptr  = [None]
        self.mode = kwargs.pop('mode', 0)
        # New state vars
        self.same_fig = same_fig
        self.use_homog = False
        self.vert = kwargs.pop('vert', None)
        self.mx   = kwargs.pop('mx', None)
        self.last_fx = 0
        self.fnum2 = pt.next_fnum()
        self.figtitle = figtitle
        self.kwargs = kwargs

        abstract_interaction.register_interaction(self)
        ut.inject_func_as_method(self, AbstractInteraction.append_button.im_func)
        ut.inject_func_as_method(self, AbstractInteraction.show_popup_menu.im_func)
        self.scope = []

        if not kwargs.get('nobegin', False):
            dodraw = kwargs.get('dodraw', True)
            self.begin(dodraw=dodraw)
Beispiel #17
0
    def __init__(self,
                 ibs,
                 cm,
                 aid2=None,
                 fnum=None,
                 figtitle='Match Interaction',
                 same_fig=True,
                 qreq_=None,
                 **kwargs):
        self.qres = cm

        self.ibs = ibs
        self.cm = cm
        self.qreq_ = qreq_
        self.fnum = pt.ensure_fnum(fnum)
        # Unpack Args
        if aid2 is None:
            index = 0
            # FIXME: no sortself
            cm.sortself()
            self.rank = index
        else:
            index = cm.daid2_idx.get(aid2, None)
            # TODO: rank?
            self.rank = None
        if index is not None:
            self.qaid = self.cm.qaid
            self.daid = self.cm.daid_list[index]
            self.fm = self.cm.fm_list[index]
            self.fk = self.cm.fk_list[index]
            self.fsv = self.cm.fsv_list[index]
            if self.cm.fs_list is None:
                fs_list = self.cm.get_fsv_prod_list()
            else:
                fs_list = self.cm.fs_list
            self.fs = None if fs_list is None else fs_list[index]
            self.score = None if self.cm.score_list is None else self.cm.score_list[
                index]
            self.H1 = None if self.cm.H_list is None else cm.H_list[index]
        else:
            self.qaid = self.cm.qaid
            self.daid = aid2
            self.fm = np.empty((0, 2), dtype=hstypes.FM_DTYPE)
            self.fk = np.empty(0, dtype=hstypes.FK_DTYPE)
            self.fsv = np.empty((0, 2), dtype=hstypes.FS_DTYPE)
            self.fs = np.empty(0, dtype=hstypes.FS_DTYPE)
            self.score = None
            self.H1 = None

        # Read properties
        self.query_config2_ = (None if self.qreq_ is None else
                               self.qreq_.get_external_query_config2())
        self.data_config2_ = (None if self.qreq_ is None else
                              self.qreq_.get_external_data_config2())
        self.rchip1 = vh.get_chips(ibs, [self.qaid],
                                   config2_=self.query_config2_)[0]
        self.rchip2 = vh.get_chips(ibs, [self.daid],
                                   config2_=self.data_config2_)[0]
        # Begin Interaction
        # call doclf docla and make figure
        self.fig = ih.begin_interaction('matches', self.fnum)
        self.xywh2_ptr = [None]
        self.mode = kwargs.pop('mode', 0)
        # New state vars
        self.same_fig = same_fig
        self.use_homog = False
        self.vert = kwargs.pop('vert', None)
        self.mx = kwargs.pop('mx', None)
        self.last_fx = 0
        self.fnum2 = pt.next_fnum()
        self.figtitle = figtitle
        self.kwargs = kwargs

        abstract_interaction.register_interaction(self)
        ut.inject_func_as_method(self,
                                 AbstractInteraction.append_button.im_func)
        ut.inject_func_as_method(self,
                                 AbstractInteraction.show_popup_menu.im_func)
        self.scope = []

        if not kwargs.get('nobegin', False):
            dodraw = kwargs.get('dodraw', True)
            self.begin(dodraw=dodraw)
Beispiel #18
0
def ishow_image(ibs,
                gid,
                sel_aids=[],
                fnum=None,
                select_callback=None,
                **kwargs):
    if ut.VERBOSE:
        print(ut.get_caller_name(range(9)))
        print('[interact_image] gid=%r fnum=%r' % (
            gid,
            fnum,
        ))
    if fnum is None:
        fnum = df2.next_fnum()
    # TODO: change to class based structure
    self = ut.DynStruct()
    self.fnum = fnum

    fig = ih.begin_interaction('image', fnum)
    #printDBG(utool.func_str(interact_image, [], locals()))
    kwargs['draw_lbls'] = kwargs.get('draw_lbls', True)

    def _image_view(sel_aids=sel_aids, **_kwargs):
        try:
            viz.show_image(ibs,
                           gid,
                           sel_aids=sel_aids,
                           fnum=self.fnum,
                           **_kwargs)
            df2.set_figtitle('Image View')
        except TypeError as ex:
            ut.printex(ex, ut.dict_str(_kwargs))
            raise

    # Create callback wrapper
    def _on_image_click(event):
        printDBG('[inter] clicked image')
        if ih.clicked_outside_axis(event):
            # Toggle draw lbls
            kwargs['draw_lbls'] = not kwargs.get('draw_lbls', True)
            _image_view(**kwargs)
        else:
            ax = event.inaxes
            viztype = vh.get_ibsdat(ax, 'viztype')
            annotation_centers = vh.get_ibsdat(ax,
                                               'annotation_centers',
                                               default=[])
            printDBG(' annotation_centers=%r' % annotation_centers)
            printDBG(' viztype=%r' % viztype)
            if len(annotation_centers) == 0:
                print(' ...no chips exist to click')
                return
            x, y = event.xdata, event.ydata
            # Find ANNOTATION center nearest to the clicked point
            aid_list = vh.get_ibsdat(ax, 'aid_list', default=[])
            centx, _dist = ut.nearest_point(x, y, annotation_centers)
            aid = aid_list[centx]
            print(' ...clicked aid=%r' % aid)
            if select_callback is not None:
                # HACK, should just implement this correctly here
                select_callback(gid, sel_aids=[aid], fnum=self.fnum)
            else:
                _image_view(sel_aids=[aid])

        viz.draw()

    _image_view(**kwargs)
    viz.draw()
    ih.connect_callback(fig, 'button_press_event', _on_image_click)
Beispiel #19
0
def ishow_keypoints(chip, kpts, desc, fnum=0, figtitle=None, nodraw=False, **kwargs):
    """
    TODO: Depricate in favor of the class

    CommandLine:
        python -m plottool.interact_keypoints --test-ishow_keypoints --show
        python -m plottool.interact_keypoints --test-ishow_keypoints --show --fname zebra.png

    Example:
        >>> # DISABLE_DOCTEST
        >>> from plottool.interact_keypoints import *  # NOQA
        >>> import numpy as np
        >>> import plottool as pt
        >>> import utool as ut
        >>> import pyhesaff
        >>> import vtool as vt
        >>> kpts, vecs, imgBGR = pt.viz_keypoints.testdata_kpts()
        >>> ut.quit_if_noshow()
        >>> #pt.interact_keypoints.ishow_keypoints(imgBGR, kpts, vecs, ori=True, ell_alpha=.4, color='distinct')
        >>> pt.interact_keypoints.ishow_keypoints(imgBGR, kpts, vecs, ori=True, ell_alpha=.4)
        >>> pt.show_if_requested()
    """
    if isinstance(chip, six.string_types):
        import vtool as vt
        chip = vt.imread(chip)
    fig = ih.begin_interaction('keypoint', fnum)
    annote_ptr = [1]

    self = ut.DynStruct()  # MOVE TO A CLASS INTERACTION
    self.kpts = kpts
    vecs = desc
    self.vecs = vecs

    def _select_ith_kpt(fx):
        print('[interact] viewing ith=%r keypoint' % fx)
        # Get the fx-th keypiont
        kp, sift = kpts[fx], vecs[fx]
        # Draw the image with keypoint fx highlighted
        _viz_keypoints(fnum, (2, 1, 1), sel_fx=fx, **kwargs)  # MAYBE: remove kwargs
        # Draw the selected feature
        nRows, nCols, px = (2, 3, 3)
        draw_feat_row(chip, fx, kp, sift, fnum, nRows, nCols, px, None)

    def _viz_keypoints(fnum, pnum=(1, 1, 1), **kwargs):
        df2.figure(fnum=fnum, docla=True, doclf=True)
        show_keypoints(chip, kpts, fnum=fnum, pnum=pnum, **kwargs)
        if figtitle is not None:
            df2.set_figtitle(figtitle)

    def _on_keypoints_click(event):
        print('[viz] clicked keypoint view')
        if event is None  or event.xdata is None or event.inaxes is None:
            annote_ptr[0] = (annote_ptr[0] + 1) % 3
            mode = annote_ptr[0]
            ell = mode == 1
            pts = mode == 2
            print('... default kpts view mode=%r' % mode)
            _viz_keypoints(fnum, ell=ell, pts=pts, **kwargs)    # MAYBE: remove kwargs
        else:
            ax = event.inaxes
            viztype = ph.get_plotdat(ax, 'viztype', None)
            print('[ik] viztype=%r' % viztype)
            if viztype == 'keypoints':
                kpts = ph.get_plotdat(ax, 'kpts', [])
                if len(kpts) == 0:
                    print('...nokpts')
                else:
                    print('...nearest')
                    x, y = event.xdata, event.ydata
                    fx = ut.nearest_point(x, y, kpts)[0]
                    _select_ith_kpt(fx)
            elif viztype == 'warped':
                hs_fx = ph.get_plotdat(ax, 'fx', None)
                #kpts = ph.get_plotdat(ax, 'kpts', [])
                if hs_fx is not None:
                    # Ugly. Interactions should be changed to classes.
                    kp = self.kpts[hs_fx]  # FIXME
                    sift = self.vecs[hs_fx]
                    df2.draw_keypoint_gradient_orientations(chip, kp, sift=sift, mode='vec',
                                                            fnum=df2.next_fnum())
            elif viztype.startswith('colorbar'):
                pass
                # Hack to get a specific scoring feature
                #sortx = self.fs.argsort()
                #idx = np.clip(int(np.round(y * len(sortx))), 0, len(sortx) - 1)
                #mx = sortx[idx]
                #(fx1, fx2) = self.fm[mx]
                #(fx1, fx2) = self.fm[mx]
                #print('... selected score at rank idx=%r' % (idx,))
                #print('... selected score with fs=%r' % (self.fs[mx],))
                #print('... resolved to mx=%r' % mx)
                #print('... fx1, fx2 = %r, %r' % (fx1, fx2,))
                #self.select_ith_match(mx)
            else:
                print('...unhandled')
        ph.draw()

    # Draw without keypoints the first time
    _viz_keypoints(fnum, **kwargs)   # MAYBE: remove kwargs
    ih.connect_callback(fig, 'button_press_event', _on_keypoints_click)
    if not nodraw:
        ph.draw()
Beispiel #20
0
def ishow_name(ibs, nid, sel_aids=[], select_aid_callback=None, fnum=5, dodraw=True, **kwargs):
    r"""
    Args:
        ibs (IBEISController):  ibeis controller object
        nid (?):
        sel_aids (list):
        select_aid_callback (None):
        fnum (int):  figure number

    CommandLine:
        python -m ibeis.viz.interact.interact_name --test-ishow_name --show

    Example:
        >>> # DISABLE_DOCTEST
        >>> from ibeis.viz.interact.interact_name import *  # NOQA
        >>> import ibeis
        >>> # build test data
        >>> ibs = ibeis.opendb('testdb1')
        >>> nid = ut.get_argval('--nid', int, default=1)
        >>> sel_aids = []
        >>> select_aid_callback = None
        >>> fnum = 5
        >>> dodraw = ut.show_was_requested()
        >>> # execute function
        >>> result = ishow_name(ibs, nid, sel_aids, select_aid_callback, fnum, dodraw)
        >>> # verify results
        >>> pt.show_if_requested()
        >>> print(result)
    """
    if fnum is None:
        fnum = pt.next_fnum()
    fig = ih.begin_interaction('name', fnum)

    def _on_name_click(event):
        print_('[inter] clicked name')
        ax = event.inaxes
        if ih.clicked_inside_axis(event):
            viztype = vh.get_ibsdat(ax, 'viztype')
            print_(' viztype=%r' % viztype)
            if viztype == 'chip':
                aid = vh.get_ibsdat(ax, 'aid')
                print('... aid=%r' % aid)
                if event.button == 3:   # right-click
                    import guitool
                    from ibeis.viz.interact import interact_chip
                    height = fig.canvas.geometry().height()
                    qpoint = guitool.newQPoint(event.x, height - event.y)
                    refresh_func = functools.partial(viz.show_name, ibs, nid, fnum=fnum, sel_aids=sel_aids)
                    interact_chip.show_annot_context_menu(
                        ibs, aid, fig.canvas, qpoint, refresh_func=refresh_func,
                        with_interact_name=False)
                else:
                    viz.show_name(ibs, nid, fnum=fnum, sel_aids=[aid], in_image=True)
                    if select_aid_callback is not None:
                        select_aid_callback(aid)
        viz.draw()

    viz.show_name(ibs, nid, fnum=fnum, sel_aids=sel_aids, in_image=True)
    if dodraw:
        viz.draw()
    ih.connect_callback(fig, 'button_press_event', _on_name_click)
    pass
    def start_new_viz(simp, nRows, nCols, fnum=None):
        import plottool as pt
        rchip1, rchip2, kpts1, vecs1, kpts2, vecs2, dlen_sqrd2  = simp.testtup
        fm_ORIG, fs_ORIG, fm_RAT, fs_RAT, fm_SV, fs_SV, H_RAT   = simp.basetup
        fm_SC, fs_SC, fm_SCR, fs_SCR, fm_SCRSV, fs_SCRSV, H_SCR = simp.nexttup
        fm_norm_RAT, fm_norm_SV                                 = simp.base_meta
        fm_norm_SC, fm_norm_SCR, fm_norm_SVSCR                  = simp.next_meta

        locals_ = ut.delete_dict_keys(locals(), ['title'])

        keytitle_tups = [
            ('ORIG', 'initial neighbors'),
            ('RAT', 'ratio filtered'),
            ('SV', 'ratio filtered + SV'),
            ('SC', 'spatially constrained'),
            ('SCR', 'spatially constrained + ratio'),
            ('SCRSV', 'spatially constrained + SV'),
        ]
        keytitle_dict = dict(keytitle_tups)
        key_list = ut.get_list_column(keytitle_tups, 0)
        matchtup_dict = {
            key: (locals_['fm_' + key], locals_['fs_' + key])
            for key in key_list
        }
        normtup_dict = {
            key: locals_.get('fm_norm_' + key, None)
            for key in key_list
        }

        next_pnum = pt.make_pnum_nextgen(nRows=nRows, nCols=nCols)
        if fnum is None:
            fnum = pt.next_fnum()
        INTERACTIVE = True
        if INTERACTIVE:
            from plottool import interact_helpers as ih
            fig = ih.begin_interaction('qres', fnum)
            ih.connect_callback(fig, 'button_press_event', on_single_match_clicked)
        else:
            pt.figure(fnum=fnum, doclf=True, docla=True)

        def show_matches_(key, **kwargs):
            assert key in key_list, 'unknown key=%r' % (key,)
            showkw = locals_.copy()
            pnum = next_pnum()
            showkw['pnum'] = pnum
            showkw['fnum'] = fnum
            showkw.update(kwargs)
            _fm, _fs = matchtup_dict[key]
            title = keytitle_dict[key]
            if kwargs.get('coverage'):
                from vtool import coverage_kpts
                kpts2, rchip2 = ut.dict_get(locals_, ('kpts2', 'rchip2'))
                kpts2_m = kpts2.take(_fm.T[1], axis=0)
                chipshape2 = rchip2.shape
                chipsize2 = chipshape2[0:2][::-1]
                coverage_mask = coverage_kpts.make_kpts_coverage_mask(kpts2_m, chipsize2, fx2_score=_fs, resize=True, return_patch=False)
                pt.imshow(coverage_mask * 255, pnum=pnum, fnum=fnum)
            else:
                if kwargs.get('norm', False):
                    _fm = normtup_dict[key]
                    assert _fm is not None, key
                    showkw['cmap'] = 'cool'
                    title += ' normalizers'
                show_matches(_fm, _fs, title=title, key=key, **showkw)
        # state hack
        #show_matches_.next_pnum = next_pnum
        return show_matches_