def TEST_keypoint(imgBGR, img_fpath, kpts, desc, sel, fnum=1, figtitle=''):
    from plottool import draw_func2 as df2
    from plottool.viz_keypoints import _annotate_kpts, show_keypoints
    from plottool.viz_featrow import draw_feat_row
    import plottool
    import vtool.patch as ptool
    #----------------------#
    # --- Extract Data --- #
    #----------------------#
    kp = kpts[sel]
    # Extract patches, gradients, and orientations
    print('[rotinvar] 1) Extract patch, gradients, and orientations')
    wpatch, wkp = ptool.get_warped_patch(imgBGR, kp, gray=True)
    gradx, grady = ptool.patch_gradient(wpatch)
    gmag = ptool.patch_mag(gradx, grady)
    gori = ptool.patch_ori(gradx, grady)
    gori_weights = ptool.gaussian_weight_patch(gmag)

    # Get orientation histogram
    print('[rotinvar] 2) Get orientation histogram')
    hist, centers = ptool.get_orientation_histogram(gori, gori_weights)

    #----------------------#
    # --- Draw Results --- #
    #----------------------#
    f1_loc = TEST_figure1(wpatch,
                          gradx,
                          grady,
                          gmag,
                          gori,
                          hist,
                          centers,
                          fnum=fnum)
    df2.set_figtitle(figtitle + 'Dominant Orienation Extraction')

    TEST_figure2(imgBGR, kpts, desc, sel, fnum=fnum + 1)
    df2.set_figtitle(figtitle)
    #    TEST_figure2(imgBGR, kpts2, Desc2, sel, fnum=fnum + 2)
    #    df2.set_figtitle('Rotation Invariant')

    #df2.draw_keypoint_gradient_orientations(imgBGR, kp=kpts2[sel],
    #                                        sift=desc[sel], mode='vec',
    #                                        fnum=4)

    #df2.draw_vector_field(gradx, grady, pnum=(1, 1, 1), fnum=4)
    #df2.draw_kpts2(np.array([wkp]), sifts=desc[sel:sel + 1], ori=True)
    return locals()
Exemplo n.º 2
0
def TEST_keypoint(imgBGR, img_fpath, kpts, desc, sel):
    import pyhesaff
    import vtool.patch as ptool
    from plottool import draw_func2 as df2
    #----------------------#
    # --- Extract Data --- #
    #----------------------#
    kp = kpts[sel]
    # Extract patches, gradients, and orientations
    print('[rotinvar] 1) Extract patch, gradients, and orientations')
    wpatch, wkp = ptool.get_warped_patch(imgBGR, kp, gray=True)
    gradx, grady = ptool.patch_gradient(wpatch, gaussian_weighted=False)
    gmag = ptool.patch_mag(gradx, grady)
    gori = ptool.patch_ori(gradx, grady)

    # Get orientation histogram
    print('[rotinvar] 2) Get orientation histogram')
    gori_weights = ptool.gaussian_weight_patch(gmag)
    hist, centers = ptool.get_orientation_histogram(gori, gori_weights)

    # Get dominant direction in radians
    kpts2 = TEST_ptool_find_kpts_direction(imgBGR, kpts)
    kpts2, desc2 = pyhesaff.vtool_adapt_rotation(img_fpath, kpts)

    #----------------------#
    # --- Draw Results --- #
    #----------------------#
    f1_loc = TEST_figure1(wpatch, gradx, grady, gmag, gori, hist, centers)
    df2.set_figtitle('Dominant Orienation Extraction')

    TEST_figure2(imgBGR, kpts, desc, sel, fnum=2)
    df2.set_figtitle('Gravity Vector')
    TEST_figure2(imgBGR, kpts2, desc2, sel, fnum=3)
    df2.set_figtitle('Rotation Invariant')

    #df2.draw_keypoint_gradient_orientations(imgBGR, kp=kpts2[sel],
    #                                        sift=desc[sel], mode='vec',
    #                                        fnum=4)

    #df2.draw_vector_field(gradx, grady, pnum=(1, 1, 1), fnum=4)
    #df2.draw_kpts2(np.array([wkp]), sifts=desc[sel:sel + 1], ori=True)
    return locals()
