Пример #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)
Пример #2
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
Пример #3
0
    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()
Пример #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
Пример #5
0
    def show_each_dstncvs_chip(self, dodraw=True):
        """
        CommandLine:
            python -m ibeis.viz.interact.interact_matches --test-show_each_dstncvs_chip --show

        Example:
            >>> # DISABLE_DOCTEST
            >>> from ibeis.viz.interact.interact_matches import *  # NOQA
            >>> self = testdata_match_interact(mx=1)
            >>> self.show_each_dstncvs_chip(dodraw=False)
            >>> pt.show_if_requested()
        """
        dstncvs1, dstncvs2 = scoring.get_kpts_distinctiveness(self.ibs,
                                                              [self.qaid,
                                                               self.daid])
        print('dstncvs1_stats = ' + ut.get_stats_str(dstncvs1))
        print('dstncvs2_stats = ' + ut.get_stats_str(dstncvs2))
        weight_label = 'dstncvs'
        showkw = dict(weight_label=weight_label, ell=False, pts=True)
        viz_chip.show_chip(self.ibs, self.qaid, weights=dstncvs1,
                           fnum=pt.next_fnum(), **showkw)
        viz_chip.show_chip(self.ibs, self.daid, weights=dstncvs2,
                           fnum=pt.next_fnum(), **showkw)
        if dodraw:
            viz.draw()
Пример #6
0
    def show_each_dstncvs_chip(self, dodraw=True):
        """
        CommandLine:
            python -m ibeis.viz.interact.interact_matches --test-show_each_dstncvs_chip --show

        Example:
            >>> # DISABLE_DOCTEST
            >>> from ibeis.viz.interact.interact_matches import *  # NOQA
            >>> self = testdata_match_interact(mx=1)
            >>> self.show_each_dstncvs_chip(dodraw=False)
            >>> pt.show_if_requested()
        """
        dstncvs1, dstncvs2 = scoring.get_kpts_distinctiveness(
            self.ibs, [self.qaid, self.daid])
        print('dstncvs1_stats = ' + ut.get_stats_str(dstncvs1))
        print('dstncvs2_stats = ' + ut.get_stats_str(dstncvs2))
        weight_label = 'dstncvs'
        showkw = dict(weight_label=weight_label, ell=False, pts=True)
        viz_chip.show_chip(self.ibs,
                           self.qaid,
                           weights=dstncvs1,
                           fnum=pt.next_fnum(),
                           **showkw)
        viz_chip.show_chip(self.ibs,
                           self.daid,
                           weights=dstncvs2,
                           fnum=pt.next_fnum(),
                           **showkw)
        if dodraw:
            viz.draw()
Пример #7
0
 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()
Пример #8
0
    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=[])
            import vtool_ibeis 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()
Пример #9
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)
Пример #10
0
 def query_last_feature(self):
     ibs      = self.ibs
     qaid     = self.qaid
     viz.show_nearest_descriptors(ibs, qaid, self.last_fx, df2.next_fnum(),
                                  qreq_=self.qreq_, draw_chip=True)
     fig3 = df2.gcf()
     ih.connect_callback(fig3, 'button_press_event', self.on_click)
     viz.draw()
Пример #11
0
 def show_each_probchip(self):
     viz_hough.show_probability_chip(self.ibs,
                                     self.qaid,
                                     fnum=pt.next_fnum())
     viz_hough.show_probability_chip(self.ibs,
                                     self.daid,
                                     fnum=pt.next_fnum())
     viz.draw()
Пример #12
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)
Пример #13
0
 def show_each_chip(self):
     viz_chip.show_chip(self.ibs,
                        self.qaid,
                        fnum=pt.next_fnum(),
                        nokpts=True)
     viz_chip.show_chip(self.ibs,
                        self.daid,
                        fnum=pt.next_fnum(),
                        nokpts=True)
     viz.draw()
Пример #14
0
 def show_each_fgweight_chip(self):
     viz_chip.show_chip(self.ibs,
                        self.qaid,
                        fnum=pt.next_fnum(),
                        weight_label='fg_weights')
     viz_chip.show_chip(self.ibs,
                        self.daid,
                        fnum=pt.next_fnum(),
                        weight_label='fg_weights')
     viz.draw()
Пример #15
0
    def sv_view(self, dodraw=True):
        """ spatial verification view

        """
        #fnum = viz.FNUMS['special']
        aid = self.daid
        fnum = pt.next_fnum()
        fig = df2.figure(fnum=fnum, docla=True, doclf=True)
        ih.disconnect_callback(fig, 'button_press_event')
        viz.viz_sver.show_sver(self.ibs, self.qaid, aid2=aid, fnum=fnum)
        if dodraw:
            viz.draw()
