예제 #1
0
def show_notch_tips(depc, aid, config={}, fnum=None, pnum=None):
    import plottool as pt
    pt.figure(fnum=fnum, pnum=pnum)
    notch = depc.get('Notch_Tips', aid, config=config)
    chip = depc.get('chips', aid, 'img', config=config)
    pt.imshow(chip)
    pt.draw_kpts2(np.array(notch), pts=True, ell=False, pts_size=20)
예제 #2
0
def show_chip_distinctiveness_plot(chip, kpts, dstncvs, fnum=1, pnum=None):
    import plottool as pt
    pt.figure(fnum, pnum=pnum)
    ax = pt.gca()
    divider = pt.ensure_divider(ax)
    #ax1 = divider.append_axes("left", size="50%", pad=0)
    ax1 = ax
    ax2 = divider.append_axes("bottom", size="100%", pad=0.05)
    #f, (ax1, ax2) = pt.plt.subplots(1, 2, sharex=True)
    cmapstr = 'rainbow'  # 'hot'
    color_list = pt.df2.plt.get_cmap(cmapstr)(ut.norm_zero_one(dstncvs))
    sortx = dstncvs.argsort()
    #pt.df2.plt.plot(qfx2_dstncvs[sortx], c=color_list[sortx])
    pt.plt.sca(ax1)
    pt.colorline(np.arange(len(sortx)), dstncvs[sortx],
                 cmap=pt.plt.get_cmap(cmapstr))
    pt.gca().set_xlim(0, len(sortx))
    pt.dark_background()
    pt.plt.sca(ax2)
    pt.imshow(chip, darken=.2)
    # MATPLOTLIB BUG CANNOT SHOW DIFFERENT ALPHA FOR POINTS AND KEYPOINTS AT ONCE
    #pt.draw_kpts2(kpts, pts_color=color_list, ell_color=color_list, ell_alpha=.1, ell=True, pts=True)
    #pt.draw_kpts2(kpts, color_list=color_list, pts_alpha=1.0, pts_size=1.5,
    #              ell=True, ell_alpha=.1, pts=False)
    ell = ut.get_argflag('--ell')
    pt.draw_kpts2(kpts, color_list=color_list, pts_alpha=1.0, pts_size=1.5,
                  ell=ell, ell_alpha=.3, pts=not ell)
    pt.plt.sca(ax)
예제 #3
0
def show_notch_tips(depc, aid, config={}, fnum=None, pnum=None):
    import plottool as pt
    pt.figure(fnum=fnum, pnum=pnum)
    notch = depc.get('Notch_Tips', aid, config=config)
    chip = depc.get('chips', aid, 'img', config=config)
    pt.imshow(chip)
    pt.draw_kpts2(np.array(notch), pts=True, ell=False, pts_size=20)
예제 #4
0
def show_coverage_map(chip,
                      mask,
                      patch,
                      kpts,
                      fnum=None,
                      ell_alpha=.6,
                      show_mask_kpts=False):
    """ testing function """
    import plottool as pt
    if fnum is None:
        fnum = pt.next_fnum()
    pnum_ = pt.get_pnum_func(nRows=2, nCols=2)
    if patch is not None:
        pt.imshow((patch * 255).astype(np.uint8),
                  fnum=fnum,
                  pnum=pnum_(0),
                  title='patch')
        #ut.embed()
        pt.imshow((mask * 255).astype(np.uint8),
                  fnum=fnum,
                  pnum=pnum_(1),
                  title='mask')
    else:
        pt.imshow((mask * 255).astype(np.uint8),
                  fnum=fnum,
                  pnum=(2, 1, 1),
                  title='mask')
    if show_mask_kpts:
        pt.draw_kpts2(kpts, rect=True, ell_alpha=ell_alpha)
    pt.imshow(chip, fnum=fnum, pnum=pnum_(2), title='chip')
    pt.draw_kpts2(kpts, rect=True, ell_alpha=ell_alpha)
    masked_chip = (chip * mask[:, :, None]).astype(np.uint8)
    pt.imshow(masked_chip, fnum=fnum, pnum=pnum_(3), title='masked chip')
