Ejemplo n.º 1
0
def show_sver(ibs, aid1, aid2, chipmatch_FILT=None, aid2_svtup=None, config2_=None, **kwargs):
    """
    Compiles IBEIS information and sends it to plottool

    CommandLine:
        python -m ibeis.viz.viz_sver --test-show_sver --show

    Example:
        >>> # SLOW_DOCTEST
        >>> from ibeis.viz.viz_sver import *   # NOQA
        >>> import ibeis
        >>> import utool as ut
        >>> ibs = ibeis.opendb('testdb1')
        >>> aid_list = ibs.get_valid_aids()
        >>> aid1, aid2 = aid_list[0:2]
        >>> chipmatch_FILT = None
        >>> aid2_svtup = None
        >>> kwargs = {}
        >>> show_sver(ibs, aid1, aid2)
        >>> ut.quit_if_noshow()
        >>> import plottool as pt
        >>> exec(pt.present())
    """
    print('\n[show_sver] ====================== [show_sver]')
    #print(ut.func_str(show_sv, kwargs=locals()))
    if chipmatch_FILT is None or aid2_svtup is None:
        chipmatch_FILT, aid2_svtup = _compute_svvars(ibs, aid1)
    sv_vartup = _get_sv_vartup_for_plottool(ibs, aid1, aid2, chipmatch_FILT, aid2_svtup, config2_=config2_)
    (chip1, chip2, kpts1, kpts2, fm, homog_tup, aff_tup) = sv_vartup
    if WRITE_SV_DEBUG:
        keys = ('chip1', 'chip2', 'kpts1', 'kpts2', 'fm', 'homog_tup', 'aff_tup')
        ut.save_testdata(*keys)
        print('[vizsv] write test info')
        ut.qflag()
    draw_sv.show_sv(chip1, chip2, kpts1, kpts2, fm, homog_tup=homog_tup, aff_tup=aff_tup, **kwargs)
Ejemplo n.º 2
0
def show_sver(ibs, aid1, aid2, chipmatch_FILT=None, aid2_svtup=None, **kwargs):
    """ Compiles IBEIS information and sends it to plottool """
    print('\n[show_sver] ====================== [show_sver]')
    #print(utool.func_str(show_sv, kwargs=locals()))
    if chipmatch_FILT is None or aid2_svtup is None:
        chipmatch_FILT, aid2_svtup = _compute_svvars(ibs, aid1)
    sv_vartup = _get_sv_vartup_for_plottool(ibs, aid1, aid2, chipmatch_FILT, aid2_svtup)
    (chip1, chip2, kpts1, kpts2, fm, homog_tup, aff_tup) = sv_vartup
    if WRITE_SV_DEBUG:
        keys = ('chip1', 'chip2', 'kpts1', 'kpts2', 'fm', 'homog_tup', 'aff_tup')
        utool.save_testdata(*keys)
        print('[vizsv] write test info')
        utool.qflag()
    draw_sv.show_sv(chip1, chip2, kpts1, kpts2, fm, homog_tup=homog_tup, aff_tup=aff_tup, **kwargs)
