def query_aids(ibs, qaid_list, daid_list=None): """ CommandLine: python dev.py -w --show -t query --db PZ_MTEST --qaid 72 """ import wbia if daid_list is None: daid_list = ibs.get_valid_aids() cm_list = ibs.query_chips(qaid_list, daid_list) for cm in cm_list: assert isinstance(cm, wbia.algo.hots.hots_query_result.QueryResult) cm.ishow_top(ibs, fnum=df2.next_fnum(), annot_mode=1, make_figtitle=True)
def sver_aids(ibs, qaid_list, daid_list=None): """ CommandLine: python dev.py -w --show -t sver --db PZ_MTEST --qaid 72 python dev.py -w --show -t sver --db PZ_MTEST --qaid 1 """ from wbia.viz import interact if daid_list is None: daid_list = ibs.get_valid_aids() cm_list = ibs.query_chips(qaid_list, daid_list) for cm in cm_list: aid2 = cm.get_top_aids()[0] interact.ishow_sver(ibs, cm.qaid, aid2, fnum=df2.next_fnum(), annot_mode=1)
def show_keypoint_gradient_orientations(ibs, aid, fx, fnum=None, pnum=None, config2_=None): # Draw the gradient vectors of a patch overlaying the keypoint if fnum is None: fnum = df2.next_fnum() rchip = 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] fig = df2.draw_keypoint_gradient_orientations(rchip, kp, sift=sift, mode='vec', fnum=fnum, pnum=pnum) fig.canvas.draw() fig.show() df2.set_title('Gradient orientation\n %s, fx=%d' % (get_aidstrs(aid), fx))
def ishow_image(ibs, gid, sel_aids=[], fnum=None, select_callback=None, **kwargs): if ut.VERBOSE: print(ut.get_caller_name(range(9))) print('[interact_image] gid=%r fnum=%r' % (gid, fnum)) if fnum is None: fnum = df2.next_fnum() # TODO: change to class based structure self = ut.DynStruct() self.fnum = fnum fig = ih.begin_interaction('image', fnum) # printDBG(utool.func_str(interact_image, [], locals())) kwargs['draw_lbls'] = kwargs.get('draw_lbls', True) def _image_view(sel_aids=sel_aids, **_kwargs): try: viz.show_image(ibs, gid, sel_aids=sel_aids, fnum=self.fnum, **_kwargs) df2.set_figtitle('Image View') except TypeError as ex: ut.printex(ex, ut.repr2(_kwargs)) raise # Create callback wrapper def _on_image_click(event): print('[inter] clicked image') if ih.clicked_outside_axis(event): # Toggle draw lbls kwargs['draw_lbls'] = not kwargs.get('draw_lbls', True) _image_view(**kwargs) else: ax = event.inaxes viztype = vh.get_ibsdat(ax, 'viztype') annotation_centers = vh.get_ibsdat(ax, 'annotation_centers', default=[]) print(' annotation_centers=%r' % annotation_centers) print(' viztype=%r' % viztype) if len(annotation_centers) == 0: print(' ...no chips exist to click') return x, y = event.xdata, event.ydata # Find ANNOTATION center nearest to the clicked point aid_list = vh.get_ibsdat(ax, 'aid_list', default=[]) import vtool as vt centx, _dist = vt.nearest_point(x, y, annotation_centers) aid = aid_list[centx] print(' ...clicked aid=%r' % aid) if select_callback is not None: # HACK, should just implement this correctly here select_callback(gid, sel_aids=[aid], fnum=self.fnum) else: _image_view(sel_aids=[aid]) viz.draw() _image_view(**kwargs) viz.draw() ih.connect_callback(fig, 'button_press_event', _on_image_click)
def show_nearest_descriptors(ibs, qaid, qfx, fnum=None, stride=5, qreq_=None, **kwargs): r""" Args: ibs (wbia.IBEISController): image analysis api qaid (int): query annotation id qfx (int): query feature index fnum (int): figure number stride (int): consecutive_distance_compare (bool): CommandLine: # Find a good match to inspect python -m wbia.viz.interact.interact_matches --test-testdata_match_interact --show --db PZ_MTEST --qaid 3 # Now inspect it python -m wbia.viz.viz_nearest_descriptors --test-show_nearest_descriptors --show --db PZ_MTEST --qaid 3 --qfx 879 python -m wbia.viz.viz_nearest_descriptors --test-show_nearest_descriptors --show python -m wbia.viz.viz_nearest_descriptors --test-show_nearest_descriptors --db PZ_MTEST --qaid 3 --qfx 879 --diskshow --save foo.png --dpi=256 SeeAlso: plottool.viz_featrow ~/code/plottool/plottool/viz_featrow.py Example: >>> # DISABLE_DOCTEST >>> from wbia.viz.viz_nearest_descriptors import * # NOQA >>> import wbia >>> # build test data >>> if True: >>> import matplotlib as mpl >>> from wbia.scripts.thesis import TMP_RC >>> mpl.rcParams.update(TMP_RC) >>> qreq_ = wbia.testdata_qreq_() >>> ibs = wbia.opendb('PZ_MTEST') >>> qaid = qreq_.qaids[0] >>> qfx = ut.get_argval('--qfx', type_=None, default=879) >>> fnum = None >>> stride = 5 >>> # execute function >>> skip = False >>> result = show_nearest_descriptors(ibs, qaid, qfx, fnum, stride, >>> draw_chip=True, >>> draw_warped=True, >>> draw_unwarped=False, >>> draw_desc=False, qreq_=qreq_) >>> # verify results >>> print(result) >>> pt.show_if_requested() """ import wbia.plottool as pt # NOQA consecutive_distance_compare = True draw_chip = kwargs.get('draw_chip', False) draw_desc = kwargs.get('draw_desc', True) draw_warped = kwargs.get('draw_warped', True) draw_unwarped = kwargs.get('draw_unwarped', True) # skip = kwargs.get('skip', True) # Plots the nearest neighbors of a given feature (qaid, qfx) if fnum is None: fnum = df2.next_fnum() try: # Flann NN query (qfx, qfx2_daid, qfx2_dfx, qfx2_dist, K, Knorm) = get_annotfeat_nn_index(ibs, qaid, qfx, qreq_=qreq_) # Adds metadata to a feature match def get_extract_tuple(aid, fx, k=-1): rchip = ibs.get_annot_chips(aid) kp = ibs.get_annot_kpts(aid)[fx] sift = ibs.get_annot_vecs(aid)[fx] if not ut.get_argflag('--texknormplot'): aidstr = vh.get_aidstrs(aid) nidstr = vh.get_nidstrs(ibs.get_annot_nids(aid)) id_str = ' ' + aidstr + ' ' + nidstr + ' fx=%r' % (fx, ) else: id_str = nidstr = aidstr = '' info = '' if k == -1: if pt.is_texmode(): info = '\\vspace{1cm}' info += 'Query $\\mathbf{d}_i$' info += '\n\\_' info += '\n\\_' else: if len(id_str) > '': info = 'Query: %s' % (id_str, ) else: info = 'Query' type_ = 'Query' elif k < K: type_ = 'Match' if ut.get_argflag('--texknormplot') and pt.is_texmode(): # info = 'Match:\n$k=%r$, $\\frac{||\\mathbf{d}_i - \\mathbf{d}_j||}{Z}=%.3f$' % (k, qfx2_dist[0, k]) info = '\\vspace{1cm}' info += 'Match: $\\mathbf{d}_{j_%r}$\n$\\textrm{dist}=%.3f$' % ( k, qfx2_dist[0, k], ) # info += '\n$s_{\\tt{LNBNN}}=%.3f$' % (qfx2_dist[0, K + Knorm - 1] - qfx2_dist[0, k]) info += '\n$s=%.3f$' % (qfx2_dist[0, K + Knorm - 1] - qfx2_dist[0, k]) else: info = 'Match:%s\nk=%r, dist=%.3f' % (id_str, k, qfx2_dist[0, k]) info += '\nLNBNN=%.3f' % (qfx2_dist[0, K + Knorm - 1] - qfx2_dist[0, k]) elif k < Knorm + K: type_ = 'Norm' if ut.get_argflag('--texknormplot') and pt.is_texmode(): # info = 'Norm: $j_%r$\ndist=%.3f' % (id_str, k, qfx2_dist[0, k]) info = '\\vspace{1cm}' info += 'Norm: $j_%r$\n$\\textrm{dist}=%.3f$' % ( k, qfx2_dist[0, k]) info += '\n\\_' else: info = 'Norm: %s\n$k=%r$, dist=$%.3f$' % ( id_str, k, qfx2_dist[0, k], ) else: raise Exception('[viz] problem k=%r') return (rchip, kp, sift, fx, aid, info, type_) extracted_list = [] # Remember the query sift feature extracted_list.append(get_extract_tuple(qaid, qfx, -1)) origsift = extracted_list[0][2] skipped = 0 for k in range(K + Knorm): # if qfx2_daid[0, k] == qaid and qfx2_dfx[0, k] == qfx: if qfx2_daid[0, k] == qaid: skipped += 1 continue tup = get_extract_tuple(qfx2_daid[0, k], qfx2_dfx[0, k], k) extracted_list.append(tup) # Draw the _select_ith_match plot nRows = len(extracted_list) if stride is None: stride = nRows # Draw selected feature matches prevsift = None px = 0 # plot offset px_shift = 0 # plot stride shift nExtracted = len(extracted_list) featrow_kw = dict( draw_chip=draw_chip, draw_desc=draw_desc, draw_warped=draw_warped, draw_unwarped=draw_unwarped, ) if ut.get_argflag('--texknormplot'): featrow_kw['ell_color'] = pt.ORANGE featrow_kw['ell_linewidth'] = 1 featrow_kw['arm1_lw'] = 0.5 featrow_kw['stroke'] = 0 pass for listx, tup in enumerate(extracted_list): (rchip, kp, sift, fx, aid, info, type_) = tup if listx % stride == 0: # Create a temporary nRows and fnum in case we are splitting # up nearest neighbors into separate figures with stride _fnum = fnum + listx _nRows = min(nExtracted - listx, stride) px_shift = px df2.figure(fnum=_fnum, docla=True, doclf=True) px_ = px - px_shift px = draw_feat_row( rchip, fx, kp, sift, _fnum, _nRows, px=px_, prevsift=prevsift, origsift=origsift, aid=aid, info=info, type_=type_, **featrow_kw, ) px += px_shift if prevsift is None or consecutive_distance_compare: prevsift = sift # df2.adjust_subplots(hspace=.85, wspace=0, top=.95, bottom=.087, left=.05, right=.95) except Exception as ex: logger.info('[viz] Error in show nearest descriptors') logger.info(ex) raise
def show_aids(ibs, qaid_list): from wbia.viz import interact for aid in qaid_list: interact.ishow_chip(ibs, aid, fnum=df2.next_fnum())