예제 #5
0
def show_coverage_map(chip, mask, patch, kpts, fnum=None, ell_alpha=.6,
                      show_mask_kpts=False):
    """ testing function """
    import plottool as pt
    if fnum is None:
        fnum = pt.next_fnum()
    pnum_ = pt.get_pnum_func(nRows=2, nCols=2)
    if patch is not None:
        pt.imshow((patch * 255).astype(np.uint8), fnum=fnum, pnum=pnum_(0), title='patch')
        #ut.embed()
        pt.imshow((mask * 255).astype(np.uint8), fnum=fnum, pnum=pnum_(1), title='mask')
    else:
        pt.imshow((mask * 255).astype(np.uint8), fnum=fnum, pnum=(2, 1, 1), title='mask')
    if show_mask_kpts:
        pt.draw_kpts2(kpts, rect=True, ell_alpha=ell_alpha)
    pt.imshow(chip, fnum=fnum, pnum=pnum_(2), title='chip')
    pt.draw_kpts2(kpts, rect=True, ell_alpha=ell_alpha)
    masked_chip = (chip * mask[:, :, None]).astype(np.uint8)
    pt.imshow(masked_chip, fnum=fnum, pnum=pnum_(3), title='masked chip')
예제 #6
0
    def show(annot):
        import plottool as pt

        pt.imshow(annot.rchip)
        pt.draw_kpts2(annot.kpts)
예제 #7
0
 def show(annot):
     import plottool as pt
     pt.imshow(annot.rchip)
     pt.draw_kpts2(annot.kpts)
예제 #8
0
def test_rot_invar():
    r"""
    CommandLine:
        python -m pyhesaff test_rot_invar --show --rebuild-hesaff --no-rmbuild
        python -m pyhesaff test_rot_invar --show --nocpp

        python -m vtool.tests.dummy testdata_ratio_matches --show --ratio_thresh=1.0 --rotation_invariance --rebuild-hesaff
        python -m vtool.tests.dummy testdata_ratio_matches --show --ratio_thresh=1.1 --rotation_invariance --rebuild-hesaff

    Example:
        >>> # DISABLE_DODCTEST
        >>> from pyhesaff._pyhesaff import *  # NOQA
        >>> test_rot_invar()
    """
    import cv2
    import vtool as vt
    import plottool as pt
    TAU = 2 * np.pi
    fnum = pt.next_fnum()
    NUM_PTS = 5  # 9
    theta_list = np.linspace(0, TAU, NUM_PTS, endpoint=False)
    nRows, nCols = pt.get_square_row_cols(len(theta_list), fix=True)
    next_pnum = pt.make_pnum_nextgen(nRows, nCols)
    # Expand the border a bit around star.png
    pad_ = 100
    img_fpath = grab_test_imgpath('star.png')
    img_fpath2 = vt.pad_image_ondisk(img_fpath, pad_, value=26)
    for theta in theta_list:
        print('-----------------')
        print('theta = %r' % (theta, ))
        img_fpath = vt.rotate_image_ondisk(img_fpath2,
                                           theta,
                                           border_mode=cv2.BORDER_REPLICATE)
        if not ub.argflag('--nocpp'):
            (kpts_list_ri, vecs_list2) = detect_feats(img_fpath,
                                                      rotation_invariance=True)
            kpts_ri = kpts_list_ri[0:2]
        (kpts_list_gv, vecs_list1) = detect_feats(img_fpath,
                                                  rotation_invariance=False)
        kpts_gv = kpts_list_gv[0:2]
        # find_kpts_direction
        imgBGR = vt.imread(img_fpath)
        kpts_ripy = vt.find_kpts_direction(imgBGR,
                                           kpts_gv,
                                           DEBUG_ROTINVAR=False)
        # Verify results stdout
        #print('nkpts = %r' % (len(kpts_gv)))
        #print(vt.kpts_repr(kpts_gv))
        #print(vt.kpts_repr(kpts_ri))
        #print(vt.kpts_repr(kpts_ripy))
        # Verify results plot
        pt.figure(fnum=fnum, pnum=next_pnum())
        pt.imshow(imgBGR)
        #if len(kpts_gv) > 0:
        #    pt.draw_kpts2(kpts_gv, ori=True, ell_color=pt.BLUE, ell_linewidth=10.5)
        ell = False
        rect = True
        if not ub.argflag('--nocpp'):
            if len(kpts_ri) > 0:
                pt.draw_kpts2(kpts_ri,
                              rect=rect,
                              ell=ell,
                              ori=True,
                              ell_color=pt.RED,
                              ell_linewidth=5.5)
        if len(kpts_ripy) > 0:
            pt.draw_kpts2(kpts_ripy,
                          rect=rect,
                          ell=ell,
                          ori=True,
                          ell_color=pt.GREEN,
                          ell_linewidth=3.5)
    pt.set_figtitle('green=python, red=C++')
    pt.show_if_requested()
