Esempio n. 1
0
def get_data_annot_pair_info(ibs, aid_list, qreq_, draw_fmatches,
                             scale_down=False, kpts2_list=None):
    data_config2_ = (None if qreq_ is None else
                     qreq_.get_external_data_config2())
    #print('!!! data_config2_ = %r' % (data_config2_,))
    #print('!!! dqreq_ = %r' % (qreq_,))
    tblhack = getattr(qreq_, 'tablename', None)
    if (not tblhack or tblhack == 'BC_DTW') and getattr(qreq_, '_isnewreq', None):
        if hasattr(qreq_, 'get_fmatch_overlayed_chip') and draw_fmatches and draw_fmatches != 'hackoff':
            rchip2_list = qreq_.get_fmatch_overlayed_chip(aid_list, config=data_config2_)
            #rchip2_list = ibs.depc_annot.get_property('chips', aid_list, 'img', config=data_config2_)
            draw_fmatches = False
        else:
            rchip2_list = ibs.depc_annot.get_property('chips', aid_list, 'img', config=data_config2_)
            draw_fmatches = False
        #vh.get_chips(ibs, aid_list, config2_=data_config2_)
    else:
        rchip2_list = vh.get_chips(ibs, aid_list, config2_=data_config2_)
    if draw_fmatches:
        if kpts2_list is None:
            kpts2_list = vh.get_kpts(ibs, aid_list, config2_=data_config2_)
    else:
        kpts2_list = [None] * len(aid_list)
    if scale_down:
        pass
    return rchip2_list, kpts2_list
Esempio n. 2
0
def get_query_annot_pair_info(ibs, qaid, qreq_, draw_fmatches, kpts1=None):
    #print('!!! qqreq_ = %r' % (qreq_,))
    query_config2_ = (None
                      if qreq_ is None else qreq_.get_external_query_config2())
    tblhack = getattr(qreq_, 'tablename', None)
    #print('!!! query_config2_ = %r' % (query_config2_,))
    if (not tblhack or tblhack == 'BC_DTW') and getattr(
            qreq_, '_isnewreq', None):
        if hasattr(qreq_, 'get_fmatch_overlayed_chip'
                   ) and draw_fmatches and draw_fmatches != 'hackoff':
            rchip1 = qreq_.get_fmatch_overlayed_chip(qaid,
                                                     config=query_config2_)
            draw_fmatches = False
        else:
            rchip1 = ibs.depc_annot.get_property('chips',
                                                 qaid,
                                                 'img',
                                                 config=query_config2_)
            draw_fmatches = False
    else:
        rchip1 = vh.get_chips(ibs, [qaid], config2_=query_config2_)[0]
    if draw_fmatches:
        if kpts1 is None:
            kpts1 = vh.get_kpts(ibs, [qaid], config2_=query_config2_)[0]
    else:
        kpts1 = None
    return rchip1, kpts1
Esempio n. 3
0
def get_query_annot_pair_info(ibs,
                              qaid,
                              qreq_,
                              draw_fmatches,
                              kpts1=None,
                              as_fpath=False):
    #print('!!! qqreq_ = %r' % (qreq_,))
    query_config2_ = (None if qreq_ is None else qreq_.extern_query_config2)
    tblhack = getattr(qreq_, 'tablename', None)
    #print('!!! query_config2_ = %r' % (query_config2_,))
    if (not tblhack or tblhack.lower() in [
            'bc_dtw', 'oc_wdtw', 'curvrankdorsal', 'curvrankfluke'
    ]) and getattr(qreq_, '_isnewreq', None):
        if hasattr(qreq_, 'get_fmatch_overlayed_chip'
                   ) and draw_fmatches and draw_fmatches != 'hackoff':
            rchip1 = qreq_.get_fmatch_overlayed_chip(qaid,
                                                     config=query_config2_)
            draw_fmatches = False
        else:
            rchip1 = ibs.depc_annot.get_property('chips',
                                                 qaid,
                                                 'img',
                                                 config=query_config2_)
            draw_fmatches = False
    else:
        rchip1 = vh.get_chips(ibs, [qaid],
                              config2_=query_config2_,
                              as_fpath=as_fpath)[0]
    if draw_fmatches:
        if kpts1 is None:
            kpts1 = vh.get_kpts(ibs, [qaid], config2_=query_config2_)[0]
    else:
        kpts1 = None
    return rchip1, kpts1
