def chipmatch_view(self, fnum=None, pnum=(1, 1, 1), verbose=None, **kwargs_): """ just visualizes the matches using some type of lines """ import plottool as pt from 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) 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.dict_str(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 chipmatch_view(self, fnum=None, pnum=(1, 1, 1), verbose=None, **kwargs_): """ just visualizes the matches using some type of lines """ import plottool as pt from 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, ) 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.dict_str(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_hud(self): """ Creates heads up display """ # Button positioners hl_slot, hr_slot = pt.make_bbox_positioners(y=.02, w=.16, h=3 * ut.PHI_B ** 4, xpad=.05, startx=0, stopx=1) select_none_text = 'None of these' if self.suggest_aids is not None and len(self.suggest_aids) == 0: select_none_text += '\n(SUGGESTED BY IBEIS)' none_tup = self.append_button(select_none_text, callback=partial(self.select_none), rect=hl_slot(0)) #Draw boarder around the None of these button none_button_axis = none_tup[1] if self.other_checkbox_states['none']: pt.draw_border(none_button_axis, color=(0, 1, 0), lw=4, adjust=False) else: pt.draw_border(none_button_axis, color=(.7, .7, .7), lw=4, adjust=False) select_junk_text = 'Junk Query Image' junk_tup = self.append_button(select_junk_text, callback=partial(self.select_junk), rect=hl_slot(1)) #Draw boarder around the None of these button junk_button_axis = junk_tup[1] if self.other_checkbox_states['junk']: pt.draw_border(junk_button_axis, color=(0, 1, 0), lw=4, adjust=False) else: pt.draw_border(junk_button_axis, color=(.7, .7, .7), lw=4, adjust=False) #Add other HUD buttons self.append_button('Quit', callback=partial(self.quit), rect=hr_slot(0)) self.append_button('Confirm Selection', callback=partial(self.confirm), rect=hr_slot(1)) if self.progress_current is not None and self.progress_total is not None: self.progress_string = str(self.progress_current) + '/' + str(self.progress_total) else: self.progress_string = '' figtitle_fmt = ''' Animal Identification {progress_string} ''' figtitle = figtitle_fmt.format(**self.__dict__) # sexy: using obj dict as fmtkw pt.set_figtitle(figtitle)
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_chip(self, aid, nRows, nCols, px, fulldraw=True, **kwargs): """ Plots an individual chip in a subaxis """ ibs = self.ibs if aid in [self.aid1, self.aid2]: # Bold color for the matching chips lw = 5 text_color = np.array((135, 206, 235, 255)) / 255.0 else: lw = 2 text_color = None pnum = (nRows, nCols, px) if not fulldraw: # not doing full draw so we have to clear any axes # that are here already manually ax = self.fig.add_subplot(*pnum) self.clear_parent_axes(ax) #ut.embed() #print(subax) viz_chip_kw = { 'fnum': self.fnum, 'pnum': pnum, 'nokpts': True, 'show_name': True, 'show_gname': False, 'show_aidstr': True, 'notitle': True, 'show_num_gt': False, 'text_color': text_color, } if False and ut.is_developer(): enable_chip_title_prefix = True viz_chip_kw.update( { 'enable_chip_title_prefix': enable_chip_title_prefix, 'show_name': True, 'show_aidstr': True, 'show_yawtext': True, 'show_num_gt': True, 'show_quality_text': True, } ) viz_chip.show_chip(ibs, aid, **viz_chip_kw) ax = pt.gca() pt.draw_border(ax, color=kwargs.get('color'), lw=lw) if kwargs.get('make_buttons', True): #divider = pt.ensure_divider(ax) butkw = { #'divider': divider, 'ax': ax, 'size': '13%' #'size': '15%' } # Chip matching/naming options nid = ibs.get_annot_name_rowids(aid) annotation_unknown = ibs.is_nid_unknown([nid])[0] if not annotation_unknown: # remove name callback = functools.partial(self.unname_annotation, aid) self.append_button('remove name (' + ibs.get_name_texts(nid) + ')', callback=callback, **butkw) else: # new name callback = functools.partial(self.mark_annotation_as_new_name, aid) self.append_button('mark as new name', callback=callback, **butkw) if nid != self.nid2 and not ibs.is_nid_unknown([self.nid2])[0] and not self.is_split_case: # match to nid2 callback = functools.partial(self.rename_annotation, aid, self.nid2) text = 'match to name2: ' + ibs.get_name_texts(self.nid2) self.append_button(text, callback=callback, **butkw) if nid != self.nid1 and not ibs.is_nid_unknown([self.nid1])[0]: # match to nid1 callback = functools.partial(self.rename_annotation, aid, self.nid1) text = 'match to name1: ' + ibs.get_name_texts(self.nid1) self.append_button(text, callback=callback, **butkw) other_nid_list = self.get_other_nids() for other_nid in other_nid_list: if other_nid == nid: continue # rename nid2 callback = functools.partial(self.rename_annotation, aid, other_nid) text = 'match to: ' + ibs.get_name_texts(other_nid) self.append_button(text, callback=callback, **butkw) return ax
def plot_chip(self, aid, nRows, nCols, px, fulldraw=True, **kwargs): """ Plots an individual chip in a subaxis """ ibs = self.ibs if aid in [self.aid1, self.aid2]: # Bold color for the matching chips lw = 5 text_color = np.array((135, 206, 235, 255)) / 255.0 else: lw = 2 text_color = None pnum = (nRows, nCols, px) if not fulldraw: # not doing full draw so we have to clear any axes # that are here already manually ax = self.fig.add_subplot(*pnum) self.clear_parent_axes(ax) #ut.embed() #print(subax) viz_chip_kw = { 'fnum': self.fnum, 'pnum': pnum, 'nokpts': True, 'show_name': True, 'show_gname': False, 'show_aidstr': True, 'notitle': True, 'show_num_gt': False, 'text_color': text_color, } if False and ut.is_developer(): enable_chip_title_prefix = True viz_chip_kw.update({ 'enable_chip_title_prefix': enable_chip_title_prefix, 'show_name': True, 'show_aidstr': True, 'show_viewcode': True, 'show_num_gt': True, 'show_quality_text': True, }) viz_chip.show_chip(ibs, aid, **viz_chip_kw) ax = pt.gca() pt.draw_border(ax, color=kwargs.get('color'), lw=lw) if kwargs.get('make_buttons', True): #divider = pt.ensure_divider(ax) butkw = { #'divider': divider, 'ax': ax, 'size': '13%' #'size': '15%' } # Chip matching/naming options nid = ibs.get_annot_name_rowids(aid) annotation_unknown = ibs.is_nid_unknown([nid])[0] if not annotation_unknown: # remove name callback = functools.partial(self.unname_annotation, aid) self.append_button('remove name (' + ibs.get_name_texts(nid) + ')', callback=callback, **butkw) else: # new name callback = functools.partial(self.mark_annotation_as_new_name, aid) self.append_button('mark as new name', callback=callback, **butkw) if nid != self.nid2 and not ibs.is_nid_unknown( [self.nid2])[0] and not self.is_split_case: # match to nid2 callback = functools.partial(self.rename_annotation, aid, self.nid2) text = 'match to name2: ' + ibs.get_name_texts(self.nid2) self.append_button(text, callback=callback, **butkw) if nid != self.nid1 and not ibs.is_nid_unknown([self.nid1])[0]: # match to nid1 callback = functools.partial(self.rename_annotation, aid, self.nid1) text = 'match to name1: ' + ibs.get_name_texts(self.nid1) self.append_button(text, callback=callback, **butkw) other_nid_list = self.get_other_nids() for other_nid in other_nid_list: if other_nid == nid: continue # rename nid2 callback = functools.partial(self.rename_annotation, aid, other_nid) text = 'match to: ' + ibs.get_name_texts(other_nid) self.append_button(text, callback=callback, **butkw) return ax
def show_hud(self): """ Creates heads up display """ # Button positioners hl_slot, hr_slot = pt.make_bbox_positioners(y=.02, w=.16, h=3 * ut.PHI_B**4, xpad=.05, startx=0, stopx=1) select_none_text = 'None of these' if self.suggest_aids is not None and len(self.suggest_aids) == 0: select_none_text += '\n(SUGGESTED BY IBEIS)' none_tup = self.append_button(select_none_text, callback=partial(self.select_none), rect=hl_slot(0)) #Draw boarder around the None of these button none_button_axis = none_tup[1] if self.other_checkbox_states['none']: pt.draw_border(none_button_axis, color=(0, 1, 0), lw=4, adjust=False) else: pt.draw_border(none_button_axis, color=(.7, .7, .7), lw=4, adjust=False) select_junk_text = 'Junk Query Image' junk_tup = self.append_button(select_junk_text, callback=partial(self.select_junk), rect=hl_slot(1)) #Draw boarder around the None of these button junk_button_axis = junk_tup[1] if self.other_checkbox_states['junk']: pt.draw_border(junk_button_axis, color=(0, 1, 0), lw=4, adjust=False) else: pt.draw_border(junk_button_axis, color=(.7, .7, .7), lw=4, adjust=False) #Add other HUD buttons self.append_button('Quit', callback=partial(self.quit), rect=hr_slot(0)) self.append_button('Confirm Selection', callback=partial(self.confirm), rect=hr_slot(1)) if self.progress_current is not None and self.progress_total is not None: self.progress_string = str(self.progress_current) + '/' + str( self.progress_total) else: self.progress_string = '' figtitle_fmt = ''' Animal Identification {progress_string} ''' figtitle = figtitle_fmt.format( **self.__dict__) # sexy: using obj dict as fmtkw pt.set_figtitle(figtitle)
def plot_chip(self, aid, nRows, nCols, px, **kwargs): """ Plots an individual chip in a subaxis """ ibs = self.ibs enable_chip_title_prefix = ut.is_developer() #enable_chip_title_prefix = False if aid in self.comp_aids: score = self.cm.get_annot_scores([aid])[0] rawscore = self.cm.get_annot_scores([aid])[0] title_suf = kwargs.get('title_suffix', '') if score != rawscore: if score is None: title_suf += '\n score=____' else: title_suf += '\n score=%0.2f' % score title_suf += '\n rawscore=%0.2f' % rawscore else: title_suf = kwargs.get('title_suffix', '') if enable_chip_title_prefix: title_suf = '\n' + title_suf #nid = ibs.get_annot_name_rowids(aid) viz_chip_kw = { 'fnum': self.fnum, 'pnum': (nRows, nCols, px), 'nokpts': True, 'show_gname': False, 'show_exemplar': False, 'show_num_gt': False, 'show_gname': False, 'title_suffix': title_suf, # 'text_color': kwargs.get('color'), ### #'show_name': False, #'show_aidstr': False, 'enable_chip_title_prefix': enable_chip_title_prefix, 'show_name': True, 'show_aidstr': True, 'show_yawtext': True, 'show_quality_text': True, } viz_chip.show_chip(ibs, aid, **viz_chip_kw) ax = pt.gca() if kwargs.get('make_buttons', True): divider = pt.ensure_divider(ax) butkw = {'divider': divider, 'size': '13%'} self.aid2_ax = {} self.aid2_border = {} if aid in self.comp_aids: callback = partial(self.select, aid) self.append_button('Select This Animal', callback=callback, **butkw) #Hack to toggle colors if aid in self.aid_checkbox_states: #If we are selecting it, then make it green, otherwise change it back to grey if self.aid_checkbox_states[aid]: border = pt.draw_border(ax, color=(0, 1, 0), lw=4) else: border = pt.draw_border(ax, color=(.7, .7, .7), lw=4) self.aid2_border[aid] = border else: self.aid_checkbox_states[aid] = False self.append_button('Examine', callback=partial(self.examine, aid), **butkw)
def plot_chip(self, aid, nRows, nCols, px, **kwargs): """ Plots an individual chip in a subaxis """ ibs = self.ibs enable_chip_title_prefix = ut.is_developer() #enable_chip_title_prefix = False if aid in self.comp_aids: score = self.cm.get_annot_scores([aid])[0] rawscore = self.cm.get_annot_scores([aid])[0] title_suf = kwargs.get('title_suffix', '') if score != rawscore: if score is None: title_suf += '\n score=____' else: title_suf += '\n score=%0.2f' % score title_suf += '\n rawscore=%0.2f' % rawscore else: title_suf = kwargs.get('title_suffix', '') if enable_chip_title_prefix: title_suf = '\n' + title_suf #nid = ibs.get_annot_name_rowids(aid) viz_chip_kw = { 'fnum': self.fnum, 'pnum': (nRows, nCols, px), 'nokpts': True, 'show_gname': False, 'show_exemplar': False, 'show_num_gt': False, 'show_gname': False, 'title_suffix': title_suf, # 'text_color': kwargs.get('color'), ### #'show_name': False, #'show_aidstr': False, 'enable_chip_title_prefix': enable_chip_title_prefix, 'show_name': True, 'show_aidstr': True, 'show_yawtext': True, 'show_quality_text': True, } viz_chip.show_chip(ibs, aid, **viz_chip_kw) ax = pt.gca() if kwargs.get('make_buttons', True): divider = pt.ensure_divider(ax) butkw = { 'divider': divider, 'size': '13%' } self.aid2_ax = {} self.aid2_border = {} if aid in self.comp_aids: callback = partial(self.select, aid) self.append_button('Select This Animal', callback=callback, **butkw) #Hack to toggle colors if aid in self.aid_checkbox_states: #If we are selecting it, then make it green, otherwise change it back to grey if self.aid_checkbox_states[aid]: border = pt.draw_border(ax, color=(0, 1, 0), lw=4) else: border = pt.draw_border(ax, color=(.7, .7, .7), lw=4) self.aid2_border[aid] = border else: self.aid_checkbox_states[aid] = False self.append_button('Examine', callback=partial(self.examine, aid), **butkw)
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