def detect(detector, fn, splt_num=64, simu_type="default"): full_fn = myfsys.get_template_file_full_path_(fn) img = read_image(full_fn) cv2.imshow('hoge', img) with Timer('Detection with [ ' + simu_type + ' ]'): splt_kp, splt_desc = spltA.affine_detect_into_mesh(detector, splt_num, img, simu_param=simu_type) return img, splt_kp, splt_desc
def expt_meshdtct_perf_spltASIFT(column_num = 8, row_num = 8, template_f = 'qrmarker.png'): split_num = column_num * row_num template_fn = myfsys.get_template_file_full_path_(template_f) detector, matcher = init_feature(emod.Features.SIFT) imgQ, s_kpQ, s_descQ = split_asift_detect(detector, template_fn, split_num=split_num) keyargs = {'prefix_shape': emod.PrefixShapes.PL.value, 'template_fn': template_fn} testset_full_path = myfsys.get_dir_full_path_testset('cgs', **keyargs) print(testset_full_path) testcase_fns = os.listdir(testset_full_path) testcase_fns.sort() print(testcase_fns) results = [] for input_fns in testcase_fns: calculate_each_mesh(column_num, detector, input_fns, matcher, results, row_num, s_descQ, s_kpQ)
logging.getLogger('my_file_path_manager').setLevel(level=logging.DEBUG) logging.getLogger('my_file_path_manager').addHandler(timeRotationHandler) logging.getLogger('my_file_path_manager').addHandler(consoleHandler) logger.info(__doc__.format(os.path.basename(__file__))) a = myfsys.make_list_template_filename() a = emod.only(a, 'glass.png') detector, matcher = init_feature(emod.Features.SIFT.name) column_num = 8 row_num = 8 split_num = column_num * row_num expt_name = os.path.basename(expt_path) for template_fn in a: logger.info('Template:{}'.format(template_fn)) # global s_kpQ, s_descQ, testset_full_path template_full_fn = myfsys.get_template_file_full_path_(template_fn) # imgQ, s_kpQ, s_descQ = split_asift_detect(detector, template_full_fn, split_num=split_num) keyargs = {'prefix_shape': emod.PrefixShapes.PL.value, 'template_fn': template_fn} testset_full_path = myfsys.get_dir_full_path_testset('cgs', **keyargs) testset_name = os.path.basename(testset_full_path) logger.debug('testset_name is {}'.format(testset_name)) logger.info('Test Set:{}'.format(testset_name)) output_dir = myfsys.setup_output_directory(expt_name, testset_name, 'npfiles') testcase_fns = os.listdir(testset_full_path) testcase_fns.sort() print(testcase_fns) # dictionary = exam(testset_full_path, s_kpQ, s_descQ) # np.savez_compressed(os.path.join(expt_path, testset_name), **dictionary) # result_collection = np.load(os.path.join(expt_path, testset_name+'.npz'))
timeRotationHandler) logging.getLogger('commons.my_file_path_manager').addHandler( consoleHandler) logger.info(__doc__.format(os.path.basename(__file__))) import sys, getopt opts, args = getopt.getopt(sys.argv[1:], '', ['feature=']) opts = dict(opts) feature_name = opts.get('--feature', 'sift') try: fn1, fn2, column_num, row_num = args except: dir = os.path.abspath( os.path.join(os.path.dirname(__file__), os.pardir, os.pardir)) fn1 = myfsys.get_template_file_full_path_('qrmarker.png') fn2 = os.path.abspath( os.path.join(dir, 'data/inputs/cgs/pl_qrmarker/288_010-350.png')) column_num = 8 row_num = 8 detector, matcher = init_feature(feature_name) if detector is None: logger.info('unknown feature:{}'.format(feature_name)) sys.exit(1) split_num = column_num * row_num img_q, splt_kp_q, splt_desc_q = split_asift_detect(detector, fn1, split_num)
def asfit(): pass if __name__ == '__main__': expt_path = setup_expt_directory() logging.basicConfig(filename=os.path.join(expt_path, 'log.txt'), level=logging.DEBUG) logger.info(__doc__.format(os.path.basename(__file__))) a = os.listdir(myfsys.get_dir_full_path_(DirNames.TEMPLATES.value)) a.pop(a.index('mesh_label.png')) detector, matcher = init_feature(Features.SIFT.name) for testcase in a: logger.info(testcase + 'の場合') fn = myfsys.get_template_file_full_path_(testcase) imgQ, kpQ, descQ = asift_detect(detector, fn) imgT, kpT, descT = asift_detect(detector, fn) logger.info('imgQ - %d features, imgT - %d features' % (len(kpQ), len(kpT))) with Timer('matching'): pQ, pT, pairs = match_with_cross(matcher, descQ, kpQ, descT, kpT) if len(pQ) >= 4: H, status = cv2.findHomography(pQ, pT, cv2.RANSAC, 5.0) logger.info('%d / %d inliers/matched' % (np.sum(status), len(status))) # do not draw outliers (there will be a lot of them) pairs = [kpp for kpp, flag in zip(pairs, status) if flag] else: H, status = None, None logger.info(