Esempio n. 4
0
def get_query_annot_pair_info(ibs, qaid, qreq_, draw_fmatches, kpts1=None):
    #print('!!! qqreq_ = %r' % (qreq_,))
    query_config2_ = (None if qreq_ is None
                      else qreq_.get_external_query_config2())
    tblhack = getattr(qreq_, 'tablename', None)
    #print('!!! query_config2_ = %r' % (query_config2_,))
    if (not tblhack or tblhack == 'BC_DTW') and getattr(qreq_, '_isnewreq', None):
        if hasattr(qreq_, 'get_fmatch_overlayed_chip')  and draw_fmatches and draw_fmatches != 'hackoff':
            rchip1 = qreq_.get_fmatch_overlayed_chip(qaid, config=query_config2_)
            draw_fmatches = False
        else:
            rchip1 = ibs.depc_annot.get_property('chips', qaid, 'img', config=query_config2_)
            draw_fmatches = False
    else:
        rchip1 = vh.get_chips(ibs, [qaid], config2_=query_config2_)[0]
    if draw_fmatches:
        if kpts1 is None:
            kpts1 = vh.get_kpts(ibs, [qaid], config2_=query_config2_)[0]
    else:
        kpts1 = None
    return rchip1, kpts1
Esempio n. 5
0
def get_data_annot_pair_info(ibs,
                             aid_list,
                             qreq_,
                             draw_fmatches,
                             scale_down=False,
                             kpts2_list=None,
                             as_fpath=False):
    data_config2_ = (None if qreq_ is None else qreq_.extern_data_config2)
    #print('!!! data_config2_ = %r' % (data_config2_,))
    #print('!!! dqreq_ = %r' % (qreq_,))
    tblhack = getattr(qreq_, 'tablename', None)
    if (not tblhack or tblhack.lower() in [
            'bc_dtw', 'oc_wdtw', 'curvrankdorsal', 'curvrankfluke'
    ]) and getattr(qreq_, '_isnewreq', None):
        if hasattr(qreq_, 'get_fmatch_overlayed_chip'
                   ) and draw_fmatches and draw_fmatches != 'hackoff':
            rchip2_list = qreq_.get_fmatch_overlayed_chip(aid_list,
                                                          config=data_config2_)
            #rchip2_list = ibs.depc_annot.get_property('chips', aid_list, 'img', config=data_config2_)
            draw_fmatches = False
        else:
            rchip2_list = ibs.depc_annot.get_property('chips',
                                                      aid_list,
                                                      'img',
                                                      config=data_config2_)
            draw_fmatches = False
        #vh.get_chips(ibs, aid_list, config2_=data_config2_)
    else:
        rchip2_list = vh.get_chips(ibs,
                                   aid_list,
                                   config2_=data_config2_,
                                   as_fpath=as_fpath)
    if draw_fmatches:
        if kpts2_list is None:
            kpts2_list = vh.get_kpts(ibs, aid_list, config2_=data_config2_)
    else:
        kpts2_list = [None] * len(aid_list)
    if scale_down:
        pass
    return rchip2_list, kpts2_list