예제 #9
0
def test_featweight_worker():
    """
    test function

    python -m ibeis.algo.preproc.preproc_featweight --test-gen_featweight_worker --show --cnn
    """
    import ibeis
    qreq_ = ibeis.main_helpers.testdata_qreq_(defaultdb='PZ_MTEST', p=['default:fw_detector=cnn'], qaid_override=[1])
    ibs = qreq_.ibs
    config2_ = qreq_.qparams
    lazy = True
    aid_list            = qreq_.get_external_qaids()
    #aid_list = ibs.get_valid_aids()[0:30]
    kpts_list           = ibs.get_annot_kpts(aid_list)
    chipsize_list       = ibs.get_annot_chip_sizes(aid_list, config2_=config2_)
    probchip_fpath_list = preproc_probchip.compute_and_write_probchip(ibs,
                                                                      aid_list,
                                                                      lazy=lazy,
                                                                      config2_=config2_)
    print('probchip_fpath_list = %r' % (probchip_fpath_list,))
    probchip_list       = [vt.imread(fpath, grayscale=True) if exists(fpath) else None
                           for fpath in probchip_fpath_list]

    _iter = list(zip(aid_list, kpts_list, probchip_list, chipsize_list))
    _iter = ut.InteractiveIter(_iter, enabled=ut.get_argflag('--show'))
    for aid, kpts, probchip, chipsize in _iter:
        #kpts     = kpts_list[0]
        #aid      = aid_list[0]
        #probchip = probchip_list[0]
        #chipsize = chipsize_list[0]
        tup = (aid, kpts, probchip, chipsize)
        (aid, weights) = gen_featweight_worker(tup)
        if aid == 3 and ibs.get_dbname() == 'testdb1':
            # Run Asserts if not interactive
            weights_03_test = weights[0:3]
            print('weights[0:3] = %r' % (weights_03_test,))
            #weights_03_target = [ 0.098, 0.155,  0.422]
            #weights_03_target = [ 0.324, 0.407,  0.688]
            #weights_thresh    = [ 0.09, 0.09,  0.09]
            #ut.assert_almost_eq(weights_03_test, weights_03_target, weights_thresh)
            ut.assert_inbounds(weights_03_test, 0, 1)
            if not ut.show_was_requested():
                break
        if ut.show_was_requested():
            import plottool as pt
            #sfx, sfy = (probchip.shape[1] / chipsize[0], probchip.shape[0] / chipsize[1])
            #kpts_ = vt.offset_kpts(kpts, (0, 0), (sfx, sfy))
            pnum_ = pt.make_pnum_nextgen(1, 3)  # *pt.get_square_row_cols(4))
            fnum = 1
            pt.figure(fnum=fnum, doclf=True)
            ###
            pt.imshow(ibs.get_annot_chips(aid, config2_=config2_), pnum=pnum_(0), fnum=fnum)
            if ut.get_argflag('--numlbl'):
                pt.gca().set_xlabel('(1)')
            ###
            pt.imshow(probchip, pnum=pnum_(2), fnum=fnum)
            if ut.get_argflag('--numlbl'):
                pt.gca().set_xlabel('(2)')
            #pt.draw_kpts2(kpts_, ell_alpha=.4, color_list=pt.ORANGE)
            ###
            #pt.imshow(probchip, pnum=pnum_(3), fnum=fnum)
            #color_list = pt.draw_kpts2(kpts_, weights=weights, ell_alpha=.7, cmap_='jet')
            #cb = pt.colorbar(weights, color_list)
            #cb.set_label('featweights')
            ###
            pt.imshow(ibs.get_annot_chips(aid, config2_=qreq_.qparams), pnum=pnum_(1), fnum=fnum)
            #color_list = pt.draw_kpts2(kpts, weights=weights, ell_alpha=.3, cmap_='jet')
            color_list = pt.draw_kpts2(kpts, weights=weights, ell_alpha=.3)
            cb = pt.colorbar(weights, color_list)
            cb.set_label('featweights')
            if ut.get_argflag('--numlbl'):
                pt.gca().set_xlabel('(3)')
            #pt.draw_kpts2(kpts, ell_alpha=.4)
            pt.draw()
            pt.show_if_requested()