Ejemplo n.º 3
0
def test_sver(chip1, chip2, kpts1, kpts2, fm, nShow=6):
    r"""
    Args:
        chip1 (ndarray[uint8_t, ndim=2]):  annotation image data
        chip2 (ndarray[uint8_t, ndim=2]):  annotation image data
        kpts1 (ndarray[float32_t, ndim=2]):  keypoints
        kpts2 (ndarray[float32_t, ndim=2]):  keypoints
        fm (list):  list of feature matches as tuples (qfx, dfx)
        nShow (int):

    Returns:
        ?:

    CommandLine:
        python -m vtool.tests.test_spatial_verification --test-test_sver:0 --show
        python -m vtool.tests.test_spatial_verification --test-test_sver:1 --show

    Example0:
        >>> # DISABLE_DOCTEST
        >>> import plottool as pt
        >>> from vtool.tests.test_spatial_verification import *  # NOQA
        >>> # build test data
        >>> nShow = utool.get_argval('--nShow', int, 1)
        >>> chip1, chip2, kpts1, kpts2, fm = get_dummy_test_vars()
        >>> # execute function
        >>> result = test_sver(chip1, chip2, kpts1, kpts2, fm, nShow)
        >>> # verify results
        >>> print(result)
        >>> pt.show_if_requested()

    Example1:
        >>> # DISABLE_DOCTEST
        >>> import plottool as pt
        >>> from vtool.tests.test_spatial_verification import *  # NOQA
        >>> # build test data
        >>> nShow = utool.get_argval('--nShow', int, 1)
        >>> chip1, chip2, kpts1, kpts2, fm = get_dummy_test_vars1()
        >>> # execute function
        >>> result = test_sver(chip1, chip2, kpts1, kpts2, fm, nShow)
        >>> # verify results
        >>> print(result)
        >>> pt.show_if_requested()
    """

    xy_thresh_sqrd = ktool.get_diag_extent_sqrd(kpts2) * xy_thresh

    def pack_errors(xy_err, scale_err, ori_err):
        """ makes human readable errors """
        def _pack(bits, errs, thresh):
            return utool.indentjoin([
                '%5s %f < %f' % (bit, err, thresh)
                for (bit, err) in zip(bits, errs)
            ])

        xy_flag = xy_err < xy_thresh_sqrd
        scale_flag = scale_err < scale_thresh_sqrd
        ori_flag = ori_err < ori_thresh
        errors_dict = {
            'xy_err':
            _pack(xy_flag, np.sqrt(xy_err), np.sqrt(xy_thresh_sqrd)),
            'scale_err':
            _pack(scale_flag, np.sqrt(scale_err), np.sqrt(scale_thresh_sqrd)),
            'ori_err':
            _pack(ori_flag, ori_err, ori_thresh),
        }
        return errors_dict

    # Test each affine hypothesis
    #assert kpts1.dtype == ktool.KPTS_DTYPE, 'bad cast somewhere kpts1.dtype=%r' % (kpts1.dtype)
    #assert kpts2.dtype == ktool.KPTS_DTYPE, 'bad cast somewhere kpts2.dtype=%r' % (kpts2.dtype)
    #assert xy_thresh_sqrd.dtype == ktool.KPTS_DTYPE, 'bad cast somewhere
    #xy_thresh_sqrd.dtype=%r' % (xy_thresh_sqrd.dtype)
    aff_hypo_tups = sver.get_affine_inliers(kpts1, kpts2, fm, xy_thresh_sqrd,
                                            scale_thresh_sqrd, ori_thresh)
    inliers_list, errors_list, Aff_mats = aff_hypo_tups

    # Determine best hypothesis
    nInliers_list = np.array(list(map(len, inliers_list)))
    best_mxs = nInliers_list.argsort()[::-1]

    for fnum, mx in enumerate(best_mxs[0:min(len(best_mxs), nShow)]):
        Aff = Aff_mats[mx]
        aff_inliers = inliers_list[mx]
        if utool.get_argflag('--print-error'):
            errors = pack_errors(*errors_list[mx])  # NOQA
            print(utool.dict_str(errors, strvals=True))

        homog_inliers, homog_errors, H = sver.get_homography_inliers(
            kpts1, kpts2, fm, aff_inliers, xy_thresh_sqrd)

        kpts1_At = ktool.transform_kpts(kpts1, Aff)
        kpts1_Ht = ktool.transform_kpts(kpts1, H)
        kpts = kpts1
        M = H

        homog_tup = (homog_inliers, H)
        aff_tup = (aff_inliers, Aff)

        _args = (chip1, chip2, kpts1, kpts2, fm)
        _kw = dict(show_assign=True, show_kpts=True, mx=mx, fnum=fnum * 3)
        draw_sv.show_sv(*_args, aff_tup=aff_tup, homog_tup=homog_tup, **_kw)
        #draw_sv.show_sv(*_args, aff_tup=aff_tup, mx=mx, fnum=fnum * 3)
        #draw_sv.show_sv(*_args, homog_tup=homog_tup, mx=mx, fnum=3)

        df2.set_figtitle('# %r inliers (in rects, hypo in bold)' %
                         (nInliers_list[mx], ))
    return locals()
