コード例 #1
0
def ishow_name(ibs,
               nid,
               sel_aids=[],
               select_aid_callback=None,
               fnum=5,
               dodraw=True,
               **kwargs):
    r"""
    Args:
        ibs (IBEISController):  wbia controller object
        nid (?):
        sel_aids (list):
        select_aid_callback (None):
        fnum (int):  figure number

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

    Example:
        >>> # DISABLE_DOCTEST
        >>> from wbia.viz.interact.interact_name import *  # NOQA
        >>> import wbia
        >>> # build test data
        >>> ibs = wbia.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')
                logger.info('... aid=%r' % aid)
                if event.button == 3:  # right-click
                    from wbia import guitool
                    from wbia.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
コード例 #2
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):  wbia controller object
        aid (int):  annotation id
        fnum (int):  figure number
        fx (None):

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

    Example:
        >>> # DISABLE_DOCTEST
        >>> from wbia.viz.interact.interact_chip import *  # NOQA
        >>> import wbia
        >>> # build test data
        >>> ibs = wbia.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):
        from wbia.plottool.viz_featrow import draw_feat_row

        # 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):
        logger.info('... _chip_view mode=%r' % mode_ptr[0])
        kwargs['ell'] = mode_ptr[0] == 1
        kwargs['pts'] = mode_ptr[0] == 2

        if not ischild:
            pt.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)
        pt.set_figtitle('Chip View')

    def _on_chip_click(event):
        logger.info('[inter] clicked chip')
        ax, x, y = event.inaxes, event.xdata, event.ydata
        if ih.clicked_outside_axis(event):
            if not ischild:
                logger.info('... out of axis')
                mode_ptr[0] = (mode_ptr[0] + 1) % 3
                _chip_view(**kwargs)
        else:
            if event.button == 3:  # right-click
                import wbia.guitool as gt

                # from wbia.viz.interact import interact_chip
                height = fig.canvas.geometry().height()
                qpoint = gt.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
                gt.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')
                logger.info('[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]
                        logger.info('... clicked fx=%r' % fx)
                        _select_fxth_kpt(fx)
                    else:
                        logger.info('... 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=pt.next_fnum())
                else:
                    logger.info('...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)
コード例 #3
0
def ishow_keypoints(chip,
                    kpts,
                    desc,
                    fnum=0,
                    figtitle=None,
                    nodraw=False,
                    **kwargs):
    """
    TODO: Depricate in favor of the class

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

    Example:
        >>> # DISABLE_DOCTEST
        >>> from wbia.plottool.interact_keypoints import *  # NOQA
        >>> import numpy as np
        >>> import wbia.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):
        logger.info('[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):
        logger.info('[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
            logger.info('... 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)
            logger.info('[ik] viztype=%r' % viztype)
            if viztype == 'keypoints':
                kpts = ph.get_plotdat(ax, 'kpts', [])
                if len(kpts) == 0:
                    logger.info('...nokpts')
                else:
                    logger.info('...nearest')
                    x, y = event.xdata, event.ydata
                    import vtool as vt

                    fx = vt.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]
                # logger.info('... selected score at rank idx=%r' % (idx,))
                # logger.info('... selected score with fs=%r' % (self.fs[mx],))
                # logger.info('... resolved to mx=%r' % mx)
                # logger.info('... fx1, fx2 = %r, %r' % (fx1, fx2,))
                # self.select_ith_match(mx)
            else:
                logger.info('...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()
コード例 #4
0
 def connect_callbacks(self):
     if self.debug:
         print('[pt.a] connect_callbacks')
     ih.connect_callback(self.fig, 'button_press_event', self.on_click)
     ih.connect_callback(self.fig, 'button_release_event',
                         self.on_click_release)
     ih.connect_callback(self.fig, 'key_press_event', self.on_key_press)
     ih.connect_callback(self.fig, 'motion_notify_event', self.on_motion)
     ih.connect_callback(self.fig, 'draw_event', self.on_draw)
     ih.connect_callback(self.fig, 'scroll_event', self.on_scroll)
コード例 #5
0
 def _start_interaction(self):
     # self.fig = df2.figure(fnum=self.fnum, doclf=True, docla=True)
     self.fig = df2.figure(fnum=self.fnum, doclf=True)
     ih.connect_callback(self.fig, 'close_event', self.on_close)
     register_interaction(self)
     self.is_running = True
コード例 #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.repr2(_kwargs))
            raise

    # Create callback wrapper
    def _on_image_click(event):
        print('[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=[])
            print(' annotation_centers=%r' % annotation_centers)
            print(' 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=[])
            import vtool as vt

            centx, _dist = vt.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)
コード例 #7
0
    def select_ith_match(self, mx):
        """
        Selects the ith match and visualizes and prints information concerning
        features weights, keypoint details, and sift descriptions
        """
        import wbia.plottool as pt
        from wbia.plottool import viz_featrow
        from wbia.plottool import interact_helpers as ih

        fnum = self.fnum
        same_fig = self.same_fig
        rchip1 = self.rchip1
        rchip2 = self.rchip2
        self.mx = mx
        print('+--- SELECT --- ')
        print('... selecting mx-th=%r feature match' % mx)
        fsv = self.fsv
        fs = self.fs
        print('score stats:')
        print(ut.repr2(ut.get_stats(fsv, axis=0), nl=1))
        print('fsv[mx] = %r' % (fsv[mx], ))
        print('fs[mx] = %r' % (fs[mx], ))
        # ----------------------
        # Get info for the select_ith_match plot
        self.mode = 1
        # Get the mx-th feature match
        fx1, fx2 = self.fm[mx]

        # Older info
        fscore2 = self.fs[mx]
        fk2 = None if self.fk is None else self.fk[mx]
        kp1, kp2 = self.kpts1[fx1], self.kpts2[fx2]
        vecs1, vecs2 = self.vecs1[fx1], self.vecs2[fx2]
        info1 = '\nquery'
        info2 = '\nk=%r fscore=%r' % (fk2, fscore2)
        # self.last_fx = fx1
        self.last_fx = fx1

        # Extracted keypoints to draw
        extracted_list = [
            (rchip1, kp1, vecs1, fx1, 'aid1', info1),
            (rchip2, kp2, vecs2, fx2, 'aid2', info2),
        ]
        # Normalizng Keypoint
        # if hasattr(cm, 'filt2_meta') and 'lnbnn' in cm.filt2_meta:
        #    qfx2_norm = cm.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_vecs(aid3)[fx3]
        #    info3 = '\nnorm %s k=%r' % (vh.get_aidstrs(aid3), normk)
        #    extracted_list.append((rchip3, kp3, sift3, fx3, aid3, info3))
        # else:
        #    pass
        #    #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)
        vert = self.vert if self.vert is not None else False
        self.chipmatch_view(
            pnum=pnum1,
            ell_alpha=0.4,
            ell_linewidth=1.8,
            colors=pt.BLUE,
            sel_fm=sel_fm,
            vert=vert,
        )
        # Draw selected feature matches
        px = nCols * same_fig  # plot offset
        prevsift = None
        if not same_fig:
            # fnum2 = fnum + len(viz.FNUMS)
            fnum2 = self.fnum2
            fig2 = pt.figure(fnum=fnum2, docla=True, doclf=True)
        else:
            fnum2 = fnum

        for (rchip, kp, sift, fx, aid, info) in extracted_list:
            px = viz_featrow.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', self.on_click)