def vary_two_cfg(hs, qcx, cx, query_cfg, vary_cfg, fnum=1): if len(vary_cfg) > 2: raise Exception('can only vary at most two cfgeters') print('[dev] vary_two_cfg: q' + hs.vs_str(qcx, cx)) cfg_keys = vary_cfg.keys() cfg_vals = vary_cfg.values() cfg1_name = cfg_keys[0] cfg2_name = cfg_keys[1] cfg1_steps = cfg_vals[0] cfg2_steps = cfg_vals[1] nRows = len(cfg1_steps) nCols = len(cfg2_steps) print('[dev] Varying configs: nRows=%r, nCols=%r' % (nRows, nCols)) print('[dev] %r = %r ' % (cfg1_name, cfg1_steps)) print('[dev] %r = %r ' % (cfg2_name, cfg2_steps)) ylabel_args = dict(rotation='horizontal', verticalalignment='bottom', horizontalalignment='right', fontproperties=df2.FONTS.medbold) xlabel_args = dict(fontproperties=df2.FONTS.medbold) #ax = df2.gca() # Vary cfg1 #df2..gcf().clf() print_lock_ = helpers.ModulePrintLock(mc3, df2) assign_alg = query_cfg.agg_cfg.query_type vert = not hs.args.horiz plt_match_args = dict(fnum=fnum, show_gname=False, showTF=False, vert=vert) for rowx, cfg1_value in enumerate(cfg1_steps): query_cfg.update_cfg(**{cfg1_name: cfg1_value}) y_title = cfg1_name + '=' + helpers.format(cfg1_value, 3) # Vary cfg2 for colx, cfg2_value in enumerate(cfg2_steps): query_cfg.update_cfg(**{cfg2_name: cfg2_value}) pnum = (nRows, nCols, rowx * nCols + colx + 1) # HACK #print(pnum) #print(query_cfg) # query only the chips of interest (groundtruth) when doing vsone if assign_alg == 'vsone': res = hs.query_groundtruth(qcx, query_cfg) # query the entire database in vsmany (just as fast as vgroundtruth) elif assign_alg == 'vsmany': res = hs.query(qcx, query_cfg) res.plot_single_match(hs, cx, pnum=pnum, **plt_match_args) x_title = cfg2_name + '=' + helpers.format(cfg2_value, 3) # helpers.commas(cfg2_value, 3) ax = df2.gca() if rowx == len(cfg1_steps) - 1: ax.set_xlabel(x_title, **xlabel_args) if colx == 0: ax.set_ylabel(y_title, **ylabel_args) del print_lock_ vary_title = '%s vary %s and %s' % (assign_alg, cfg1_name, cfg2_name) figtitle = '%s %s %s' % (vary_title, hs.vs_str(qcx, cx), str(hs.cx2_property(qcx, 'Notes'))) subtitle = mc3.simplify_test_uid(query_cfg.get_uid()) df2.set_figtitle(figtitle, subtitle) df2.adjust_subplots_xylabels() fnum += 1 viz.save_if_requested(hs, vary_title) return fnum
def viz_chipgraph(hs, graph, fnum=1, with_images=False): # Adapated from # https://gist.github.com/shobhit/3236373 print('[encounter] drawing chip graph') df2.figure(fnum=fnum, pnum=(1, 1, 1)) ax = df2.gca() #pos = netx.spring_layout(graph) pos = netx.graphviz_layout(graph) netx.draw(graph, pos=pos, ax=ax) if with_images: cx_list = graph.nodes() pos_list = [pos[cx] for cx in cx_list] thumb_list = hs.get_thumb(cx_list, 16, 16) draw_images_at_positions(thumb_list, pos_list)
def draw_images_at_positions(img_list, pos_list): print('[encounter] drawing %d images' % len(img_list)) # Thumb stack ax = df2.gca() fig = df2.gcf() trans = ax.transData.transform trans2 = fig.transFigure.inverted().transform mark_progress, end_progress = util.progress_func(len(pos_list), lbl='drawing img') for ix, ((x, y), img) in enumerate(izip(pos_list, img_list)): mark_progress(ix) xx, yy = trans((x, y)) # figure coordinates xa, ya = trans2((xx, yy)) # axes coordinates # width, height = img.shape[0:2] tlx = xa - (width / 2.0) tly = ya - (height / 2.0) img_bbox = [tlx, tly, width, height] # Make new axis for the image img_ax = df2.plt.axes(img_bbox) img_ax.imshow(img) img_ax.set_aspect('equal') img_ax.axis('off') end_progress()
def vary_two_cfg(hs, qcx, cx, query_cfg, vary_cfg, fnum=1): if len(vary_cfg) > 2: raise Exception('can only vary at most two cfgeters') print('[dev] vary_two_cfg: q' + hs.vs_str(qcx, cx)) cfg_keys = vary_cfg.keys() cfg_vals = vary_cfg.values() cfg1_name = cfg_keys[0] cfg2_name = cfg_keys[1] cfg1_steps = cfg_vals[0] cfg2_steps = cfg_vals[1] nRows = len(cfg1_steps) nCols = len(cfg2_steps) print('[dev] Varying configs: nRows=%r, nCols=%r' % (nRows, nCols)) print('[dev] %r = %r ' % (cfg1_name, cfg1_steps)) print('[dev] %r = %r ' % (cfg2_name, cfg2_steps)) ylabel_args = dict(rotation='horizontal', verticalalignment='bottom', horizontalalignment='right', fontproperties=df2.FONTS.medbold) xlabel_args = dict(fontproperties=df2.FONTS.medbold) #ax = df2.gca() # Vary cfg1 #df2..gcf().clf() print_lock_ = helpers.ModulePrintLock(mc3, df2) assign_alg = query_cfg.agg_cfg.query_type vert = not hs.args.horiz plt_match_args = dict(fnum=fnum, show_gname=False, showTF=False, vert=vert) for rowx, cfg1_value in enumerate(cfg1_steps): query_cfg.update_cfg(**{cfg1_name: cfg1_value}) y_title = cfg1_name + '=' + helpers.format(cfg1_value, 3) # Vary cfg2 for colx, cfg2_value in enumerate(cfg2_steps): query_cfg.update_cfg(**{cfg2_name: cfg2_value}) pnum = (nRows, nCols, rowx * nCols + colx + 1) # HACK #print(pnum) #print(query_cfg) # query only the chips of interest (groundtruth) when doing vsone if assign_alg == 'vsone': res = hs.query_groundtruth(qcx, query_cfg) # query the entire database in vsmany (just as fast as vgroundtruth) elif assign_alg == 'vsmany': res = hs.query(qcx, query_cfg) res.plot_single_match(hs, cx, pnum=pnum, **plt_match_args) x_title = cfg2_name + '=' + helpers.format( cfg2_value, 3) # helpers.commas(cfg2_value, 3) ax = df2.gca() if rowx == len(cfg1_steps) - 1: ax.set_xlabel(x_title, **xlabel_args) if colx == 0: ax.set_ylabel(y_title, **ylabel_args) del print_lock_ vary_title = '%s vary %s and %s' % (assign_alg, cfg1_name, cfg2_name) figtitle = '%s %s %s' % (vary_title, hs.vs_str( qcx, cx), str(hs.cx2_property(qcx, 'Notes'))) subtitle = mc3.simplify_test_uid(query_cfg.get_uid()) df2.set_figtitle(figtitle, subtitle) df2.adjust_subplots_xylabels() fnum += 1 viz.save_if_requested(hs, vary_title) return fnum
def annotate_chipres(hs, res, cx, showTF=True, showScore=True, title_pref='', title_suff='', show_2nd_gname=True, show_2nd_name=True, show_1st=True, time_appart=True, in_image=False, offset1=(0, 0), offset2=(0, 0), show_query=True, xywh2=None, **kwargs): printDBG('[viz] annotate_chipres()') #print('Did not expect args: %r' % (kwargs.keys(),)) qcx = res.qcx score = res.cx2_score[cx] matched_kpts= np.float32(len(res.cx2_fs[cx])) print('matched_kpts=%d'%matched_kpts) # TODO Use this function when you clean show_chipres (truestr, falsestr, nonamestr) = ('TRUE', 'FALSE', '???') is_true, is_unknown = hs.is_true_match(qcx, cx) isgt_str = nonamestr if is_unknown else (truestr if is_true else falsestr) match_color = {nonamestr: df2.UNKNOWN_PURP, truestr: df2.TRUE_GREEN, falsestr: df2.FALSE_RED}[isgt_str] # Build title title = '*%s*' % isgt_str if showTF else '' if showScore: score_str = (' score=' + helpers.num_fmt(score))% (score) score_str +=(' matched_kpts='+ helpers.num_fmt(matched_kpts))% (matched_kpts) title += score_str title = title_pref + str(title) + title_suff # Build xlabel xlabel_ = [] ax = df2.gca() ax._hs_viewtype = 'chipres' ax._hs_qcx = qcx ax._hs_cx = cx if 'show_1st': xlabel_.append('top_gname=%r'%hs.cx2_gname(qcx)) xlabel_.append('top_name=%r'%hs.cx2_name(qcx)) if 'show_2nd_gname': xlabel_.append('\n below_gname=%r' % hs.cx2_gname(cx)) if 'show_2nd_name': xlabel_.append('below_name=%r' % hs.cx2_name(cx)) if 'time_appart': xlabel_.append('\n' + hs.get_timedelta_str(qcx, cx)) xlabel = ', '.join(xlabel_) if NO_LABEL_OVERRIDE: title = '' xlabel = '' df2.set_title(title, ax) df2.set_xlabel(xlabel, ax) if in_image: roi1 = hs.cx2_roi(qcx) + np.array(list(offset1) + [0, 0]) roi2 = hs.cx2_roi(cx) + np.array(list(offset2) + [0, 0]) theta1 = hs.cx2_theta(qcx) theta2 = hs.cx2_theta(cx) # HACK! lbl1 = 'q' + hs.cidstr(qcx) lbl2 = hs.cidstr(cx) if show_query: df2.draw_roi(roi1, bbox_color=df2.ORANGE, label=lbl1, theta=theta1) df2.draw_roi(roi2, bbox_color=match_color, label=lbl2, theta=theta2) # No matches draw a red box if len(res.cx2_fm[cx]) == 0: df2.draw_boxedX(roi2, theta=theta2) else: if xywh2 is None: xy, w, h = df2._axis_xy_width_height(ax) xywh2 = (xy[0], xy[1], w, h) df2.draw_border(ax, match_color, 4, offset=offset2) # No matches draw a red box if len(res.cx2_fm[cx]) == 0: df2.draw_boxedX(xywh2)