Esempio n. 6
0
def get_data_annot_pair_info(ibs,
                             aid_list,
                             qreq_,
                             draw_fmatches,
                             scale_down=False,
                             kpts2_list=None):
    data_config2_ = (None
                     if qreq_ is None else qreq_.get_external_data_config2())
    #print('!!! data_config2_ = %r' % (data_config2_,))
    #print('!!! dqreq_ = %r' % (qreq_,))
    tblhack = getattr(qreq_, 'tablename', None)
    if (not tblhack or tblhack == 'BC_DTW') and getattr(
            qreq_, '_isnewreq', None):
        if hasattr(qreq_, 'get_fmatch_overlayed_chip'
                   ) and draw_fmatches and draw_fmatches != 'hackoff':
            rchip2_list = qreq_.get_fmatch_overlayed_chip(aid_list,
                                                          config=data_config2_)
            #rchip2_list = ibs.depc_annot.get_property('chips', aid_list, 'img', config=data_config2_)
            draw_fmatches = False
        else:
            rchip2_list = ibs.depc_annot.get_property('chips',
                                                      aid_list,
                                                      'img',
                                                      config=data_config2_)
            draw_fmatches = False
        #vh.get_chips(ibs, aid_list, config2_=data_config2_)
    else:
        rchip2_list = vh.get_chips(ibs, aid_list, config2_=data_config2_)
    if draw_fmatches:
        if kpts2_list is None:
            kpts2_list = vh.get_kpts(ibs, aid_list, config2_=data_config2_)
    else:
        kpts2_list = [None] * len(aid_list)
    if scale_down:
        pass
    return rchip2_list, kpts2_list
