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 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_)
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]) 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_)
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/ibeis_cnn/ibeis_cnn/ingest_ibeis.py': ingest_ibeis.py : 827 | >>> ibeis.viz.viz_matches.show_matches2(ibs, aid1, aid2, fm=None, kpts1=kpts1, kpts2=kpts2) ---------------------- Found 4 line(s) in '/home/joncrall/code/ibeis/ibeis/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 ibeis.viz.viz_matches --exec-show_matches2 --show viz_matches.py : 431 | python -m ibeis --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/ibeis/ibeis/viz/interact/interact_matches.py': interact_matches.py : 372 | tup = viz.viz_matches.show_matches2(ibs, self.qaid, self.daid, ---------------------- Found 1 line(s) in '/home/joncrall/code/ibeis/ibeis/algo/hots/vsone_pipeline.py': vsone_pipeline.py : 1339 | viz_matches.show_matches2(ibs, qaid, daid, fm=fm, fs=fs, fm_norm=fm_norm, ori=True, ---------------------- Found 2 line(s) in '/home/joncrall/code/ibeis/ibeis/algo/hots/chip_match.py': chip_match.py : 204 | viz_matches.show_matches2(qreq_.ibs, cm.qaid, daid, qreq_=qreq_, chip_match.py : 219 | ibeis.viz.viz_matches.show_matches2 ---------------------- Found 1 line(s) in '/home/joncrall/code/ibeis/ibeis/algo/hots/scoring.py': scoring.py : 562 | viz.viz_matches.show_matches2(qreq_.ibs, qaid, daid, fm, fs, CommandLine: python -m ibeis.viz.viz_matches --exec-show_matches2 --show python -m ibeis --tf ChipMatch.ishow_single_annotmatch show_matches2 --show Example: >>> # DISABLE_DOCTEST >>> from ibeis.algo.hots.chip_match import * # NOQA >>> import ibeis >>> cm, qreq_ = ibeis.testdata_cm(defaultdb='PZ_MTEST', default_qaids=[18]) >>> cm.score_nsum(qreq_) >>> daid = cm.get_top_aids()[0] >>> cm.show_single_annotmatch(qreq_, daid) >>> ut.show_if_requested() """ if qreq_ is None: print('[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]') print('') 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 annotate_matches2( ibs, aid1, aid2, fm, fs, offset1=(0, 0), offset2=(0, 0), xywh2=None, # (0, 0, 0, 0), xywh1=None, # (0, 0, 0, 0), qreq_=None, **kwargs): """ TODO: use this as the main function. """ if True: aid_list = [aid1, aid2] bbox_list = [xywh1, xywh2] offset_list = [offset1, offset2] name_fm_list = [fm] name_fs_list = [fs] return annotate_matches3(ibs, aid_list, bbox_list, offset_list, name_fm_list, name_fs_list, qreq_=qreq_, **kwargs) else: # TODO: make sure all of this functionality is incorporated into annotate_matches3 in_image = kwargs.get('in_image', False) show_query = kwargs.get('show_query', True) draw_border = kwargs.get('draw_border', True) draw_lbl = kwargs.get('draw_lbl', True) notitle = kwargs.get('notitle', False) truth = ibs.get_match_truth(aid1, aid2) truth_color = vh.get_truth_color(truth) # Build title title = vh.get_query_text(ibs, None, aid2, truth, qaid=aid1, **kwargs) # Build xlbl ax = pt.gca() ph.set_plotdat(ax, 'viztype', 'matches') ph.set_plotdat(ax, 'qaid', aid1) ph.set_plotdat(ax, 'aid1', aid1) ph.set_plotdat(ax, 'aid2', aid2) if draw_lbl: name1, name2 = ibs.get_annot_names([aid1, aid2]) nid1, nid2 = ibs.get_annot_name_rowids([aid1, aid2], distinguish_unknowns=False) #lbl1 = repr(name1) + ' : ' + 'q' + vh.get_aidstrs(aid1) #lbl2 = repr(name2) + ' : ' + vh.get_aidstrs(aid2) lbl1_list = [] lbl2_list = [] if kwargs.get('show_aid', True): lbl1_list.append('q' + vh.get_aidstrs(aid1)) lbl2_list.append(vh.get_aidstrs(aid2)) if kwargs.get('show_name', True): lbl1_list.append(repr((name1))) lbl2_list.append(repr((name2))) if kwargs.get('show_nid', True): lbl1_list.append(vh.get_nidstrs(nid1)) lbl2_list.append(vh.get_nidstrs(nid2)) lbl1 = ' : '.join(lbl1_list) lbl2 = ' : '.join(lbl2_list) else: lbl1, lbl2 = None, None if vh.NO_LBL_OVERRIDE: title = '' if not notitle: pt.set_title(title, ax) # Plot annotations over images if in_image: bbox1, bbox2 = vh.get_bboxes(ibs, [aid1, aid2], [offset1, offset2]) theta1, theta2 = ibs.get_annot_thetas([aid1, aid2]) # HACK! if show_query: pt.draw_bbox(bbox1, bbox_color=pt.ORANGE, lbl=lbl1, theta=theta1) bbox_color2 = truth_color if draw_border else pt.ORANGE pt.draw_bbox(bbox2, bbox_color=bbox_color2, lbl=lbl2, theta=theta2) else: xy, w, h = pt.get_axis_xy_width_height(ax) bbox2 = (xy[0], xy[1], w, h) theta2 = 0 if xywh2 is None: #xywh2 = (xy[0], xy[1], w, h) # weird when sidebyside is off y seems to be inverted xywh2 = (0, 0, w, h) if not show_query and xywh1 is None: data_config2 = (None if qreq_ is None else qreq_.get_external_data_config2()) # FIXME, pass data in kpts2 = ibs.get_annot_kpts([aid2], config2_=data_config2)[0] #pt.draw_kpts2(kpts2.take(fm.T[1], axis=0)) # Draw any selected matches #sm_kw = dict(rect=True, colors=pt.BLUE) pt.plot_fmatch(None, xywh2, None, kpts2, fm, fs=fs, **kwargs) if draw_border: pt.draw_border(ax, truth_color, 4, offset=offset2) if draw_lbl: # Custom user lbl for chips 1 and 2 if show_query: (x1, y1, w1, h1) = xywh1 pt.absolute_lbl(x1 + w1, y1, lbl1) (x2, y2, w2, h2) = xywh2 pt.absolute_lbl(x2 + w2, y2, lbl2) if True: # No matches draw a red box if fm is None or len(fm) == 0: if draw_border: pass
def annotate_matches3(ibs, aid_list, bbox_list, offset_list, name_fm_list, name_fs_list, qreq_=None, **kwargs): """ TODO: use this as the main function. """ # TODO Use this function when you clean show_matches in_image = kwargs.get('in_image', False) #show_query = kwargs.get('show_query', True) draw_border = kwargs.get('draw_border', True) draw_lbl = kwargs.get('draw_lbl', True) notitle = kwargs.get('notitle', False) # List of annotation scores for each annot in the name #printDBG('[viz] annotate_matches3()') #truth = ibs.get_match_truth(aid1, aid2) #name_equality = ( # np.array(ibs.get_annot_nids(aid_list[1:])) == ibs.get_annot_nids(aid_list[0]) #).tolist() #truth = 1 if all(name_equality) else (2 if any(name_equality) else 0) #truth_color = vh.get_truth_color(truth) ## Build title #score = kwargs.pop('score', None) #rawscore = kwargs.pop('rawscore', None) #aid2_raw_rank = kwargs.pop('aid2_raw_rank', None) #print(kwargs) #title = vh.get_query_text(ibs, None, aid2, truth, qaid=aid1, **kwargs) # Build xlbl ax = pt.gca() ph.set_plotdat(ax, 'viztype', 'multi_match') ph.set_plotdat(ax, 'qaid', aid_list[0]) ph.set_plotdat(ax, 'num_matches', len(aid_list) - 1) ph.set_plotdat(ax, 'aid_list', aid_list[1:]) for count, aid in enumerate(aid_list, start=1): ph.set_plotdat(ax, 'aid%d' % (count, ), aid) #name_equality = (ibs.get_annot_nids(aid_list[0]) == # np.array(ibs.get_annot_nids(aid_list[1:]))) #truth = 1 if np.all(name_equality) else (2 if np.any(name_equality) else 0) truth = get_multitruth(ibs, aid_list) if any(ibs.is_aid_unknown(aid_list[1:])) or ibs.is_aid_unknown( aid_list[0]): truth = ibs.const.TRUTH_UNKNOWN truth_color = vh.get_truth_color(truth) name_annot_scores = kwargs.get('name_annot_scores', None) if len(aid_list) == 2: # HACK; generalize to multple annots title = vh.get_query_text(ibs, None, aid_list[1], truth, qaid=aid_list[0], **kwargs) if not notitle: pt.set_title(title, ax) if draw_lbl: # Build labels nid_list = ibs.get_annot_nids(aid_list, distinguish_unknowns=False) name_list = ibs.get_annot_names(aid_list) lbls_list = [[] for _ in range(len(aid_list))] if kwargs.get('show_name', False): for count, (lbls, name) in enumerate(zip(lbls_list, name_list)): lbls.append(ut.repr2((name))) if kwargs.get('show_nid', True): for count, (lbls, nid) in enumerate(zip(lbls_list, nid_list)): # only label the first two images with nids LABEL_ALL_NIDS = False if count <= 1 or LABEL_ALL_NIDS: #lbls.append(vh.get_nidstrs(nid)) lbls.append(('q' if count == 0 else '') + vh.get_nidstrs(nid)) if kwargs.get('show_aid', True): for count, (lbls, aid) in enumerate(zip(lbls_list, aid_list)): lbls.append(('q' if count == 0 else '') + vh.get_aidstrs(aid)) if (kwargs.get('show_annot_score', True) and name_annot_scores is not None): max_digits = kwargs.get('score_precision', None) for (lbls, score) in zip(lbls_list[1:], name_annot_scores): lbls.append(ut.num_fmt(score, max_digits=max_digits)) lbl_list = [' : '.join(lbls) for lbls in lbls_list] else: lbl_list = [None] * len(aid_list) #pt.set_title(title, ax) # Plot annotations over images if in_image: in_image_bbox_list = vh.get_bboxes(ibs, aid_list, offset_list) in_image_theta_list = ibs.get_annot_thetas(aid_list) # HACK! #if show_query: # pt.draw_bbox(bbox1, bbox_color=pt.ORANGE, lbl=lbl1, theta=theta1) bbox_color = pt.ORANGE bbox_color = truth_color if draw_border else pt.ORANGE for bbox, theta, lbl in zip(in_image_bbox_list, in_image_theta_list, lbl_list): pt.draw_bbox(bbox, bbox_color=bbox_color, lbl=lbl, theta=theta) pass else: xy, w, h = pt.get_axis_xy_width_height(ax) #theta2 = 0 #if xywh2 is None: # #xywh2 = (xy[0], xy[1], w, h) # # weird when sidebyside is off y seems to be inverted # xywh2 = (0, 0, w, h) #if not show_query and xywh1 is None: # data_config2 = None if qreq_ is None else # qreq_.get_external_data_config2() # kpts2 = ibs.get_annot_kpts([aid2], config2_=data_config2)[0] # #pt.draw_kpts2(kpts2.take(fm.T[1], axis=0)) # # Draw any selected matches # #sm_kw = dict(rect=True, colors=pt.BLUE) # pt.plot_fmatch(None, xywh2, None, kpts2, fm, fs=fs, **kwargs) #if draw_border: # pt.draw_border(ax, truth_color, 4, offset=offset2) if draw_border: pt.draw_border(ax, color=truth_color, lw=4) if draw_lbl: # Custom user lbl for chips 1 and 2 #if show_query: # (x1, y1, w1, h1) = xywh1 # pt.absolute_lbl(x1 + w1, y1, lbl1) for bbox, lbl in zip(bbox_list, lbl_list): (x, y, w, h) = bbox pt.absolute_lbl(x + w, y, lbl) # No matches draw a red box if True: no_matches = name_fm_list is None or all( [True if fm is None else len(fm) == 0 for fm in name_fm_list]) if no_matches: xy, w, h = pt.get_axis_xy_width_height(ax) #axes_bbox = (xy[0], xy[1], w, h) if draw_border: pass
def _plot_matches_aids(aid_list, plotx_shift, rowcols): """ helper for show_qres to draw many aids """ _kwshow = dict(draw_ell=annot_mode, draw_pts=False, draw_lines=annot_mode, ell_alpha=.5, all_kpts=all_kpts) _kwshow.update(kwargs) _kwshow['fnum'] = fnum _kwshow['in_image'] = in_image if sidebyside: # Draw each match side by side the query _kwshow['draw_ell'] = annot_mode == 1 _kwshow['draw_lines'] = annot_mode >= 1 else: #print('annot_mode = %r' % (annot_mode,)) _kwshow['draw_ell'] = annot_mode == 1 #_kwshow['draw_pts'] = annot_mode >= 1 #_kwshow['draw_lines'] = False _kwshow['show_query'] = False def _show_matches_fn(aid, orank, pnum): """ Helper function for drawing matches to one aid """ aug = 'rank=%r\n' % orank _kwshow['pnum'] = pnum _kwshow['title_aug'] = aug #draw_ell = annot_mode == 1 #draw_lines = annot_mode >= 1 # If we already are showing the query dont show it here if sidebyside: # Draw each match side by side the query if viz_name_score: cm.show_single_namematch(qreq_, ibs.get_annot_nids(aid), **_kwshow) else: _kwshow['draw_border'] = False _kwshow['draw_lbl'] = False _kwshow['notitle'] = True _kwshow['vert'] = False cm.show_single_annotmatch(qreq_, aid, **_kwshow) #viz_matches.show_matches(ibs, cm, aid, qreq_=qreq_, **_kwshow) else: # Draw each match by themselves data_config2_ = None if qreq_ is None else qreq_.get_external_data_config2( ) #_kwshow['draw_border'] = kwargs.get('draw_border', True) #_kwshow['notitle'] = ut.get_argflag(('--no-title', '--notitle')) viz_chip.show_chip(ibs, aid, annote=False, notitle=True, data_config2_=data_config2_, **_kwshow) if DEBUG_SHOW_QRES: print('[show_qres()] Plotting Chips %s:' % vh.get_aidstrs(aid_list)) if aid_list is None: return # Do lazy load before show #data_config2_ = None if qreq_ is None else qreq_.get_external_data_config2() tblhack = getattr(qreq_, 'tablename', None) # HACK FOR HUMPBACKS # (Also in viz_matches) if tblhack == 'vsone' or (qreq_ is not None and not qreq_._isnewreq): # precompute pass #ibs.get_annot_chips(aid_list, config2_=data_config2_, ensure=True) #ibs.get_annot_kpts(aid_list, config2_=data_config2_, ensure=True) for ox, aid in enumerate(aid_list): plotx = ox + plotx_shift + 1 pnum = (rowcols[0], rowcols[1], plotx) oranks = np.where(ranked_aids == aid)[0] # This pair has no matches between them. if len(oranks) == 0: orank = -1 if aid is None: pt.imshow_null('Failed to find matches\nfor qaid=%r' % (cm.qaid), fnum=fnum, pnum=pnum, fontsize=18) else: _show_matches_fn(aid, orank, pnum) #if DEBUG_SHOW_QRES: # print('skipping pnum=%r' % (pnum,)) continue if DEBUG_SHOW_QRES: print('pnum=%r' % (pnum, )) orank = oranks[0] + 1 _show_matches_fn(aid, orank, pnum)
def _plot_matches_aids(aid_list, plotx_shift, rowcols): """ helper for show_qres to draw many aids """ _kwshow = dict(draw_ell=annot_mode, draw_pts=False, draw_lines=annot_mode, ell_alpha=.5, all_kpts=all_kpts) _kwshow.update(kwargs) _kwshow['fnum'] = fnum _kwshow['in_image'] = in_image if sidebyside: # Draw each match side by side the query _kwshow['draw_ell'] = annot_mode == 1 _kwshow['draw_lines'] = annot_mode >= 1 else: #print('annot_mode = %r' % (annot_mode,)) _kwshow['draw_ell'] = annot_mode == 1 #_kwshow['draw_pts'] = annot_mode >= 1 #_kwshow['draw_lines'] = False _kwshow['show_query'] = False def _show_matches_fn(aid, orank, pnum): """ Helper function for drawing matches to one aid """ aug = 'rank=%r\n' % orank _kwshow['pnum'] = pnum _kwshow['title_aug'] = aug #draw_ell = annot_mode == 1 #draw_lines = annot_mode >= 1 # If we already are showing the query dont show it here if sidebyside: # Draw each match side by side the query if viz_name_score: cm.show_single_namematch(qreq_, ibs.get_annot_nids(aid), **_kwshow) else: _kwshow['draw_border'] = False _kwshow['draw_lbl'] = False _kwshow['notitle'] = True _kwshow['vert'] = False cm.show_single_annotmatch(qreq_, aid, **_kwshow) #viz_matches.show_matches(ibs, cm, aid, qreq_=qreq_, **_kwshow) else: # Draw each match by themselves data_config2_ = None if qreq_ is None else qreq_.get_external_data_config2() #_kwshow['draw_border'] = kwargs.get('draw_border', True) #_kwshow['notitle'] = ut.get_argflag(('--no-title', '--notitle')) viz_chip.show_chip(ibs, aid, annote=False, notitle=True, data_config2_=data_config2_, **_kwshow) if DEBUG_SHOW_QRES: print('[show_qres()] Plotting Chips %s:' % vh.get_aidstrs(aid_list)) if aid_list is None: return # Do lazy load before show #data_config2_ = None if qreq_ is None else qreq_.get_external_data_config2() tblhack = getattr(qreq_, 'tablename', None) # HACK FOR HUMPBACKS # (Also in viz_matches) if tblhack == 'vsone' or (qreq_ is not None and not qreq_._isnewreq): # precompute pass #ibs.get_annot_chips(aid_list, config2_=data_config2_, ensure=True) #ibs.get_annot_kpts(aid_list, config2_=data_config2_, ensure=True) for ox, aid in enumerate(aid_list): plotx = ox + plotx_shift + 1 pnum = (rowcols[0], rowcols[1], plotx) oranks = np.where(ranked_aids == aid)[0] # This pair has no matches between them. if len(oranks) == 0: orank = -1 if aid is None: pt.imshow_null('Failed to find matches\nfor qaid=%r' % (cm.qaid), fnum=fnum, pnum=pnum, fontsize=18) else: _show_matches_fn(aid, orank, pnum) #if DEBUG_SHOW_QRES: # print('skipping pnum=%r' % (pnum,)) continue if DEBUG_SHOW_QRES: print('pnum=%r' % (pnum,)) orank = oranks[0] + 1 _show_matches_fn(aid, orank, pnum)
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/ibeis_cnn/ibeis_cnn/ingest_ibeis.py': ingest_ibeis.py : 827 | >>> ibeis.viz.viz_matches.show_matches2(ibs, aid1, aid2, fm=None, kpts1=kpts1, kpts2=kpts2) ---------------------- Found 4 line(s) in '/home/joncrall/code/ibeis/ibeis/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 ibeis.viz.viz_matches --exec-show_matches2 --show viz_matches.py : 431 | python -m ibeis --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/ibeis/ibeis/viz/interact/interact_matches.py': interact_matches.py : 372 | tup = viz.viz_matches.show_matches2(ibs, self.qaid, self.daid, ---------------------- Found 1 line(s) in '/home/joncrall/code/ibeis/ibeis/algo/hots/vsone_pipeline.py': vsone_pipeline.py : 1339 | viz_matches.show_matches2(ibs, qaid, daid, fm=fm, fs=fs, fm_norm=fm_norm, ori=True, ---------------------- Found 2 line(s) in '/home/joncrall/code/ibeis/ibeis/algo/hots/chip_match.py': chip_match.py : 204 | viz_matches.show_matches2(qreq_.ibs, cm.qaid, daid, qreq_=qreq_, chip_match.py : 219 | ibeis.viz.viz_matches.show_matches2 ---------------------- Found 1 line(s) in '/home/joncrall/code/ibeis/ibeis/algo/hots/scoring.py': scoring.py : 562 | viz.viz_matches.show_matches2(qreq_.ibs, qaid, daid, fm, fs, CommandLine: python -m ibeis.viz.viz_matches --exec-show_matches2 --show python -m ibeis --tf ChipMatch.ishow_single_annotmatch show_matches2 --show Example: >>> # DISABLE_DOCTEST >>> from ibeis.algo.hots.chip_match import * # NOQA >>> import ibeis >>> cm, qreq_ = ibeis.testdata_cm(defaultdb='PZ_MTEST', default_qaids=[18]) >>> cm.score_nsum(qreq_) >>> daid = cm.get_top_aids()[0] >>> cm.show_single_annotmatch(qreq_, daid) >>> ut.show_if_requested() """ if qreq_ is None: print('[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]') print('') 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 annotate_matches2(ibs, aid1, aid2, fm, fs, offset1=(0, 0), offset2=(0, 0), xywh2=None, # (0, 0, 0, 0), xywh1=None, # (0, 0, 0, 0), qreq_=None, **kwargs): """ TODO: use this as the main function. """ if True: aid_list = [aid1, aid2] bbox_list = [xywh1, xywh2] offset_list = [offset1, offset2] name_fm_list = [fm] name_fs_list = [fs] return annotate_matches3(ibs, aid_list, bbox_list, offset_list, name_fm_list, name_fs_list, qreq_=qreq_, **kwargs) else: # TODO: make sure all of this functionality is incorporated into annotate_matches3 in_image = kwargs.get('in_image', False) show_query = kwargs.get('show_query', True) draw_border = kwargs.get('draw_border', True) draw_lbl = kwargs.get('draw_lbl', True) notitle = kwargs.get('notitle', False) truth = ibs.get_match_truth(aid1, aid2) truth_color = vh.get_truth_color(truth) # Build title title = vh.get_query_text(ibs, None, aid2, truth, qaid=aid1, **kwargs) # Build xlbl ax = pt.gca() ph.set_plotdat(ax, 'viztype', 'matches') ph.set_plotdat(ax, 'qaid', aid1) ph.set_plotdat(ax, 'aid1', aid1) ph.set_plotdat(ax, 'aid2', aid2) if draw_lbl: name1, name2 = ibs.get_annot_names([aid1, aid2]) nid1, nid2 = ibs.get_annot_name_rowids([aid1, aid2], distinguish_unknowns=False) #lbl1 = repr(name1) + ' : ' + 'q' + vh.get_aidstrs(aid1) #lbl2 = repr(name2) + ' : ' + vh.get_aidstrs(aid2) lbl1_list = [] lbl2_list = [] if kwargs.get('show_aid', True): lbl1_list.append('q' + vh.get_aidstrs(aid1)) lbl2_list.append(vh.get_aidstrs(aid2)) if kwargs.get('show_name', True): lbl1_list.append(repr((name1))) lbl2_list.append(repr((name2))) if kwargs.get('show_nid', True): lbl1_list.append(vh.get_nidstrs(nid1)) lbl2_list.append(vh.get_nidstrs(nid2)) lbl1 = ' : '.join(lbl1_list) lbl2 = ' : '.join(lbl2_list) else: lbl1, lbl2 = None, None if vh.NO_LBL_OVERRIDE: title = '' if not notitle: pt.set_title(title, ax) # Plot annotations over images if in_image: bbox1, bbox2 = vh.get_bboxes(ibs, [aid1, aid2], [offset1, offset2]) theta1, theta2 = ibs.get_annot_thetas([aid1, aid2]) # HACK! if show_query: pt.draw_bbox(bbox1, bbox_color=pt.ORANGE, lbl=lbl1, theta=theta1) bbox_color2 = truth_color if draw_border else pt.ORANGE pt.draw_bbox(bbox2, bbox_color=bbox_color2, lbl=lbl2, theta=theta2) else: xy, w, h = pt.get_axis_xy_width_height(ax) bbox2 = (xy[0], xy[1], w, h) theta2 = 0 if xywh2 is None: #xywh2 = (xy[0], xy[1], w, h) # weird when sidebyside is off y seems to be inverted xywh2 = (0, 0, w, h) if not show_query and xywh1 is None: data_config2 = (None if qreq_ is None else qreq_.get_external_data_config2()) # FIXME, pass data in kpts2 = ibs.get_annot_kpts([aid2], config2_=data_config2)[0] #pt.draw_kpts2(kpts2.take(fm.T[1], axis=0)) # Draw any selected matches #sm_kw = dict(rect=True, colors=pt.BLUE) pt.plot_fmatch(None, xywh2, None, kpts2, fm, fs=fs, **kwargs) if draw_border: pt.draw_border(ax, truth_color, 4, offset=offset2) if draw_lbl: # Custom user lbl for chips 1 and 2 if show_query: (x1, y1, w1, h1) = xywh1 pt.absolute_lbl(x1 + w1, y1, lbl1) (x2, y2, w2, h2) = xywh2 pt.absolute_lbl(x2 + w2, y2, lbl2) if True: # No matches draw a red box if fm is None or len(fm) == 0: if draw_border: pass
def annotate_matches3(ibs, aid_list, bbox_list, offset_list, name_fm_list, name_fs_list, qreq_=None, **kwargs): """ TODO: use this as the main function. """ # TODO Use this function when you clean show_matches in_image = kwargs.get('in_image', False) #show_query = kwargs.get('show_query', True) draw_border = kwargs.get('draw_border', True) draw_lbl = kwargs.get('draw_lbl', True) notitle = kwargs.get('notitle', False) # List of annotation scores for each annot in the name #printDBG('[viz] annotate_matches3()') #truth = ibs.get_match_truth(aid1, aid2) #name_equality = ( # np.array(ibs.get_annot_nids(aid_list[1:])) == ibs.get_annot_nids(aid_list[0]) #).tolist() #truth = 1 if all(name_equality) else (2 if any(name_equality) else 0) #truth_color = vh.get_truth_color(truth) ## Build title #score = kwargs.pop('score', None) #rawscore = kwargs.pop('rawscore', None) #aid2_raw_rank = kwargs.pop('aid2_raw_rank', None) #print(kwargs) #title = vh.get_query_text(ibs, None, aid2, truth, qaid=aid1, **kwargs) # Build xlbl ax = pt.gca() ph.set_plotdat(ax, 'viztype', 'multi_match') ph.set_plotdat(ax, 'qaid', aid_list[0]) ph.set_plotdat(ax, 'num_matches', len(aid_list) - 1) ph.set_plotdat(ax, 'aid_list', aid_list[1:]) for count, aid in enumerate(aid_list, start=1): ph.set_plotdat(ax, 'aid%d' % (count,), aid) #name_equality = (ibs.get_annot_nids(aid_list[0]) == # np.array(ibs.get_annot_nids(aid_list[1:]))) #truth = 1 if np.all(name_equality) else (2 if np.any(name_equality) else 0) truth = get_multitruth(ibs, aid_list) if any(ibs.is_aid_unknown(aid_list[1:])) or ibs.is_aid_unknown(aid_list[0]): truth = ibs.const.TRUTH_UNKNOWN truth_color = vh.get_truth_color(truth) name_annot_scores = kwargs.get('name_annot_scores', None) if len(aid_list) == 2: # HACK; generalize to multple annots title = vh.get_query_text(ibs, None, aid_list[1], truth, qaid=aid_list[0], **kwargs) if not notitle: pt.set_title(title, ax) if draw_lbl: # Build labels nid_list = ibs.get_annot_nids(aid_list, distinguish_unknowns=False) name_list = ibs.get_annot_names(aid_list) lbls_list = [[] for _ in range(len(aid_list))] if kwargs.get('show_name', False): for count, (lbls, name) in enumerate(zip(lbls_list, name_list)): lbls.append(ut.repr2((name))) if kwargs.get('show_nid', True): for count, (lbls, nid) in enumerate(zip(lbls_list, nid_list)): # only label the first two images with nids LABEL_ALL_NIDS = False if count <= 1 or LABEL_ALL_NIDS: #lbls.append(vh.get_nidstrs(nid)) lbls.append(('q' if count == 0 else '') + vh.get_nidstrs(nid)) if kwargs.get('show_aid', True): for count, (lbls, aid) in enumerate(zip(lbls_list, aid_list)): lbls.append(('q' if count == 0 else '') + vh.get_aidstrs(aid)) if (kwargs.get('show_annot_score', True) and name_annot_scores is not None): max_digits = kwargs.get('score_precision', None) for (lbls, score) in zip(lbls_list[1:], name_annot_scores): lbls.append(ut.num_fmt(score, max_digits=max_digits)) lbl_list = [' : '.join(lbls) for lbls in lbls_list] else: lbl_list = [None] * len(aid_list) #pt.set_title(title, ax) # Plot annotations over images if in_image: in_image_bbox_list = vh.get_bboxes(ibs, aid_list, offset_list) in_image_theta_list = ibs.get_annot_thetas(aid_list) # HACK! #if show_query: # pt.draw_bbox(bbox1, bbox_color=pt.ORANGE, lbl=lbl1, theta=theta1) bbox_color = pt.ORANGE bbox_color = truth_color if draw_border else pt.ORANGE for bbox, theta, lbl in zip(in_image_bbox_list, in_image_theta_list, lbl_list): pt.draw_bbox(bbox, bbox_color=bbox_color, lbl=lbl, theta=theta) pass else: xy, w, h = pt.get_axis_xy_width_height(ax) #theta2 = 0 #if xywh2 is None: # #xywh2 = (xy[0], xy[1], w, h) # # weird when sidebyside is off y seems to be inverted # xywh2 = (0, 0, w, h) #if not show_query and xywh1 is None: # data_config2 = None if qreq_ is None else # qreq_.get_external_data_config2() # kpts2 = ibs.get_annot_kpts([aid2], config2_=data_config2)[0] # #pt.draw_kpts2(kpts2.take(fm.T[1], axis=0)) # # Draw any selected matches # #sm_kw = dict(rect=True, colors=pt.BLUE) # pt.plot_fmatch(None, xywh2, None, kpts2, fm, fs=fs, **kwargs) #if draw_border: # pt.draw_border(ax, truth_color, 4, offset=offset2) if draw_border: pt.draw_border(ax, color=truth_color, lw=4) if draw_lbl: # Custom user lbl for chips 1 and 2 #if show_query: # (x1, y1, w1, h1) = xywh1 # pt.absolute_lbl(x1 + w1, y1, lbl1) for bbox, lbl in zip(bbox_list, lbl_list): (x, y, w, h) = bbox pt.absolute_lbl(x + w, y, lbl) # No matches draw a red box if True: no_matches = name_fm_list is None or all([True if fm is None else len(fm) == 0 for fm in name_fm_list]) if no_matches: xy, w, h = pt.get_axis_xy_width_height(ax) #axes_bbox = (xy[0], xy[1], w, h) if draw_border: pass