def TEST_keypoint(imgBGR, img_fpath, kpts, desc, sel, fnum=1, figtitle=''):
    from plottool import draw_func2 as df2
    from plottool.viz_keypoints import _annotate_kpts, show_keypoints
    from plottool.viz_featrow import draw_feat_row
    import plottool
    import vtool.patch as ptool
    #----------------------#
    # --- Extract Data --- #
    #----------------------#
    kp = kpts[sel]
    # Extract patches, gradients, and orientations
    print('[rotinvar] 1) Extract patch, gradients, and orientations')
    wpatch, wkp  = ptool.get_warped_patch(imgBGR, kp, gray=True)
    gradx, grady = ptool.patch_gradient(wpatch)
    gmag         = ptool.patch_mag(gradx, grady)
    gori         = ptool.patch_ori(gradx, grady)
    gori_weights = ptool.gaussian_weight_patch(gmag)

    # Get orientation histogram
    print('[rotinvar] 2) Get orientation histogram')
    hist, centers = ptool.get_orientation_histogram(gori, gori_weights)

    #----------------------#
    # --- Draw Results --- #
    #----------------------#
    f1_loc = TEST_figure1(wpatch, gradx, grady, gmag, gori, hist, centers, fnum=fnum)
    df2.set_figtitle(figtitle + 'Dominant Orienation Extraction')

    TEST_figure2(imgBGR, kpts, desc, sel, fnum=fnum + 1)
    df2.set_figtitle(figtitle)
#    TEST_figure2(imgBGR, kpts2, Desc2, sel, fnum=fnum + 2)
#    df2.set_figtitle('Rotation Invariant')

    #df2.draw_keypoint_gradient_orientations(imgBGR, kp=kpts2[sel],
    #                                        sift=desc[sel], mode='vec',
    #                                        fnum=4)

    #df2.draw_vector_field(gradx, grady, pnum=(1, 1, 1), fnum=4)
    #df2.draw_kpts2(np.array([wkp]), sifts=desc[sel:sel + 1], ori=True)
    return locals()
Exemplo n.º 4
0
def TEST_keypoint(imgBGR, img_fpath, kpts, desc, sel):
    import pyhesaff
    #----------------------#
    # --- Extract Data --- #
    #----------------------#
    kp = kpts[sel]
    # Extract patches, gradients, and orientations
    print('[rotinvar] 1) Extract patch, gradients, and orientations')
    wpatch, wkp  = ptool.get_warped_patch(imgBGR, kp, gray=True)
    gradx, grady = ptool.patch_gradient(wpatch, gaussian_weighted=False)
    gmag         = ptool.patch_mag(gradx, grady)
    gori         = ptool.patch_ori(gradx, grady)

    # Get orientation histogram
    print('[rotinvar] 2) Get orientation histogram')
    gori_weights = ptool.gaussian_weight_patch(gmag)
    hist, centers = ptool.get_orientation_histogram(gori, gori_weights)

    # Get dominant direction in radians
    kpts2 = TEST_ptool_find_kpts_direction(imgBGR, kpts)
    kpts2, desc2 = pyhesaff.vtool_adapt_rotation(img_fpath, kpts)

    #----------------------#
    # --- Draw Results --- #
    #----------------------#
    f1_loc = TEST_figure1(wpatch, gradx, grady, gmag, gori, hist, centers)
    df2.set_figtitle('Dominant Orienation Extraction')

    TEST_figure2(imgBGR, kpts, desc, sel, fnum=2)
    df2.set_figtitle('Gravity Vector')
    TEST_figure2(imgBGR, kpts2, desc2, sel, fnum=3)
    df2.set_figtitle('Rotation Invariant')

    #df2.draw_keypoint_gradient_orientations(imgBGR, kp=kpts2[sel],
    #                                        sift=desc[sel], mode='vec',
    #                                        fnum=4)

    #df2.draw_vector_field(gradx, grady, pnum=(1, 1, 1), fnum=4)
    #df2.draw_kpts2(np.array([wkp]), sifts=desc[sel:sel + 1], ori=True)
    return locals()
