def show_matches2( ibs, aid1, aid2, fm=None, fs=None, fm_norm=None, sel_fm=[], H1=None, H2=None, qreq_=None, **kwargs ): """ TODO: DEPRICATE and use special case of show_name_matches Integrate ChipMatch Used in: Found 1 line(s) in '/home/joncrall/code/wbia_cnn/wbia_cnn/ingest_wbia.py': ingest_wbia.py : 827 | >>> wbia.viz.viz_matches.show_matches2(ibs, aid1, aid2, fm=None, kpts1=kpts1, kpts2=kpts2) ---------------------- Found 4 line(s) in '/home/joncrall/code/wbia/wbia/viz/viz_matches.py': viz_matches.py : 423 |def show_matches2(ibs, aid1, aid2, fm=None, fs=None, fm_norm=None, sel_fm=[], viz_matches.py : 430 | python -m wbia.viz.viz_matches --exec-show_matches2 --show viz_matches.py : 431 | python -m wbia --tf ChipMatch.ishow_single_annotmatch show_matches2 --show viz_matches.py : 515 | return show_matches2(ibs, aid1, aid2, fm, fs, qreq_=qreq_, **kwargs) ---------------------- Found 1 line(s) in '/home/joncrall/code/wbia/wbia/viz/interact/interact_matches.py': interact_matches.py : 372 | tup = viz.viz_matches.show_matches2(ibs, self.qaid, self.daid, ---------------------- Found 2 line(s) in '/home/joncrall/code/wbia/wbia/algo/hots/chip_match.py': chip_match.py : 204 | viz_matches.show_matches2(qreq_.ibs, cm.qaid, daid, qreq_=qreq_, chip_match.py : 219 | wbia.viz.viz_matches.show_matches2 ---------------------- Found 1 line(s) in '/home/joncrall/code/wbia/wbia/algo/hots/scoring.py': scoring.py : 562 | viz.viz_matches.show_matches2(qreq_.ibs, qaid, daid, fm, fs, CommandLine: python -m wbia.viz.viz_matches --exec-show_matches2 --show python -m wbia --tf ChipMatch.ishow_single_annotmatch show_matches2 --show Example: >>> # DISABLE_DOCTEST >>> from wbia.algo.hots.chip_match import * # NOQA >>> import wbia >>> cm, qreq_ = wbia.testdata_cm(defaultdb='PZ_MTEST', default_qaids=[18]) >>> cm.score_name_nsum(qreq_) >>> daid = cm.get_top_aids()[0] >>> cm.show_single_annotmatch(qreq_, daid) >>> ut.show_if_requested() """ if qreq_ is None: logger.info('[viz_matches] WARNING: qreq_ is None') kwargs = kwargs.copy() in_image = kwargs.get('in_image', False) draw_fmatches = kwargs.pop('draw_fmatches', True) # Read query and result info (chips, names, ...) rchip1, rchip2, kpts1, kpts2 = _get_annot_pair_info( ibs, aid1, aid2, qreq_, draw_fmatches, **kwargs ) ut.delete_keys(kwargs, ['kpts1', 'kpts2']) if fm is None: assert len(kpts1) == len(kpts2), 'keypoints should be in correspondence' import numpy as np fm = np.vstack((np.arange(len(kpts1)), np.arange(len(kpts1)))).T # Build annotation strings / colors lbl1 = 'q' + vh.get_aidstrs(aid1) lbl2 = vh.get_aidstrs(aid2) if in_image: # HACK! lbl1 = None lbl2 = None # Draws the chips and keypoint matches try: ax, xywh1, xywh2 = pt.show_chipmatch2( rchip1, rchip2, kpts1, kpts2, fm, fs=fs, fm_norm=fm_norm, H1=H1, H2=H2, lbl1=lbl1, lbl2=lbl2, sel_fm=sel_fm, **kwargs ) except Exception as ex: ut.printex(ex, 'consider qr.remove_corrupted_queries', '[viz_matches]') logger.info('') raise # Moved the code into show_chipmatch # if len(sel_fm) > 0: # # Draw any selected matches # sm_kw = dict(rect=True, colors=pt.BLUE) # pt.plot_fmatch(xywh1, xywh2, kpts1, kpts2, sel_fm, **sm_kw) (x1, y1, w1, h1) = xywh1 (x2, y2, w2, h2) = xywh2 offset1 = (x1, y1) offset2 = (x2, y2) annotate_matches2( ibs, aid1, aid2, fm, fs, xywh2=xywh2, xywh1=xywh1, offset1=offset1, offset2=offset2, **kwargs ) return ax, xywh1, xywh2
def chipmatch_view(self, fnum=None, pnum=(1, 1, 1), verbose=None, **kwargs_): """ just visualizes the matches using some type of lines """ import wbia.plottool as pt from wbia.plottool import plot_helpers as ph if fnum is None: fnum = self.fnum if verbose is None: verbose = ut.VERBOSE if verbose: print('-- CHIPMATCH VIEW --') print('[ichipmatch_view] self.mode = %r' % (self.mode, )) mode = kwargs_.get('mode', self.mode) draw_ell = mode >= 1 draw_lines = mode == 2 if verbose: print('[ichipmatch_view] draw_lines = %r' % (draw_lines, )) print('[ichipmatch_view] draw_ell = %r' % (draw_ell, )) # pt.figure(fnum=fnum, docla=True, doclf=True) # NOTE: i remove the clf here. might cause issues pt.figure(fnum=fnum, docla=True, doclf=False) # show_matches_kw = self.__dict__.copy() show_matches_kw = dict( # fnum=fnum, pnum=pnum, draw_lines=draw_lines, draw_ell=draw_ell, colorbar_=True, vert=self.vert, white_background=False, ) show_matches_kw.update(kwargs_) if verbose: print('self.warp_homog = %r' % (self.warp_homog, )) if self.warp_homog: show_matches_kw['H1'] = self.H1 show_matches_kw['H2'] = self.H2 if verbose: print('show_matches_kw = %s' % (ut.repr2(show_matches_kw, truncate=True))) # tup = show_matches(fm, fs, **show_matches_kw) ax, xywh1, xywh2 = pt.show_chipmatch2(self.rchip1, self.rchip2, self.kpts1, self.kpts2, fm=self.fm, fs=self.fs, pnum=pnum, **show_matches_kw) self.xywh2 = xywh2 ph.set_plotdat(ax, 'viztype', 'matches') if self.truth is not None and self.truth: truth_color = pt.TRUE_BLUE # if else pt.FALSE_RED pt.draw_border(ax, color=truth_color, lw=4) if self.title is not None: pt.set_title(self.title, ax=ax)
def show_sv_simple(chip1, chip2, kpts1, kpts2, fm, inliers, mx=None, fnum=1, vert=None, **kwargs): """ CommandLine: python -m wbia.plottool.draw_sv --test-show_sv_simple --show Example: >>> # DISABLE_DOCTEST >>> from wbia.plottool.draw_sv import * # NOQA >>> import vtool as vt >>> kpts1, kpts2, fm, aff_inliers, chip1, chip2, xy_thresh_sqrd = vt.testdata_matching_affine_inliers() >>> inliers = aff_inliers >>> mx = None >>> fnum = 1 >>> vert = None # ut.get_argval('--vert', type_=bool, default=None) >>> result = show_sv_simple(chip1, chip2, kpts1, kpts2, fm, inliers, mx, fnum, vert=vert) >>> print(result) >>> import wbia.plottool as pt >>> pt.show_if_requested() """ import wbia.plottool as pt import vtool as vt colors = pt.distinct_colors(2, brightness=0.95) color1, color2 = colors[0:2] # Begin the drawing fnum = pt.ensure_fnum(fnum) pt.figure(fnum=fnum, pnum=(1, 1, 1), docla=True, doclf=True) # dmkwargs = dict(fs=None, title='Inconsistent Matches', all_kpts=False, draw_lines=True, # docla=True, draw_border=True, fnum=fnum, pnum=(1, 1, 1), colors=pt.ORANGE) inlier_mask = vt.index_to_boolmask(inliers, maxval=len(fm)) fm_inliers = fm.compress(inlier_mask, axis=0) fm_outliers = fm.compress(np.logical_not(inlier_mask), axis=0) xywh1, xywh2, sf_tup = pt.show_chipmatch2(chip1, chip2, vert=vert, modifysize=True, new_return=True) sf1, sf2 = sf_tup fmatch_kw = dict(ell_linewidth=2, ell_alpha=0.7, line_alpha=0.7) pt.plot_fmatch(xywh1, xywh2, kpts1, kpts2, fm_inliers, colors=color1, scale_factor1=sf1, scale_factor2=sf2, **fmatch_kw) pt.plot_fmatch(xywh1, xywh2, kpts1, kpts2, fm_outliers, colors=color2, scale_factor1=sf1, scale_factor2=sf2, **fmatch_kw)
def nosql_draw(check_func, rchip1_fpath, rchip2_fpath, kpts1, kpts2): # This gets executed in the child thread and does drawing async style # from matplotlib.backends.backend_pdf import FigureCanvasPdf as FigureCanvas # from matplotlib.backends.backend_pdf import Figure # from matplotlib.backends.backend_svg import FigureCanvas # from matplotlib.backends.backend_svg import Figure from matplotlib.backends.backend_agg import FigureCanvas try: from matplotlib.backends.backend_agg import Figure except ImportError: from matplotlib.figure import Figure kpts1_ = vt.offset_kpts(kpts1, (0, 0), (resize_factor, resize_factor)) kpts2_ = vt.offset_kpts(kpts2, (0, 0), (resize_factor, resize_factor)) # from matplotlib.figure import Figure if check_func is not None and check_func(): return rchip1 = vt.imread(rchip1_fpath) rchip1 = vt.resize_image_by_scale(rchip1, resize_factor) if check_func is not None and check_func(): return rchip2 = vt.imread(rchip2_fpath) rchip2 = vt.resize_image_by_scale(rchip2, resize_factor) if check_func is not None and check_func(): return try: idx = cm.daid2_idx[daid] fm = cm.fm_list[idx] fsv = None if cm.fsv_list is None else cm.fsv_list[idx] fs = None if fsv is None else fsv.prod(axis=1) except KeyError: fm = [] fs = None fsv = None maxnum = 200 if fs is not None and len(fs) > maxnum: # HACK TO ONLY SHOW TOP MATCHES sortx = fs.argsort()[::-1] fm = fm.take(sortx[:maxnum], axis=0) fs = fs.take(sortx[:maxnum], axis=0) was_interactive = mpl.is_interactive() if was_interactive: mpl.interactive(False) # fnum = 32 fig = Figure() canvas = FigureCanvas(fig) # NOQA # fig.clf() ax = fig.add_subplot(1, 1, 1) if check_func is not None and check_func(): return # fig = pt.plt.figure(fnum) # H1 = np.eye(3) # H2 = np.eye(3) # H1[0, 0] = .5 # H1[1, 1] = .5 # H2[0, 0] = .5 # H2[1, 1] = .5 ax, xywh1, xywh2 = pt.show_chipmatch2(rchip1, rchip2, kpts1_, kpts2_, fm, fs=fs, colorbar_=False, ax=ax) if check_func is not None and check_func(): return savekw = { # 'dpi' : 60, 'dpi': 80, } axes_extents = pt.extract_axes_extents(fig) # assert len(axes_extents) == 1, 'more than one axes' extent = axes_extents[0] with io.BytesIO() as stream: # This call takes 23% - 15% of the time depending on settings fig.savefig(stream, bbox_inches=extent, **savekw) stream.seek(0) data = np.fromstring(stream.getvalue(), dtype=np.uint8) if check_func is not None and check_func(): return pt.plt.close(fig) image = cv2.imdecode(data, 1) thumbsize = 221 max_dsize = (thumbsize, thumbsize) dsize, sx, sy = vt.resized_clamped_thumb_dims(vt.get_size(image), max_dsize) if check_func is not None and check_func(): return image = vt.resize(image, dsize) vt.imwrite(fpath, image) if check_func is not None and check_func(): return