Ejemplo n.º 4
0
def test_sver(chip1, chip2, kpts1, kpts2, fm, nShow=6):
    r"""
    Args:
        chip1 (ndarray[uint8_t, ndim=2]):  annotation image data
        chip2 (ndarray[uint8_t, ndim=2]):  annotation image data
        kpts1 (ndarray[float32_t, ndim=2]):  keypoints
        kpts2 (ndarray[float32_t, ndim=2]):  keypoints
        fm (list):  list of feature matches as tuples (qfx, dfx)
        nShow (int):

    Returns:
        ?:

    CommandLine:
        python -m vtool.tests.test_spatial_verification --test-test_sver:0 --show
        python -m vtool.tests.test_spatial_verification --test-test_sver:1 --show

    Example0:
        >>> # DISABLE_DOCTEST
        >>> import plottool as pt
        >>> from vtool.tests.test_spatial_verification import *  # NOQA
        >>> # build test data
        >>> nShow = utool.get_argval('--nShow', int, 1)
        >>> chip1, chip2, kpts1, kpts2, fm = get_dummy_test_vars()
        >>> # execute function
        >>> result = test_sver(chip1, chip2, kpts1, kpts2, fm, nShow)
        >>> # verify results
        >>> print(result)
        >>> pt.show_if_requested()

    Example1:
        >>> # DISABLE_DOCTEST
        >>> import plottool as pt
        >>> from vtool.tests.test_spatial_verification import *  # NOQA
        >>> # build test data
        >>> nShow = utool.get_argval('--nShow', int, 1)
        >>> chip1, chip2, kpts1, kpts2, fm = get_dummy_test_vars1()
        >>> # execute function
        >>> result = test_sver(chip1, chip2, kpts1, kpts2, fm, nShow)
        >>> # verify results
        >>> print(result)
        >>> pt.show_if_requested()
    """

    xy_thresh_sqrd = ktool.get_diag_extent_sqrd(kpts2) * xy_thresh

    def pack_errors(xy_err, scale_err, ori_err):
        """ makes human readable errors """
        def _pack(bits, errs, thresh):
            return utool.indentjoin(['%5s %f < %f' % (bit, err, thresh) for
                                     (bit, err) in zip(bits, errs)])
        xy_flag = xy_err < xy_thresh_sqrd
        scale_flag = scale_err < scale_thresh_sqrd
        ori_flag = ori_err < ori_thresh
        errors_dict = {
            'xy_err':     _pack(xy_flag, np.sqrt(xy_err), np.sqrt(xy_thresh_sqrd)),
            'scale_err':  _pack(scale_flag, np.sqrt(scale_err), np.sqrt(scale_thresh_sqrd)),
            'ori_err':    _pack(ori_flag, ori_err, ori_thresh),
        }
        return errors_dict

    # Test each affine hypothesis
    #assert kpts1.dtype == ktool.KPTS_DTYPE, 'bad cast somewhere kpts1.dtype=%r' % (kpts1.dtype)
    #assert kpts2.dtype == ktool.KPTS_DTYPE, 'bad cast somewhere kpts2.dtype=%r' % (kpts2.dtype)
    #assert xy_thresh_sqrd.dtype == ktool.KPTS_DTYPE, 'bad cast somewhere
    #xy_thresh_sqrd.dtype=%r' % (xy_thresh_sqrd.dtype)
    aff_hypo_tups = sver.get_affine_inliers(kpts1, kpts2, fm, xy_thresh_sqrd,
                                            scale_thresh_sqrd, ori_thresh)
    inliers_list, errors_list, Aff_mats = aff_hypo_tups

    # Determine best hypothesis
    nInliers_list = np.array(list(map(len, inliers_list)))
    best_mxs = nInliers_list.argsort()[::-1]

    for fnum, mx in enumerate(best_mxs[0:min(len(best_mxs), nShow)]):
        Aff = Aff_mats[mx]
        aff_inliers = inliers_list[mx]
        if utool.get_argflag('--print-error'):
            errors = pack_errors(*errors_list[mx])  # NOQA
            print(utool.dict_str(errors, strvals=True))

        homog_inliers, homog_errors, H = sver.get_homography_inliers(kpts1,
                                                                     kpts2, fm,
                                                                     aff_inliers,
                                                                     xy_thresh_sqrd)

        kpts1_At = ktool.transform_kpts(kpts1, Aff)
        kpts1_Ht = ktool.transform_kpts(kpts1, H)
        kpts = kpts1
        M = H

        homog_tup = (homog_inliers, H)
        aff_tup = (aff_inliers, Aff)

        _args = (chip1, chip2, kpts1, kpts2, fm)
        _kw = dict(show_assign=True, show_kpts=True, mx=mx, fnum=fnum * 3)
        draw_sv.show_sv(*_args, aff_tup=aff_tup, homog_tup=homog_tup, **_kw)
        #draw_sv.show_sv(*_args, aff_tup=aff_tup, mx=mx, fnum=fnum * 3)
        #draw_sv.show_sv(*_args, homog_tup=homog_tup, mx=mx, fnum=3)

        df2.set_figtitle('# %r inliers (in rects, hypo in bold)' % (nInliers_list[mx],))
    return locals()