Esempio n. 7
0
def show_chip(ibs,
              aid,
              in_image=False,
              annote=True,
              title_suffix='',
              weight_label=None,
              weights=None,
              config2_=None,
              **kwargs):
    r""" Driver function to show chips

    Args:
        ibs (ibeis.IBEISController):
        aid (int): annotation rowid
        in_image (bool): displays annotation with the context of its source image
        annote (bool): enables overlay annoations
        title_suffix (str):
        weight_label (None): (default = None)
        weights (None): (default = None)
        config2_ (dict): (default = None)

    Kwargs:
        enable_chip_title_prefix, nokpts, kpts_subset, kpts, text_color,
        notitle, draw_lbls, show_aidstr, show_gname, show_name, show_nid,
        show_exemplar, show_num_gt, show_quality_text, show_viewcode, fnum,
        title, figtitle, pnum, interpolation, cmap, heatmap, data_colorbar,
        darken, update, xlabel, redraw_image, ax, alpha, docla, doclf,
        projection, pts, ell
        color (3/4-tuple, ndarray, or str): colors for keypoints

    CommandLine:
        python -m ibeis.viz.viz_chip show_chip --show --ecc
        python -c "import utool as ut; ut.print_auto_docstr('ibeis.viz.viz_chip', 'show_chip')"
        python -m ibeis.viz.viz_chip show_chip --show --db NNP_Master3 --aids 14047 --no-annote
        python -m ibeis.viz.viz_chip show_chip --show --db NNP_Master3 --aids 14047 --no-annote

        python -m ibeis.viz.viz_chip show_chip --show --db PZ_MTEST --aid 1 --bgmethod=cnn
        python -m ibeis.viz.viz_chip show_chip --show --db PZ_MTEST --aid 1 --bgmethod=cnn --scale_max=30

        python -m ibeis.viz.viz_chip show_chip --show --db PZ_MTEST --aid 1 --ecc --draw_lbls=False --notitle --save=~/slides/lnbnn_query.jpg --dpi=300

    Example:
        >>> # VIZ_TEST
        >>> from ibeis.viz.viz_chip import *  # NOQA
        >>> import numpy as np
        >>> import vtool_ibeis as vt
        >>> in_image = False
        >>> ibs, aid_list, kwargs, config2_ = testdata_showchip()
        >>> aid = aid_list[0]
        >>> if True:
        >>>     import matplotlib as mpl
        >>>     from ibeis.scripts.thesis import TMP_RC
        >>>     mpl.rcParams.update(TMP_RC)
        >>> if ut.get_argflag('--ecc'):
        >>>     kpts = ibs.get_annot_kpts(aid, config2_=config2_)
        >>>     weights = ibs.get_annot_fgweights([aid], ensure=True, config2_=config2_)[0]
        >>>     kpts = ut.random_sample(kpts[weights > .9], 200, seed=0)
        >>>     ecc = vt.get_kpts_eccentricity(kpts)
        >>>     scale = 1 / vt.get_scales(kpts)
        >>>     #s = ecc if config2_.affine_invariance else scale
        >>>     s = scale
        >>>     colors = pt.scores_to_color(s, cmap_='jet')
        >>>     kwargs['color'] = colors
        >>>     kwargs['kpts'] = kpts
        >>>     kwargs['ell_linewidth'] = 3
        >>>     kwargs['ell_alpha'] = .7
        >>> show_chip(ibs, aid, in_image=in_image, config2_=config2_, **kwargs)
        >>> pt.show_if_requested()
    """
    if ut.VERBOSE:
        print('[viz] show_chip(aid=%r)' % (aid, ))
    #ibs.assert_valid_aids((aid,))
    # Get chip
    #print('in_image = %r' % (in_image,))
    chip = vh.get_chips(ibs, aid, in_image=in_image, config2_=config2_)
    # Create chip title
    chip_text = vh.get_annot_texts(ibs, [aid], **kwargs)[0]
    if kwargs.get('enable_chip_title_prefix', True):
        chip_title_text = chip_text + title_suffix
    else:
        chip_title_text = title_suffix
    chip_title_text = chip_title_text.strip('\n')
    # Draw chip
    fig, ax = pt.imshow(chip, **kwargs)
    # Populate axis user data
    vh.set_ibsdat(ax, 'viztype', 'chip')
    vh.set_ibsdat(ax, 'aid', aid)
    if annote and not kwargs.get('nokpts', False):
        # Get and draw keypoints
        if 'color' not in kwargs:
            if weight_label == 'fg_weights':
                if weights is None and ibs.has_species_detector(
                        ibs.get_annot_species_texts(aid)):
                    weight_label = 'fg_weights'
                    weights = ibs.get_annot_fgweights([aid],
                                                      ensure=True,
                                                      config2_=config2_)[0]
            if weights is not None:
                cmap_ = 'hot'
                #if weight_label == 'dstncvs':
                #    cmap_ = 'rainbow'
                color = pt.scores_to_color(weights,
                                           cmap_=cmap_,
                                           reverse_cmap=False)
                kwargs['color'] = color
                kwargs['ell_color'] = color
                kwargs['pts_color'] = color

        kpts_ = vh.get_kpts(ibs,
                            aid,
                            in_image,
                            config2_=config2_,
                            kpts_subset=kwargs.get('kpts_subset', None),
                            kpts=kwargs.pop('kpts', None))
        pt.viz_keypoints._annotate_kpts(kpts_, **kwargs)
        if kwargs.get('draw_lbls', True):
            pt.upperleft_text(chip_text, color=kwargs.get('text_color', None))
    use_title = not kwargs.get('notitle', False)
    if use_title:
        pt.set_title(chip_title_text)
    if in_image:
        gid = ibs.get_annot_gids(aid)
        aid_list = ibs.get_image_aids(gid)
        annotekw = viz_image.get_annot_annotations(ibs,
                                                   aid_list,
                                                   sel_aids=[aid],
                                                   draw_lbls=kwargs.get(
                                                       'draw_lbls', True))
        # Put annotation centers in the axis
        ph.set_plotdat(ax, 'annotation_bbox_list', annotekw['bbox_list'])
        ph.set_plotdat(ax, 'aid_list', aid_list)
        pt.viz_image2.draw_image_overlay(ax, **annotekw)

        zoom_ = ut.get_argval('--zoom', type_=float, default=None)
        if zoom_ is not None:
            import vtool_ibeis as vt
            # Zoom into the chip for some image context
            rotated_verts = ibs.get_annot_rotated_verts(aid)
            bbox = ibs.get_annot_bboxes(aid)
            #print(bbox)
            #print(rotated_verts)
            rotated_bbox = vt.bbox_from_verts(rotated_verts)
            imgw, imgh = ibs.get_image_sizes(gid)

            pad_factor = zoom_
            pad_length = min(bbox[2], bbox[3]) * pad_factor
            minx = max(rotated_bbox[0] - pad_length, 0)
            miny = max(rotated_bbox[1] - pad_length, 0)
            maxx = min((rotated_bbox[0] + rotated_bbox[2]) + pad_length, imgw)
            maxy = min((rotated_bbox[1] + rotated_bbox[3]) + pad_length, imgh)

            #maxy = imgh - maxy
            #miny = imgh - miny

            ax = pt.gca()
            ax.set_xlim(minx, maxx)
            ax.set_ylim(miny, maxy)
            ax.invert_yaxis()
    else:
        ph.set_plotdat(ax, 'chipshape', chip.shape)

    #if 'featweights' in vars() and 'color' in kwargs:
    if weights is not None and weight_label is not None:
        ## HACK HACK HACK
        if len(weights) > 0:
            cb = pt.colorbar(weights, kwargs['color'])
            cb.set_label(weight_label)
    return fig, ax
