def on_single_match_clicked(event):
    from plottool import interact_helpers as ih
    from plottool import plot_helpers as ph
    """ result interaction mpl event callback slot """
    print('[viz] clicked result')
    if ih.clicked_outside_axis(event):
        pass
    else:
        ax = event.inaxes
        viztype = ph.get_plotdat(ax, 'viztype', '')
        #printDBG(str(event.__dict__))
        # Clicked a specific matches
        if viztype.startswith('matches'):
            #aid2 = ph.get_plotdat(ax, 'aid2', None)
            # Ctrl-Click
            evkey = '' if event.key is None else event.key
            simp = ph.get_plotdat(ax, 'simp', None)
            key = ph.get_plotdat(ax, 'key', None)
            print('evkey = %r' % evkey)
            if evkey.find('control') == 0:
                print('[viz] result control clicked')
                pass
            # Left-Click
            else:
                print(simp)
                print(key)
                print('[viz] result clicked')
                pass
    ph.draw()
示例#2
0
def on_single_match_clicked(event):
    from plottool import interact_helpers as ih
    from plottool import plot_helpers as ph
    """ result interaction mpl event callback slot """
    print('[viz] clicked result')
    if ih.clicked_outside_axis(event):
        pass
    else:
        ax = event.inaxes
        viztype = ph.get_plotdat(ax, 'viztype', '')
        #printDBG(str(event.__dict__))
        # Clicked a specific matches
        if viztype.startswith('matches'):
            #aid2 = ph.get_plotdat(ax, 'aid2', None)
            # Ctrl-Click
            evkey = '' if event.key is None else event.key
            simp = ph.get_plotdat(ax, 'simp', None)
            key = ph.get_plotdat(ax, 'key', None)
            print('evkey = %r' % evkey)
            if evkey.find('control') == 0:
                print('[viz] result control clicked')
                pass
            # Left-Click
            else:
                print(simp)
                print(key)
                print('[viz] result clicked')
                pass
    ph.draw()
示例#3
0
def show_keypoints(chip, kpts, fnum=0, pnum=None, **kwargs):
    r"""
    Args:
        chip (ndarray[uint8_t, ndim=2]):  annotation image data
        kpts (ndarray[float32_t, ndim=2]):  keypoints
        fnum (int):  figure number(default = 0)
        pnum (tuple):  plot number(default = None)

    Kwargs:
        ddd, title, figtitle, interpolation, cmap, heatmap, data_colorbar,
        darken, update, redraw_image, docla, doclf, projection, sel_fx

    CommandLine:
        python -m plottool.viz_keypoints --exec-show_keypoints

    Example:
        >>> # DISABLE_DOCTEST
        >>> from plottool.viz_keypoints import *  # NOQA
        >>> import vtool as vt
        >>> kpts, vecs, chip = testdata_kpts()
        >>> fnum = 0
        >>> pnum = None
        >>> result = show_keypoints(chip, kpts, fnum, pnum)
        >>> print(result)
    """
    #printDBG('[df2.show_kpts] %r' % (kwargs.keys(),))
    fig, ax = df2.imshow(chip, fnum=fnum, pnum=pnum, **kwargs)
    _annotate_kpts(kpts, **kwargs)
    ph.set_plotdat(ax, 'viztype', 'keypoints')
    ph.set_plotdat(ax, 'kpts', kpts)
    if kwargs.get('ddd', False):
        ph.draw()
 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()
示例#5
0
 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()
示例#6
0
    def begin(self, dodraw=True):
        r"""
        CommandLine:
            python -m ibeis.viz.interact.interact_matches --test-begin
            python -m ibeis.viz.interact.interact_matches --test-begin --show

        Example:
            >>> # DISABLE_DOCTEST
            >>> from ibeis.viz.interact.interact_matches import *  # NOQA
            >>> self = testdata_match_interact()
            >>> self.begin(dodraw=False)
            >>> pt.show_if_requested()
        """
        if self.mx is None:
            self.chipmatch_view()
        else:
            self.select_ith_match(self.mx)

        self.set_callbacks()
        # FIXME: this should probably not be called here
        if dodraw:
            ph.draw()  # ph-> adjust stuff draw -> fig_presenter.draw -> all figures show
示例#7
0
    def begin(self, dodraw=True):
        r"""
        CommandLine:
            python -m ibeis.viz.interact.interact_matches --test-begin
            python -m ibeis.viz.interact.interact_matches --test-begin --show

        Example:
            >>> # DISABLE_DOCTEST
            >>> from ibeis.viz.interact.interact_matches import *  # NOQA
            >>> self = testdata_match_interact()
            >>> self.begin(dodraw=False)
            >>> pt.show_if_requested()
        """
        if self.mx is None:
            self.chipmatch_view()
        else:
            self.select_ith_match(self.mx)

        self.set_callbacks()
        # FIXME: this should probably not be called here
        if dodraw:
            ph.draw(
            )  # ph-> adjust stuff draw -> fig_presenter.draw -> all figures show
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()
示例#9
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()