Пример #16
0
    def sv_view(self, dodraw=True):
        """ spatial verification view

        """
        #fnum = viz.FNUMS['special']
        aid = self.daid
        fnum = pt.next_fnum()
        fig = df2.figure(fnum=fnum, docla=True, doclf=True)
        ih.disconnect_callback(fig, 'button_press_event')
        viz.viz_sver.show_sver(self.ibs, self.qaid, aid2=aid, fnum=fnum)
        if dodraw:
            viz.draw()
Пример #17
0
 def query_last_feature(self):
     ibs = self.ibs
     qaid = self.qaid
     viz.show_nearest_descriptors(ibs,
                                  qaid,
                                  self.last_fx,
                                  df2.next_fnum(),
                                  qreq_=self.qreq_,
                                  draw_chip=True)
     fig3 = df2.gcf()
     ih.connect_callback(fig3, 'button_press_event', self.on_click)
     viz.draw()
Пример #18
0
    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_ibeis as gt
                #from ibeis.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')
                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 = 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=pt.next_fnum())
                else:
                    print('...Unknown viztype: %r' % viztype)

        viz.draw()
Пример #19
0
 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()
Пример #20
0
    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()
Пример #21
0
 def _on_sv_click(event):
     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')
         if viztype in ['homogblend', 'affblend', 'source', 'dest']:
             pass
         else:
             print('...Unknown viztype: %r' % viztype)
     viz.draw()
Пример #22
0
    def show_coverage(self, dodraw=True):
        """
        CommandLine:
            python -m ibeis.viz.interact.interact_matches --test-show_coverage --show
            python -m ibeis.viz.interact.interact_matches --test-show_coverage

        Example:
            >>> # DISABLE_DOCTEST
            >>> from ibeis.viz.interact.interact_matches import *  # NOQA
            >>> self = testdata_match_interact(mx=1)
            >>> self.show_coverage(dodraw=False)
            >>> pt.show_if_requested()
        """
        masks_list = scoring.get_masks(self.qreq_, self.cm)
        scoring.show_coverage_mask(self.qreq_, self.cm, masks_list)
        if dodraw:
            viz.draw()
Пример #23
0
    def show_coverage(self, dodraw=True):
        """
        CommandLine:
            python -m ibeis.viz.interact.interact_matches --test-show_coverage --show
            python -m ibeis.viz.interact.interact_matches --test-show_coverage

        Example:
            >>> # DISABLE_DOCTEST
            >>> from ibeis.viz.interact.interact_matches import *  # NOQA
            >>> self = testdata_match_interact(mx=1)
            >>> self.show_coverage(dodraw=False)
            >>> pt.show_if_requested()
        """
        masks_list = scoring.get_masks(self.qreq_, self.cm)
        scoring.show_coverage_mask(self.qreq_, self.cm, masks_list)
        if dodraw:
            viz.draw()
Пример #24
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)
Пример #25
0
 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()
Пример #26
0
 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()
Пример #27
0
def show_nearest_descriptors(qres, ibs, qfx, dodraw=True):
    from ibeis import viz
    qcid = qres.qcid
    viz.show_nearest_descriptors(ibs, qcid, qfx, fnum=None)
    if dodraw:
        viz.draw()
Пример #28
0
 def toggle_homog(self):
     self.use_homog = not self.use_homog
     self.chipmatch_view()
     viz.draw()
Пример #29
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):
        from plottool_ibeis.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):
        print('... _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):
        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_ibeis as gt
                #from ibeis.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')
                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 = 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=pt.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)
Пример #30
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)
Пример #31
0
 def show_each_probchip(self):
     viz_hough.show_probability_chip(self.ibs, self.qaid, fnum=pt.next_fnum())
     viz_hough.show_probability_chip(self.ibs, self.daid, fnum=pt.next_fnum())
     viz.draw()