Esempio n. 8
0
def show_chip(ibs, aid, in_image=False, annote=True, title_suffix='',
                weight_label=None, weights=None, config2_=None, **kwargs):
    r""" Driver function to show chips

    Args:
        ibs (ibeis.IBEISController):
        aid (int): annotation rowid
        in_image (bool): displays annotation with the context of its source image
        annote (bool): enables overlay annoations
        title_suffix (str):
        weight_label (None): (default = None)
        weights (None): (default = None)
        config2_ (dict): (default = None)

    Kwargs:
        enable_chip_title_prefix, nokpts, kpts_subset, kpts, text_color,
        notitle, draw_lbls, show_aidstr, show_gname, show_name, show_nid,
        show_exemplar, show_num_gt, show_quality_text, show_yawtext, fnum,
        title, figtitle, pnum, interpolation, cmap, heatmap, data_colorbar,
        darken, update, xlabel, redraw_image, ax, alpha, docla, doclf,
        projection, use_gridspec, pts, ell
        color (3/4-tuple, ndarray, or str): colors for keypoints

    CommandLine:
        python -m ibeis.viz.viz_chip --test-show_chip --show --ecc
        python -c "import utool as ut; ut.print_auto_docstr('ibeis.viz.viz_chip', 'show_chip')"
        python -m ibeis.viz.viz_chip --test-show_chip --show --db NNP_Master3 --aids 14047 --no-annote
        python -m ibeis.viz.viz_chip --test-show_chip --show --db NNP_Master3 --aids 14047 --no-annote

        python -m ibeis.viz.viz_chip --test-show_chip --show --db PZ_MTEST --aid 1 --bgmethod=cnn
        python -m ibeis.viz.viz_chip --test-show_chip --show --db PZ_MTEST --aid 1 --bgmethod=cnn --scale_max=30

    Example:
        >>> # VIZ_TEST
        >>> from ibeis.viz.viz_chip import *  # NOQA
        >>> import numpy as np
        >>> import vtool as vt
        >>> in_image = False
        >>> ibs, aid_list, kwargs, config2_ = testdata_showchip()
        >>> aid = aid_list[0]
        >>> if ut.get_argflag('--ecc'):
        >>>     kpts = ibs.get_annot_kpts(aid, config2_=config2_)
        >>>     weights = ibs.get_annot_fgweights([aid], ensure=True, config2_=config2_)[0]
        >>>     kpts = ut.random_sample(kpts[weights > .9], 200, seed=0)
        >>>     ecc = vt.get_kpts_eccentricity(kpts)
        >>>     scale = 1 / vt.get_scales(kpts)
        >>>     s = ecc if config2_.affine_invariance else scale
        >>>     colors = pt.scores_to_color(s, cmap_='jet')
        >>>     kwargs['color'] = colors
        >>>     kwargs['kpts'] = kpts
        >>> show_chip(ibs, aid, in_image=in_image, config2_=config2_, **kwargs)
        >>> pt.show_if_requested()
    """
    if ut.VERBOSE:
        print('[viz] show_chip(aid=%r)' % (aid,))
    #ibs.assert_valid_aids((aid,))
    # Get chip
    #print('in_image = %r' % (in_image,))
    chip = vh.get_chips(ibs, aid, in_image=in_image, config2_=config2_)
    # Create chip title
    chip_text = vh.get_annot_texts(ibs, [aid], **kwargs)[0]
    if kwargs.get('enable_chip_title_prefix', True):
        chip_title_text = chip_text + title_suffix
    else:
        chip_title_text = title_suffix
    chip_title_text = chip_title_text.strip('\n')
    # Draw chip
    fig, ax = pt.imshow(chip, **kwargs)
    # Populate axis user data
    vh.set_ibsdat(ax, 'viztype', 'chip')
    vh.set_ibsdat(ax, 'aid', aid)
    if annote and not kwargs.get('nokpts', False):
        # Get and draw keypoints
        if 'color' not in kwargs:
            if weight_label == 'fg_weights':
                if weights is None and ibs.has_species_detector(ibs.get_annot_species_texts(aid)):
                    weight_label = 'fg_weights'
                    weights = ibs.get_annot_fgweights([aid], ensure=True, config2_=config2_)[0]
            if weights is not None:
                cmap_ = 'hot'
                #if weight_label == 'dstncvs':
                #    cmap_ = 'rainbow'
                color = pt.scores_to_color(weights, cmap_=cmap_, reverse_cmap=False)
                kwargs['color'] = color
                kwargs['ell_color'] = color
                kwargs['pts_color'] = color

        kpts_ = vh.get_kpts(ibs, aid, in_image, config2_=config2_,
                            kpts_subset=kwargs.get('kpts_subset', None),
                            kpts=kwargs.get('kpts', None))
        try:
            del kwargs['kpts']
        except KeyError:
            pass
        pt.viz_keypoints._annotate_kpts(kpts_, **kwargs)
        if not ut.get_argflag('--noaidlabel'):
            pt.upperleft_text(chip_text, color=kwargs.get('text_color', None))
    use_title = not kwargs.get('notitle', False)
    if use_title:
        pt.set_title(chip_title_text)
    if in_image:
        gid = ibs.get_annot_gids(aid)
        aid_list = ibs.get_image_aids(gid)
        annotekw = viz_image.get_annot_annotations(
            ibs, aid_list, sel_aids=[aid], draw_lbls=kwargs.get('draw_lbls', True))
        # Put annotation centers in the axis
        ph.set_plotdat(ax, 'annotation_bbox_list', annotekw['bbox_list'])
        ph.set_plotdat(ax, 'aid_list', aid_list)
        pt.viz_image2.draw_image_overlay(ax, **annotekw)

        zoom_ = ut.get_argval('--zoom', type_=float, default=None)
        if zoom_ is not None:
            import vtool as vt
            # Zoom into the chip for some image context
            rotated_verts = ibs.get_annot_rotated_verts(aid)
            bbox = ibs.get_annot_bboxes(aid)
            #print(bbox)
            #print(rotated_verts)
            rotated_bbox = vt.bbox_from_verts(rotated_verts)
            imgw, imgh = ibs.get_image_sizes(gid)

            pad_factor = zoom_
            pad_length = min(bbox[2], bbox[3]) * pad_factor
            minx = max(rotated_bbox[0] - pad_length, 0)
            miny = max(rotated_bbox[1] - pad_length, 0)
            maxx = min((rotated_bbox[0] + rotated_bbox[2]) + pad_length, imgw)
            maxy = min((rotated_bbox[1] + rotated_bbox[3]) + pad_length, imgh)

            #maxy = imgh - maxy
            #miny = imgh - miny

            ax = pt.gca()
            ax.set_xlim(minx, maxx)
            ax.set_ylim(miny, maxy)
            ax.invert_yaxis()
    else:
        ph.set_plotdat(ax, 'chipshape', chip.shape)

    #if 'featweights' in vars() and 'color' in kwargs:
    if weights is not None and weight_label is not None:
        ## HACK HACK HACK
        if len(weights) > 0:
            cb = pt.colorbar(weights, kwargs['color'])
            cb.set_label(weight_label)
    return fig, ax