def _select_ith_kpt(fx): logger.info('[interact] viewing ith=%r keypoint' % fx) # Get the fx-th keypiont kp, sift = kpts[fx], vecs[fx] # Draw the image with keypoint fx highlighted _viz_keypoints(fnum, (2, 1, 1), sel_fx=fx, **kwargs) # MAYBE: remove kwargs # Draw the selected feature nRows, nCols, px = (2, 3, 3) draw_feat_row(chip, fx, kp, sift, fnum, nRows, nCols, px, None)
def _select_ith_kpt(self, fx): logger.info('[interact] viewing ith=%r keypoint' % fx) # Get the fx-th keypiont kp, sift = self.kpts[fx], self.vecs[fx] # Draw the image with keypoint fx highlighted self.plot(self.fnum, (2, 1, 1), sel_fx=fx) # Draw the selected feature nRows, nCols, px = (2, 3, 3) draw_feat_row(self.chip, fx, kp, sift, self.fnum, nRows, nCols, px, None)
def _select_fxth_kpt(fx): from wbia.plottool.viz_featrow import draw_feat_row # Get the fx-th keypiont chip = ibs.get_annot_chips(aid, config2_=config2_) kp = ibs.get_annot_kpts(aid, config2_=config2_)[fx] sift = ibs.get_annot_vecs(aid, config2_=config2_)[fx] # Draw chip + keypoints + highlighted plots _chip_view(pnum=(2, 1, 1), sel_fx=fx) # ishow_chip(ibs, aid, fnum=None, fx=fx, config2_=config2_, **kwargs) # Draw the selected feature plots nRows, nCols, px = (2, 3, 3) draw_feat_row(chip, fx, kp, sift, fnum, nRows, nCols, px, None)
def 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 select_ith_match(self, mx): """ Selects the ith match and visualizes and prints information concerning features weights, keypoint details, and sift descriptions """ import wbia.plottool as pt from wbia.plottool import viz_featrow from wbia.plottool import interact_helpers as ih fnum = self.fnum same_fig = self.same_fig rchip1 = self.rchip1 rchip2 = self.rchip2 self.mx = mx print('+--- SELECT --- ') print('... selecting mx-th=%r feature match' % mx) fsv = self.fsv fs = self.fs print('score stats:') print(ut.repr2(ut.get_stats(fsv, axis=0), nl=1)) print('fsv[mx] = %r' % (fsv[mx], )) print('fs[mx] = %r' % (fs[mx], )) # ---------------------- # Get info for the select_ith_match plot self.mode = 1 # Get the mx-th feature match fx1, fx2 = self.fm[mx] # Older info fscore2 = self.fs[mx] fk2 = None if self.fk is None else self.fk[mx] kp1, kp2 = self.kpts1[fx1], self.kpts2[fx2] vecs1, vecs2 = self.vecs1[fx1], self.vecs2[fx2] info1 = '\nquery' info2 = '\nk=%r fscore=%r' % (fk2, fscore2) # self.last_fx = fx1 self.last_fx = fx1 # Extracted keypoints to draw extracted_list = [ (rchip1, kp1, vecs1, fx1, 'aid1', info1), (rchip2, kp2, vecs2, fx2, 'aid2', info2), ] # Normalizng Keypoint # if hasattr(cm, 'filt2_meta') and 'lnbnn' in cm.filt2_meta: # qfx2_norm = cm.filt2_meta['lnbnn'] # # Normalizing chip and feature # (aid3, fx3, normk) = qfx2_norm[fx1] # rchip3 = ibs.get_annot_chips(aid3) # kp3 = ibs.get_annot_kpts(aid3)[fx3] # sift3 = ibs.get_annot_vecs(aid3)[fx3] # info3 = '\nnorm %s k=%r' % (vh.get_aidstrs(aid3), normk) # extracted_list.append((rchip3, kp3, sift3, fx3, aid3, info3)) # else: # pass # #print('WARNING: meta doesnt exist') # ---------------------- # Draw the select_ith_match plot nRows, nCols = len(extracted_list) + same_fig, 3 # Draw matching chips and features sel_fm = np.array([(fx1, fx2)]) pnum1 = (nRows, 1, 1) if same_fig else (1, 1, 1) vert = self.vert if self.vert is not None else False self.chipmatch_view( pnum=pnum1, ell_alpha=0.4, ell_linewidth=1.8, colors=pt.BLUE, sel_fm=sel_fm, vert=vert, ) # Draw selected feature matches px = nCols * same_fig # plot offset prevsift = None if not same_fig: # fnum2 = fnum + len(viz.FNUMS) fnum2 = self.fnum2 fig2 = pt.figure(fnum=fnum2, docla=True, doclf=True) else: fnum2 = fnum for (rchip, kp, sift, fx, aid, info) in extracted_list: px = viz_featrow.draw_feat_row( rchip, fx, kp, sift, fnum2, nRows, nCols, px, prevsift=prevsift, aid=aid, info=info, ) prevsift = sift if not same_fig: ih.connect_callback(fig2, 'button_press_event', self.on_click)