Пример #32
0
    def on_click(self, event):
        aid       = self.daid
        qaid      = self.qaid
        ibs       = self.ibs
        xywh2_ptr = self.xywh2_ptr
        print('[inter] clicked matches')
        if event is None:
            return
        button = event.button
        is_right_click = button == 3

        # Out of axes click
        (x, y, ax) = (event.xdata, event.ydata, event.inaxes)
        if None in [x, y, ax]:
            in_axis = False
            if not is_right_click:
                print('... out of axis')
                self.chipmatch_view()
                viz.draw()
                return
        else:
            in_axis = True

        if in_axis:
            viztype = vh.get_ibsdat(ax, 'viztype', '')
            is_match_type = viztype in ['matches', 'multi_match']
            print('[ir] viztype=%r ' % viztype)
        else:
            is_match_type = False
            viztype = ''

        if is_right_click:
            from ibeis.gui import inspect_gui
            options = []

            if is_match_type:
                options += inspect_gui.get_aidpair_context_menu_options(
                    self.ibs, self.qaid, self.daid, self.cm,
                    qreq_=self.qreq_,
                    #update_callback=self.show_page,
                    #backend_callback=None, aid_list=aid_list)
                )

            options += [
                ('Toggle same_fig', self.toggle_samefig),
                ('Toggle vert', self.toggle_vert),
                ('query last feature', self.query_last_feature),
                ('show each chip', self.show_each_chip),
                ('show each distinctiveness chip', self.show_each_dstncvs_chip),
                ('show each foreground weight chip', self.show_each_fgweight_chip),
                ('show each probchip', self.show_each_probchip),
                ('show coverage', self.show_coverage),
                #('show each probchip', self.query_last_feature),
            ]

            #options.append(('name_interaction', self.name_interaction))
            if self.H1 is not None:
                options.append(('Toggle homog', self.toggle_homog))
            if ut.is_developer():
                options.append(('dev_reload', self.dev_reload))
                options.append(('dev_embed', self.dev_embed))
            #options.append(('cancel', lambda: print('cancel')))
            self.show_popup_menu(options, event)
            return

        if in_axis:
            key = '' if event.key is None else event.key
            print('key=%r ' % key)
            ctrl_down = key.find('control') == 0
            # Click in match axes
            if is_match_type and ctrl_down:
                # Ctrl-Click
                print('.. control click')
                return self.sv_view()
            elif is_match_type:
                if len(self.fm) == 0:
                    print('[inter] no feature matches to click')
                else:
                    # Normal Click
                    # Select nearest feature match to the click
                    kpts1 = ibs.get_annot_kpts([qaid], config2_=self.query_config2_)[0]
                    kpts2 = ibs.get_annot_kpts([aid], config2_=self.data_config2_)[0]
                    kpts1_m = kpts1[self.fm.T[0]]
                    kpts2_m = kpts2[self.fm.T[1]]
                    x2, y2, w2, h2 = xywh2_ptr[0]
                    _mx1, _dist1 = ut.nearest_point(x, y, kpts1_m)
                    _mx2, _dist2 = ut.nearest_point(x - x2, y - y2, kpts2_m)
                    mx = _mx1 if _dist1 < _dist2 else _mx2
                    (fx1, fx2) = self.fm[mx]
                    print('... clicked mx=%r' % mx)
                    print('... fx1, fx2 = %r, %r' % (fx1, fx2,))
                    self.select_ith_match(mx)
            elif viztype in ['warped', 'unwarped']:
                print('clicked at patch')
                ut.print_dict(ph.get_plotdat_dict(ax))
                hs_aid = vh.get_ibsdat(ax, 'aid', None)
                hs_fx = vh.get_ibsdat(ax, 'fx', None)
                #hs_aid = ax.__dict__.get('_hs_aid', None)
                #hs_fx = ax.__dict__.get('_hs_fx', None)
                print('hs_fx = %r' % (hs_fx,))
                print('hs_aid = %r' % (hs_aid,))
                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())
            elif viztype.startswith('colorbar'):
                # 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('...Unknown viztype: %r' % viztype)
            viz.draw()
Пример #33
0
 def show_hough(back, gid, **kwargs):
     viz.show_hough(back.ibs, gid, back.ibs.cfg.detect_cfg.species, **kwargs)
     viz.draw()
Пример #34
0
 def show_each_fgweight_chip(self):
     viz_chip.show_chip(self.ibs, self.qaid, fnum=pt.next_fnum(),
                        weight_label='fg_weights')
     viz_chip.show_chip(self.ibs, self.daid, fnum=pt.next_fnum(),
                        weight_label='fg_weights')
     viz.draw()
Пример #35
0
def show_nearest_descriptors(qres, ibs, qfx, dodraw=True):
    from ibeis import viz
    qcid = qres.qcid
    viz.show_nearest_descriptors(ibs, qcid, qfx, fnum=None)
    if dodraw:
        viz.draw()
Пример #36
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
Пример #37
0
 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()
Пример #38
0
 def show_each_chip(self):
     viz_chip.show_chip(self.ibs, self.qaid, fnum=pt.next_fnum(), nokpts=True)
     viz_chip.show_chip(self.ibs, self.daid, fnum=pt.next_fnum(), nokpts=True)
     viz.draw()
