Exemple #1
0
 def test_cross_ORB(self):
     feature_name = self.opts.get('--feature', 'orb-flann')
     detector, matcher = init_feature(feature_name)
     with Timer('affine simulation detecting'):
         kp1, desc1 = ab.affine_detect(detector, self.img1) #ASIFT
     with Timer('Feature detecting'):
         h, w = self.img2.shape[:2]
         mask = np.zeros((h, w), np.uint8)
         mask[:] = 255
         kp2, desc2 = ab.affine_detect(detector, self.img2) #ASIFT
     print('imgQ - %d features, imgT - %d features' % (len(kp1), len(kp2)))
     with Timer('matching'):
         raw_matches12 = matcher.knnMatch(desc2, trainDescriptors=desc1, k=2) #2
         raw_matches21 = matcher.knnMatch(desc1, trainDescriptors=desc2, k=2) #2
     p2, p1, kp_pairs = filter_matches_wcross(kp1, kp2, raw_matches12, raw_matches21)
     print('matched points T=%d, Q=%d' % (len(p1), len(p2)))
     self.assertEqual(len(p1), len(p2), "Not same numbers")
Exemple #2
0
 def test_cross_check_same(self):
     feature_name = self.opts.get('--feature', 'sift')
     detector, matcher = init_feature(feature_name)
     with Timer('Feature detecting'):
         h, w = self.img1.shape[:2]
         mask = np.zeros((h, w), np.uint8)
         mask[:] = 255
         kp1, desc1 = detector.detectAndCompute(self.img1, mask)
     with Timer('Feature detecting'):
         h, w = self.img2.shape[:2]
         mask = np.zeros((h, w), np.uint8)
         mask[:] = 255
         kp2, desc2 = detector.detectAndCompute(self.img2, mask)
     print('imgQ - %d features, imgT - %d features' % (len(kp1), len(kp2)))
     with Timer('matching'):
         raw_matches12 = matcher.knnMatch(desc2, trainDescriptors=desc1, k=2) #2
         raw_matches21 = matcher.knnMatch(desc1, trainDescriptors=desc2, k=2) #2
     p2, p1, kp_pairs = filter_matches_wcross(kp1, kp2, raw_matches12, raw_matches21)
     print('matched points T=%d, Q=%d' % (len(p1), len(p2)))
     self.assertEqual(len(p1), len(p2), "Not same numbers")
Exemple #3
0
    def setUp(self):
        """ Set up befor test
        Using templates is qr.png
        Using input test image is 1.png
        Using feature function is SIFT
        Using split mesh number is 64
        """
        import sys, getopt
        opts, args = getopt.getopt(sys.argv[1:], '', ['feature='])
        opts = dict(opts)
        feature_name = opts.get('--feature', 'sift')
        try:
            fn1, fn2 = args
        except:
            import os
            dir = os.path.abspath(
                os.path.join(os.path.dirname(__file__), os.pardir, os.pardir,
                             os.pardir))
            fn1 = os.path.abspath(
                os.path.join(dir, 'data/templates/qrmarker.png'))
            fn2 = os.path.abspath(
                os.path.join(dir, 'data/templates/qrmarker.png'))
            #fn2 = os.path.abspath(os.path.join(dir_path_full, 'data/inputs/unittest/smpl_1.414214_152.735065.png'))

        self.img1 = cv2.imread(fn1, 0)
        self.img2 = cv2.imread(fn2, 0)
        self.detector, self.matcher = init_feature(feature_name)
        self.splt_num = 64
        if self.img1 is None:
            print('Failed to load fn1:', fn1)
            sys.exit(1)

        if self.img2 is None:
            print('Failed to load fn2:', fn2)
            sys.exit(1)

        if self.detector is None:
            print('unknown feature:', feature_name)
            sys.exit(1)
