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)
def query_last_feature(self): ibs = self.ibs qaid = self.qaid viz.show_nearest_descriptors(ibs, qaid, self.last_fx, pt.next_fnum(), qreq_=self.qreq_, draw_chip=True) fig3 = pt.gcf() ih.connect_callback(fig3, 'button_press_event', self.on_click) pt.draw()
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()
def prepare_page(self): figkw = { 'fnum': self.fnum, 'doclf': True, 'docla': True, } self.fig = pt.figure(**figkw) ih.disconnect_callback(self.fig, 'button_press_event') ih.connect_callback(self.fig, 'button_press_event', self.figure_clicked)
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))
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)
def prepare_page(self, fulldraw=True): figkw = {'fnum': self.fnum, 'doclf': fulldraw, 'docla': fulldraw, } if fulldraw: self.fig = pt.figure(**figkw) ih.disconnect_callback(self.fig, 'button_press_event') ih.disconnect_callback(self.fig, 'key_press_event') ih.connect_callback(self.fig, 'button_press_event', self.figure_clicked) ih.connect_callback(self.fig, 'key_press_event', self.on_key_press)
def prepare_page(self, fulldraw=True): figkw = { 'fnum': self.fnum, 'doclf': fulldraw, 'docla': fulldraw, } if fulldraw: self.fig = pt.figure(**figkw) ih.disconnect_callback(self.fig, 'button_press_event') ih.disconnect_callback(self.fig, 'key_press_event') ih.connect_callback(self.fig, 'button_press_event', self.figure_clicked) ih.connect_callback(self.fig, 'key_press_event', self.on_key_press)
def prepare_page(self, pagenum): """ Gets indexes for the pagenum ready to be displayed """ # Set the start index self.start_index = pagenum * self.nPerPage # Clip based on nCands self.nDisplay = min(self.nCands - self.start_index, self.nPerPage) nRows, nCols = ph.get_square_row_cols(self.nDisplay) # Create a grid to hold nPerPage self.pnum_ = df2.get_pnum_func(nRows, nCols) # Adjust stop index self.stop_index = self.start_index + self.nDisplay # Clear current figure self.clean_scope() self.fig = df2.figure(fnum=self.fnum, pnum=self.pnum_(0), doclf=True, docla=True) ih.disconnect_callback(self.fig, 'button_press_event') ih.connect_callback(self.fig, 'button_press_event', self.on_figure_clicked)
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)
def prepare_page(self, fulldraw=True): import plottool as pt ih.disconnect_callback(self.fig, 'button_press_event') ih.disconnect_callback(self.fig, 'button_release_event') ih.disconnect_callback(self.fig, 'key_press_event') ih.disconnect_callback(self.fig, 'motion_notify_event') figkw = {'fnum': self.fnum, 'doclf': fulldraw, 'docla': fulldraw, } if fulldraw: self.fig = pt.figure(**figkw) self.make_hud() 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)
def prepare_page(self, fulldraw=True): import plottool as pt ih.disconnect_callback(self.fig, 'button_press_event') ih.disconnect_callback(self.fig, 'button_release_event') ih.disconnect_callback(self.fig, 'key_press_event') ih.disconnect_callback(self.fig, 'motion_notify_event') figkw = { 'fnum': self.fnum, 'doclf': fulldraw, 'docla': fulldraw, } if fulldraw: self.fig = pt.figure(**figkw) self.make_hud() 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)
def ishow_matches(ibs, qres, aid=None, fnum=4, figtitle='Inspect Query Result', same_fig=True, **kwargs): """ Plots a chip result and sets up callbacks for interaction. """ fig = ih.begin_interaction('matches', fnum) qaid = qres.qaid if aid is None: aid = qres.get_top_aids(num=1)[0] rchip1, rchip2 = ibs.get_annot_chips([qaid, aid]) fm = qres.aid2_fm[aid] mx = kwargs.pop('mx', None) xywh2_ptr = [None] annote_ptr = [kwargs.pop('mode', 0)] last_state = LastState() last_state.same_fig = same_fig last_state.last_fx = 0 # Draw default def _chipmatch_view(pnum=(1, 1, 1), **kwargs): mode = annote_ptr[0] # drawing mode draw: with/without lines/feats draw_ell = mode >= 1 draw_lines = mode == 2 annote_ptr[0] = (annote_ptr[0] + 1) % 3 df2.figure(fnum=fnum, docla=True, doclf=True) # TODO RENAME This to remove qres and rectify with show_matches tup = viz.show_matches(ibs, qres, aid, fnum=fnum, pnum=pnum, draw_lines=draw_lines, draw_ell=draw_ell, colorbar_=True, **kwargs) ax, xywh1, xywh2 = tup xywh2_ptr[0] = xywh2 df2.set_figtitle(figtitle + ' ' + vh.get_vsstr(qaid, aid)) # Draw clicked selection def _select_ith_match(mx, qaid, aid): #---------------------- # Get info for the _select_ith_match plot annote_ptr[0] = 1 # Get the mx-th feature match aid1, aid2 = qaid, aid fx1, fx2 = fm[mx] fscore2 = qres.aid2_fs[aid2][mx] fk2 = qres.aid2_fk[aid2][mx] kpts1, kpts2 = ibs.get_annot_kpts([aid1, aid2]) desc1, desc2 = ibs.get_annot_desc([aid1, aid2]) kp1, kp2 = kpts1[fx1], kpts2[fx2] sift1, sift2 = desc1[fx1], desc2[fx2] info1 = '\nquery' info2 = '\nk=%r fscore=%r' % (fk2, fscore2) last_state.last_fx = fx1 # Extracted keypoints to draw extracted_list = [(rchip1, kp1, sift1, fx1, aid1, info1), (rchip2, kp2, sift2, fx2, aid2, info2)] # Normalizng Keypoint if hasattr(qres, 'filt2_meta') and 'lnbnn' in qres.filt2_meta: qfx2_norm = qres.filt2_meta['lnbnn'] # Normalizing chip and feature (aid3, fx3, normk) = qfx2_norm[fx1] rchip3 = ibs.get_annot_chips(aid3) kp3 = ibs.get_annot_kpts(aid3)[fx3] sift3 = ibs.get_annot_desc(aid3)[fx3] info3 = '\nnorm %s k=%r' % (vh.get_aidstrs(aid3), normk) extracted_list.append((rchip3, kp3, sift3, fx3, aid3, info3)) else: print('WARNING: meta doesnt exist') #---------------------- # Draw the _select_ith_match plot nRows, nCols = len(extracted_list) + same_fig, 3 # Draw matching chips and features sel_fm = np.array([(fx1, fx2)]) pnum1 = (nRows, 1, 1) if same_fig else (1, 1, 1) _chipmatch_view(pnum1, vert=False, ell_alpha=.4, ell_linewidth=1.8, colors=df2.BLUE, sel_fm=sel_fm, **kwargs) # Draw selected feature matches px = nCols * same_fig # plot offset prevsift = None if not same_fig: fnum2 = fnum + len(viz.FNUMS) fig2 = df2.figure(fnum=fnum2, docla=True, doclf=True) else: fnum2 = fnum for (rchip, kp, sift, fx, aid, info) in extracted_list: px = draw_feat_row(rchip, fx, kp, sift, fnum2, nRows, nCols, px, prevsift=prevsift, aid=aid, info=info) prevsift = sift if not same_fig: ih.connect_callback(fig2, 'button_press_event', _click_matches_click) df2.set_figtitle(figtitle + vh.get_vsstr(qaid, aid)) # Draw ctrl clicked selection def _sv_view(aid): fnum = viz.FNUMS['special'] fig = df2.figure(fnum=fnum, docla=True, doclf=True) ih.disconnect_callback(fig, 'button_press_event') viz.show_sv(ibs, qres.qaid, aid2=aid, fnum=fnum) viz.draw() # Callback def _click_matches_click(event): print_('[inter] clicked matches') if event is None: return button = event.button is_right_click = button == 3 if is_right_click: return (x, y, ax) = (event.xdata, event.ydata, event.inaxes) # Out of axes click if None in [x, y, ax]: print('... out of axis') _chipmatch_view() viz.draw() return viztype = vh.get_ibsdat(ax, 'viztype', '') print_('[ir] viztype=%r ' % viztype) key = '' if event.key is None else event.key print_('key=%r ' % key) ctrl_down = key.find('control') == 0 # Click in match axes if viztype == 'matches' and ctrl_down: # Ctrl-Click print('.. control click') return _sv_view(aid) elif viztype == 'matches': if len(fm) == 0: print('[inter] no feature matches to click') else: # Normal Click # Select nearest feature match to the click kpts1, kpts2 = ibs.get_annot_kpts([qaid, aid]) kpts1_m = kpts1[fm[:, 0]] kpts2_m = kpts2[fm[:, 1]] x2, y2, w2, h2 = xywh2_ptr[0] _mx1, _dist1 = utool.nearest_point(x, y, kpts1_m) _mx2, _dist2 = utool.nearest_point(x - x2, y - y2, kpts2_m) mx = _mx1 if _dist1 < _dist2 else _mx2 print('... clicked mx=%r' % mx) _select_ith_match(mx, qaid, aid) elif viztype in ['warped', 'unwarped']: hs_aid = ax.__dict__.get('_hs_aid', None) hs_fx = ax.__dict__.get('_hs_fx', None) if hs_aid is not None and viztype == 'unwarped': ishow_chip(ibs, hs_aid, fx=hs_fx, fnum=df2.next_fnum()) elif hs_aid is not None and viztype == 'warped': viz.show_keypoint_gradient_orientations(ibs, hs_aid, hs_fx, fnum=df2.next_fnum()) else: print('...Unknown viztype: %r' % viztype) viz.draw() if mx is None: _chipmatch_view() else: _select_ith_match(mx, qaid, aid) def toggle_samefig(): # FIXME: Do not do recursive calls ishow_matches(ibs, qres, aid=aid, fnum=fnum, figtitle=figtitle, same_fig=not same_fig, **kwargs) def query_last_feature(): viz.show_nearest_descriptors(ibs, qaid, last_state.last_fx, df2.next_fnum()) fig3 = df2.gcf() ih.connect_callback(fig3, 'button_press_event', _click_matches_click) df2.update() toggle_samefig_key = 'Toggle same_fig (currently %r)' % same_fig opt2_callback = [ (toggle_samefig_key, toggle_samefig), ('query last feature', query_last_feature), ('cancel', lambda: print('cancel')), ] guitool.connect_context_menu(fig.canvas, opt2_callback) ih.connect_callback(fig, 'button_press_event', _click_matches_click) viz.draw() return fig
def ishow_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)
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()
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()
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()
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
def ishow_name(ibs, nid, sel_aids=[], select_aid_callback=None, fnum=5, dodraw=True, **kwargs): r""" Args: ibs (IBEISController): ibeis controller object nid (?): sel_aids (list): select_aid_callback (None): fnum (int): figure number CommandLine: python -m ibeis.viz.interact.interact_name --test-ishow_name --show Example: >>> # DISABLE_DOCTEST >>> from ibeis.viz.interact.interact_name import * # NOQA >>> import ibeis >>> # build test data >>> ibs = ibeis.opendb('testdb1') >>> nid = ut.get_argval('--nid', int, default=1) >>> sel_aids = [] >>> select_aid_callback = None >>> fnum = 5 >>> dodraw = ut.show_was_requested() >>> # execute function >>> result = ishow_name(ibs, nid, sel_aids, select_aid_callback, fnum, dodraw) >>> # verify results >>> pt.show_if_requested() >>> print(result) """ if fnum is None: fnum = pt.next_fnum() fig = ih.begin_interaction('name', fnum) def _on_name_click(event): print_('[inter] clicked name') ax = event.inaxes if ih.clicked_inside_axis(event): viztype = vh.get_ibsdat(ax, 'viztype') print_(' viztype=%r' % viztype) if viztype == 'chip': aid = vh.get_ibsdat(ax, 'aid') print('... aid=%r' % aid) if event.button == 3: # right-click import guitool from ibeis.viz.interact import interact_chip height = fig.canvas.geometry().height() qpoint = guitool.newQPoint(event.x, height - event.y) refresh_func = functools.partial(viz.show_name, ibs, nid, fnum=fnum, sel_aids=sel_aids) interact_chip.show_annot_context_menu( ibs, aid, fig.canvas, qpoint, refresh_func=refresh_func, with_interact_name=False) else: viz.show_name(ibs, nid, fnum=fnum, sel_aids=[aid], in_image=True) if select_aid_callback is not None: select_aid_callback(aid) viz.draw() viz.show_name(ibs, nid, fnum=fnum, sel_aids=sel_aids, in_image=True) if dodraw: viz.draw() ih.connect_callback(fig, 'button_press_event', _on_name_click) pass
def start_new_viz(simp, nRows, nCols, fnum=None): import plottool as pt rchip1, rchip2, kpts1, vecs1, kpts2, vecs2, dlen_sqrd2 = simp.testtup fm_ORIG, fs_ORIG, fm_RAT, fs_RAT, fm_SV, fs_SV, H_RAT = simp.basetup fm_SC, fs_SC, fm_SCR, fs_SCR, fm_SCRSV, fs_SCRSV, H_SCR = simp.nexttup fm_norm_RAT, fm_norm_SV = simp.base_meta fm_norm_SC, fm_norm_SCR, fm_norm_SVSCR = simp.next_meta locals_ = ut.delete_dict_keys(locals(), ['title']) keytitle_tups = [ ('ORIG', 'initial neighbors'), ('RAT', 'ratio filtered'), ('SV', 'ratio filtered + SV'), ('SC', 'spatially constrained'), ('SCR', 'spatially constrained + ratio'), ('SCRSV', 'spatially constrained + SV'), ] keytitle_dict = dict(keytitle_tups) key_list = ut.get_list_column(keytitle_tups, 0) matchtup_dict = { key: (locals_['fm_' + key], locals_['fs_' + key]) for key in key_list } normtup_dict = { key: locals_.get('fm_norm_' + key, None) for key in key_list } next_pnum = pt.make_pnum_nextgen(nRows=nRows, nCols=nCols) if fnum is None: fnum = pt.next_fnum() INTERACTIVE = True if INTERACTIVE: from plottool import interact_helpers as ih fig = ih.begin_interaction('qres', fnum) ih.connect_callback(fig, 'button_press_event', on_single_match_clicked) else: pt.figure(fnum=fnum, doclf=True, docla=True) def show_matches_(key, **kwargs): assert key in key_list, 'unknown key=%r' % (key,) showkw = locals_.copy() pnum = next_pnum() showkw['pnum'] = pnum showkw['fnum'] = fnum showkw.update(kwargs) _fm, _fs = matchtup_dict[key] title = keytitle_dict[key] if kwargs.get('coverage'): from vtool import coverage_kpts kpts2, rchip2 = ut.dict_get(locals_, ('kpts2', 'rchip2')) kpts2_m = kpts2.take(_fm.T[1], axis=0) chipshape2 = rchip2.shape chipsize2 = chipshape2[0:2][::-1] coverage_mask = coverage_kpts.make_kpts_coverage_mask(kpts2_m, chipsize2, fx2_score=_fs, resize=True, return_patch=False) pt.imshow(coverage_mask * 255, pnum=pnum, fnum=fnum) else: if kwargs.get('norm', False): _fm = normtup_dict[key] assert _fm is not None, key showkw['cmap'] = 'cool' title += ' normalizers' show_matches(_fm, _fs, title=title, key=key, **showkw) # state hack #show_matches_.next_pnum = next_pnum return show_matches_
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
def select_ith_match(self, mx): """ Selects the ith match and visualizes and prints information concerning features weights, keypoint details, and sift descriptions """ import plottool as pt from plottool import viz_featrow from plottool import interact_helpers as ih # <CLOSURE VARS> fnum = self.fnum same_fig = self.same_fig rchip1 = self.rchip1 rchip2 = self.rchip2 # </CLOSURE VARS> self.mx = mx print("+--- SELECT --- ") print("... selecting mx-th=%r feature match" % mx) fsv = self.fsv fs = self.fs print("score stats:") print(ut.get_stats_str(fsv, axis=0, newlines=True)) 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 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)
def set_callbacks(self): # TODO: view probchip #guitool.connect_context_menu(self.fig.canvas, options) ih.connect_callback(self.fig, 'button_press_event', self.on_click)
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)
def start_new_viz(simp, nRows, nCols, fnum=None): import plottool as pt rchip1, rchip2, kpts1, vecs1, kpts2, vecs2, dlen_sqrd2 = simp.testtup fm_ORIG, fs_ORIG, fm_RAT, fs_RAT, fm_SV, fs_SV, H_RAT = simp.basetup fm_SC, fs_SC, fm_SCR, fs_SCR, fm_SCRSV, fs_SCRSV, H_SCR = simp.nexttup fm_norm_RAT, fm_norm_SV = simp.base_meta fm_norm_SC, fm_norm_SCR, fm_norm_SVSCR = simp.next_meta locals_ = ut.delete_dict_keys(locals(), ['title']) keytitle_tups = [ ('ORIG', 'initial neighbors'), ('RAT', 'ratio filtered'), ('SV', 'ratio filtered + SV'), ('SC', 'spatially constrained'), ('SCR', 'spatially constrained + ratio'), ('SCRSV', 'spatially constrained + SV'), ] keytitle_dict = dict(keytitle_tups) key_list = ut.get_list_column(keytitle_tups, 0) matchtup_dict = { key: (locals_['fm_' + key], locals_['fs_' + key]) for key in key_list } normtup_dict = { key: locals_.get('fm_norm_' + key, None) for key in key_list } next_pnum = pt.make_pnum_nextgen(nRows=nRows, nCols=nCols) if fnum is None: fnum = pt.next_fnum() INTERACTIVE = True if INTERACTIVE: from plottool import interact_helpers as ih fig = ih.begin_interaction('qres', fnum) ih.connect_callback(fig, 'button_press_event', on_single_match_clicked) else: pt.figure(fnum=fnum, doclf=True, docla=True) def show_matches_(key, **kwargs): assert key in key_list, 'unknown key=%r' % (key, ) showkw = locals_.copy() pnum = next_pnum() showkw['pnum'] = pnum showkw['fnum'] = fnum showkw.update(kwargs) _fm, _fs = matchtup_dict[key] title = keytitle_dict[key] if kwargs.get('coverage'): from vtool import coverage_kpts kpts2, rchip2 = ut.dict_get(locals_, ('kpts2', 'rchip2')) kpts2_m = kpts2.take(_fm.T[1], axis=0) chipshape2 = rchip2.shape chipsize2 = chipshape2[0:2][::-1] coverage_mask = coverage_kpts.make_kpts_coverage_mask( kpts2_m, chipsize2, fx2_score=_fs, resize=True, return_patch=False) pt.imshow(coverage_mask * 255, pnum=pnum, fnum=fnum) else: if kwargs.get('norm', False): _fm = normtup_dict[key] assert _fm is not None, key showkw['cmap'] = 'cool' title += ' normalizers' show_matches(_fm, _fs, title=title, key=key, **showkw) # state hack #show_matches_.next_pnum = next_pnum return show_matches_
def select_ith_match(self, mx): """ Selects the ith match and visualizes and prints information concerning features weights, keypoint details, and sift descriptions """ import plottool as pt from plottool import viz_featrow from plottool import interact_helpers as ih # <CLOSURE VARS> fnum = self.fnum same_fig = self.same_fig rchip1 = self.rchip1 rchip2 = self.rchip2 # </CLOSURE VARS> self.mx = mx print('+--- SELECT --- ') print('... selecting mx-th=%r feature match' % mx) fsv = self.fsv fs = self.fs print('score stats:') print(ut.get_stats_str(fsv, axis=0, newlines=True)) 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 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=.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)
def select_ith_match(self, mx): """ Selects the ith match and visualizes and prints information concerning features weights, keypoint details, and sift descriptions Args: mx (int) - the ith match to visualize qaid (int) - query annotation id aid (int) - database annotation id CommandLine: python -m ibeis.viz.interact.interact_matches --test-select_ith_match --show Example: >>> # DISABLE_DOCTEST >>> from ibeis.viz.interact.interact_matches import * # NOQA >>> self = testdata_match_interact(mx=1) >>> pt.show_if_requested() """ ibs = self.ibs qaid = self.qaid aid = self.daid fnum = self.fnum figtitle = self.figtitle rchip1 = self.rchip1 rchip2 = self.rchip2 aid = self.daid same_fig = self.same_fig self.mx = mx print('+--- SELECT --- ') print('qaid=%r, daid=%r' % (qaid, aid)) print('... selecting mx-th=%r feature match' % mx) if False: print('score stats:') print(ut.get_stats_str(self.fsv, axis=0, newlines=True)) print('fsv[mx] = %r' % (self.fsv[mx],)) print('fs[mx] = %r' % (self.fs[mx],)) """ # test feature weights of actual chips fx1, fx2 = fm[mx] daid = aid ibs.get_annot_fgweights([daid])[0][fx2] ibs.get_annot_fgweights([qaid])[0][fx1] """ #---------------------- # Get info for the select_ith_match plot self.mode = 1 # Get the mx-th feature match fx1, fx2 = self.fm[mx] fscore2 = self.fs[mx] fk2 = self.fk[mx] kpts1 = ibs.get_annot_kpts([self.qaid], config2_=self.query_config2_)[0] kpts2 = ibs.get_annot_kpts([self.daid], config2_=self.data_config2_)[0] desc1 = ibs.get_annot_vecs([self.qaid], config2_=self.query_config2_)[0] desc2 = ibs.get_annot_vecs([self.daid], config2_=self.data_config2_)[0] 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 self.last_fx = fx1 # Extracted keypoints to draw extracted_list = [(rchip1, kp1, sift1, fx1, self.qaid, info1), (rchip2, kp2, sift2, fx2, self.daid, 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(pnum1, ell_alpha=.4, ell_linewidth=1.8, colors=df2.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 = df2.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) df2.set_figtitle(figtitle + vh.get_vsstr(qaid, aid))
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)