Exemplo n.º 5
0
def gen_featweight_worker(tup):
    """
    Function to be parallelized by multiprocessing / joblib / whatever.
    Must take in one argument to be used by multiprocessing.map_async

    Args:
        tup (aid, tuple(kpts(ndarray), probchip_fpath )): keypoints and probability chip file path
           aid, kpts, probchip_fpath

    CommandLine:
        python -m ibeis.algo.preproc.preproc_featweight --test-gen_featweight_worker --show
        python -m ibeis.algo.preproc.preproc_featweight --test-gen_featweight_worker --show --dpath figures --save ~/latex/crall-candidacy-2015/figures/gen_featweight.jpg
        python -m ibeis.algo.preproc.preproc_featweight --test-gen_featweight_worker --show --db PZ_MTEST --qaid_list=1,2,3,4,5,6,7,8,9

    Example:
        >>> # ENABLE_DOCTEST
        >>> from ibeis.algo.preproc.preproc_featweight import *  # NOQA
        >>> test_featweight_worker()

    Ignore::
        import plottool as pt
        pt.imshow(probchip_list[0])
        patch_list = [vtpatch.get_warped_patch(probchip, kp)[0].astype(np.float32) / 255.0 for kp in kpts[0:1]]
        patch_ = patch_list[0].copy()
        patch = patch_
        patch = patch_[-20:, :20, 0]

        import vtool as vt
        gaussian_patch = vt.gaussian_patch(patch.shape[1], patch.shape[0], shape=patch.shape[0:2], norm_01=False)

        import cv2
        sigma = 1/10
        xkernel = (cv2.getGaussianKernel(patch.shape[1], sigma))
        ykernel = (cv2.getGaussianKernel(patch.shape[0], sigma))

        #ykernel = ykernel / ykernel.max()
        #xkernel = ykernel / xkernel.max()

        gaussian_kern2 = ykernel.dot(xkernel.T)
        print(gaussian_kern2.sum())

        patch2 = patch.copy()
        patch2 = np.multiply(patch2,   ykernel)
        patch2 = np.multiply(patch2.T, xkernel).T

        if len(patch3.shape) == 2:
            patch3 = patch.copy() * gaussian_patch[:,:]
        else:
            patch3 = patch.copy() * gaussian_patch[:,:, None]

        sum2 = patch2.sum() / (patch2.size)
        sum3 = patch3.sum() / (patch3.size)

        print(sum2)
        print(sum3)

        fig = pt.figure(fnum=1, pnum=(1, 3, 1), doclf=True, docla=True)
        pt.imshow(patch * 255)
        fig = pt.figure(fnum=1, pnum=(1, 3, 2))
        pt.imshow(gaussian_kern2 * 255.0)
        fig = pt.figure(fnum=1, pnum=(1, 3, 3))
        pt.imshow(patch2 * 255.0)
        pt.update()
    """
    (aid, kpts, probchip, chipsize) = tup
    if probchip is None:
        # hack for undetected chips. SETS ALL FEATWEIGHTS TO .25 = 1/4
        weights = np.full(len(kpts), .25, dtype=np.float32)
    else:
        sfx, sfy = (probchip.shape[1] / chipsize[0], probchip.shape[0] / chipsize[1])
        kpts_ = vt.offset_kpts(kpts, (0, 0), (sfx, sfy))
        #vtpatch.get_warped_patches()
        patch_list  = [vtpatch.get_warped_patch(probchip, kp)[0].astype(np.float32) / 255.0
                       for kp in kpts_]
        weight_list = [vtpatch.gaussian_average_patch(patch) for patch in patch_list]
        #weight_list = [patch.sum() / (patch.size) for patch in patch_list]
        weights = np.array(weight_list, dtype=np.float32)
    return (aid, weights)