Exemple #4
0
def test_module():
    import os
    import sys
    dir = os.path.abspath(os.path.join(os.path.dirname(__file__), os.pardir, os.pardir))
    fn1 = os.path.abspath(os.path.join(dir, 'data/templates/qrmarker.png'))
    fn2 = os.path.abspath(os.path.join(dir, 'data/inputs/unittest/smpl_1.414214_152.735065.png'))
    imgQ = cv2.imread(fn1, 0)
    imgT = cv2.imread(fn2, 0)
    detector, matcher = init_feature('sift')
    if imgQ is None:
        print('Failed to load fn1:', fn1)
        sys.exit(1)

    if imgT is None:
        print('Failed to load fn2:', fn2)
        sys.exit(1)

    if detector is None:
        print('unknown feature:', feature_name)
        sys.exit(1)

    template_information = {"_fn": "tmp.png", "_cols": 800, "_rows": 600, "_scols": 8, "_srows": 8, "_nneighbor": 4}
    temp_inf = TmpInf(**template_information)
    return temp_inf, imgQ, imgT, detector, matcher
Exemple #5
0
    opts, args = getopt.getopt(sys.argv[1:], '', ['feature='])
    opts = dict(opts)
    feature_name = opts.get('--feature', 'sift')
    try:
        fn1, fn2 = args
    except:
        import os

        dir = os.path.abspath(os.path.join(os.path.dirname(__file__), os.pardir, os.pardir))
        fn1 = os.path.abspath(os.path.join(dir, 'data/templates/qrmarker.png'))
        fn2 = os.path.abspath(os.path.join(dir, 'data/inputs/unittest/smpl_1.414214_152.735065.png'))

    imgQ = cv2.imread(fn1, 0)
    imgT = cv2.imread(fn2, 0)
    detector, matcher = init_feature(feature_name)

    if imgQ is None:
        print('Failed to load fn1:', fn1)
        sys.exit(1)
    print("Using Query: {}".format(fn1))
    if imgT is None:
        print('Failed to load fn2:', fn2)
        sys.exit(1)
    print("Using Training: {}".format(fn2))
    if detector is None:
        print('unknown feature:', feature_name)
        sys.exit(1)
    print('Using :', feature_name)

    template_fn, ext = os.path.splitext(os.path.basename(fn1))
Exemple #6
0
    visS = draw_matches_for_meshes(imgQ, imgT, Hs=Hs_stable)
    cv2.imwrite(myfsys.getf_output(expt_names, 'meshes_stable.png'), visS)

    viw = explore_match_for_meshes('affine find_obj', imgQ, imgT, kp_pairs_long_stable, Hs=Hs_stable)
    cv2.imwrite(myfsys.getf_output(expt_names, 'meshes_and_keypoints_stable.png'), viw)

    return vis, visS, viw


if __name__ == '__main__':
    expt_path = myfsys.setup_expt_directory(os.path.basename(__file__))
    logging.basicConfig(filename=os.path.join(expt_path, 'log.txt'), level=logging.DEBUG)
    a = os.listdir(myfsys.get_dir_full_path_(myfsys.DirNames.TEMPLATES.value))
    a.pop(a.index('mesh_label.png'))
    detector, matcher = init_feature(emod.Features.SIFT.name)
    for template in a:
        template_name, ext = template.split('.')
        print(template_name)
        fn = myfsys.get_template_file_full_path_(template)
        imgQ, kpQ, descQ = detect(detector, fn, splt_num=64, simu_type='asift')
        #実験は平面のみ
        subj_dir = emod.PrefixShapes.PL.value + template_name
        testsets = os.listdir(myfsys.get_inputs_dir_full_path(subj_dir))
        for testcase in testsets:
            print(myfsys.getf_input(subj_dir, testcase))


        # fnQ = ('qrmarker.png', 'menko.png', 'nabe.png', 'nabe.png', 'nabe.png')
        # dirT = ('unittest', 'crv_menko', 'pics_nabe', 'real-crv_nabe', 'mltf_nabe')
        # fnT = ('smpl_1.414214_152.735065.png', 'smpl_2.828427_152.735065.png', 'IMG_1118.JPG', 'my_photo-5.jpg', 'smpl_1.414214_152.735065.png')