Пример #39
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
Пример #40
0
    def on_click(self, event):
        aid = self.daid
        qaid = self.qaid
        ibs = self.ibs
        xywh2_ptr = self.xywh2_ptr
        print('[inter] clicked matches')
        if event is None:
            return
        button = event.button
        is_right_click = button == 3

        # Out of axes click
        (x, y, ax) = (event.xdata, event.ydata, event.inaxes)
        if None in [x, y, ax]:
            in_axis = False
            if not is_right_click:
                print('... out of axis')
                self.chipmatch_view()
                viz.draw()
                return
        else:
            in_axis = True

        if in_axis:
            viztype = vh.get_ibsdat(ax, 'viztype', '')
            is_match_type = viztype in ['matches', 'multi_match']
            print('[ir] viztype=%r ' % viztype)
        else:
            is_match_type = False
            viztype = ''

        if is_right_click:
            from ibeis.gui import inspect_gui
            options = []

            if is_match_type:
                options += inspect_gui.get_aidpair_context_menu_options(
                    self.ibs,
                    self.qaid,
                    self.daid,
                    self.cm,
                    qreq_=self.qreq_,
                    #update_callback=self.show_page,
                    #backend_callback=None, aid_list=aid_list)
                )

            options += [
                ('Toggle same_fig', self.toggle_samefig),
                ('Toggle vert', self.toggle_vert),
                ('query last feature', self.query_last_feature),
                ('show each chip', self.show_each_chip),
                ('show each distinctiveness chip',
                 self.show_each_dstncvs_chip),
                ('show each foreground weight chip',
                 self.show_each_fgweight_chip),
                ('show each probchip', self.show_each_probchip),
                ('show coverage', self.show_coverage),
                #('show each probchip', self.query_last_feature),
            ]

            #options.append(('name_interaction', self.name_interaction))
            if self.H1 is not None:
                options.append(('Toggle homog', self.toggle_homog))
            if ut.is_developer():
                options.append(('dev_reload', self.dev_reload))
                options.append(('dev_embed', self.dev_embed))
            #options.append(('cancel', lambda: print('cancel')))
            self.show_popup_menu(options, event)
            return

        if in_axis:
            key = '' if event.key is None else event.key
            print('key=%r ' % key)
            ctrl_down = key.find('control') == 0
            # Click in match axes
            if is_match_type and ctrl_down:
                # Ctrl-Click
                print('.. control click')
                return self.sv_view()
            elif is_match_type:
                if len(self.fm) == 0:
                    print('[inter] no feature matches to click')
                else:
                    # Normal Click
                    # Select nearest feature match to the click
                    kpts1 = ibs.get_annot_kpts([qaid],
                                               config2_=self.query_config2_)[0]
                    kpts2 = ibs.get_annot_kpts([aid],
                                               config2_=self.data_config2_)[0]
                    kpts1_m = kpts1[self.fm.T[0]]
                    kpts2_m = kpts2[self.fm.T[1]]
                    x2, y2, w2, h2 = xywh2_ptr[0]
                    _mx1, _dist1 = ut.nearest_point(x, y, kpts1_m)
                    _mx2, _dist2 = ut.nearest_point(x - x2, y - y2, kpts2_m)
                    mx = _mx1 if _dist1 < _dist2 else _mx2
                    (fx1, fx2) = self.fm[mx]
                    print('... clicked mx=%r' % mx)
                    print('... fx1, fx2 = %r, %r' % (
                        fx1,
                        fx2,
                    ))
                    self.select_ith_match(mx)
            elif viztype in ['warped', 'unwarped']:
                print('clicked at patch')
                ut.print_dict(ph.get_plotdat_dict(ax))
                hs_aid = vh.get_ibsdat(ax, 'aid', None)
                hs_fx = vh.get_ibsdat(ax, 'fx', None)
                #hs_aid = ax.__dict__.get('_hs_aid', None)
                #hs_fx = ax.__dict__.get('_hs_fx', None)
                print('hs_fx = %r' % (hs_fx, ))
                print('hs_aid = %r' % (hs_aid, ))
                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())
            elif viztype.startswith('colorbar'):
                # 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('...Unknown viztype: %r' % viztype)
            viz.draw()
Пример #41
0
 def toggle_homog(self):
     self.use_homog = not self.use_homog
     self.chipmatch_view()
     viz.draw()
Пример #42
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
Пример #43
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):
        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=[])
            import vtool_ibeis 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)