예제 #10
0
def test_rot_invar():
    r"""
    CommandLine:
        python -m pyhesaff test_rot_invar --show --rebuild-hesaff --no-rmbuild
        python -m pyhesaff test_rot_invar --show --nocpp

        python -m vtool.tests.dummy testdata_ratio_matches --show --ratio_thresh=1.0 --rotation_invariance --rebuild-hesaff
        python -m vtool.tests.dummy testdata_ratio_matches --show --ratio_thresh=1.1 --rotation_invariance --rebuild-hesaff

    Example:
        >>> # DISABLE_DODCTEST
        >>> from pyhesaff._pyhesaff import *  # NOQA
        >>> test_rot_invar()
    """
    import cv2
    import utool as ut
    import vtool as vt
    import plottool as pt
    TAU = 2 * np.pi
    fnum = pt.next_fnum()
    NUM_PTS = 5  # 9
    theta_list = np.linspace(0, TAU, NUM_PTS, endpoint=False)
    nRows, nCols = pt.get_square_row_cols(len(theta_list), fix=True)
    next_pnum = pt.make_pnum_nextgen(nRows, nCols)
    # Expand the border a bit around star.png
    pad_ = 100
    img_fpath = ut.grab_test_imgpath('star.png')
    img_fpath2 = vt.pad_image_ondisk(img_fpath, pad_, value=26)
    for theta in theta_list:
        print('-----------------')
        print('theta = %r' % (theta,))
        #theta = ut.get_argval('--theta', type_=float, default=TAU * 3 / 8)
        img_fpath = vt.rotate_image_ondisk(img_fpath2, theta, borderMode=cv2.BORDER_REPLICATE)
        if not ut.get_argflag('--nocpp'):
            (kpts_list_ri, vecs_list2) = detect_feats(img_fpath, rotation_invariance=True)
            kpts_ri = ut.strided_sample(kpts_list_ri, 2)
        (kpts_list_gv, vecs_list1) = detect_feats(img_fpath, rotation_invariance=False)
        kpts_gv = ut.strided_sample(kpts_list_gv, 2)
        # find_kpts_direction
        imgBGR = vt.imread(img_fpath)
        kpts_ripy = vt.find_kpts_direction(imgBGR, kpts_gv, DEBUG_ROTINVAR=False)
        # Verify results stdout
        #print('nkpts = %r' % (len(kpts_gv)))
        #print(vt.kpts_repr(kpts_gv))
        #print(vt.kpts_repr(kpts_ri))
        #print(vt.kpts_repr(kpts_ripy))
        # Verify results plot
        pt.figure(fnum=fnum, pnum=next_pnum())
        pt.imshow(imgBGR)
        #if len(kpts_gv) > 0:
        #    pt.draw_kpts2(kpts_gv, ori=True, ell_color=pt.BLUE, ell_linewidth=10.5)
        ell = False
        rect = True
        if not ut.get_argflag('--nocpp'):
            if len(kpts_ri) > 0:
                pt.draw_kpts2(kpts_ri, rect=rect, ell=ell, ori=True,
                              ell_color=pt.RED, ell_linewidth=5.5)
        if len(kpts_ripy) > 0:
            pt.draw_kpts2(kpts_ripy, rect=rect, ell=ell,  ori=True,
                          ell_color=pt.GREEN, ell_linewidth=3.5)
        #print('\n'.join(vt.get_ori_strs(np.vstack([kpts_gv, kpts_ri, kpts_ripy]))))
        #ut.embed(exec_lines=['pt.update()'])
    pt.set_figtitle('green=python, red=C++')
    pt.show_if_requested()