Exemple #1
0
def main():
	global _threadError

	num_threads = os.cpu_count() * 2
	root_dir = path.join(utils.get_script_folder(), '..')
	docs_dir = path.join(root_dir, 'docs')
	xml_dir = path.join(docs_dir, 'xml')
	html_dir = path.join(docs_dir, 'html')
	mcss_dir = path.join(root_dir, 'extern', 'mcss')
	doxygen = path.join(mcss_dir, 'documentation', 'doxygen.py')

	# delete any leftovers from the previous run
	if 1:
		utils.delete_directory(xml_dir)
		utils.delete_directory(html_dir)

	# run doxygen to generate the xml
	if 1:
		subprocess.check_call( ['doxygen', 'Doxyfile'], shell=True, cwd=docs_dir )

	# fix some shit that's broken in the xml
	if 1:
		preprocess_xml(xml_dir)

	# run doxygen.py (m.css) to generate the html
	if 1:
		utils.run_python_script(doxygen, path.join(docs_dir, 'Doxyfile-mcss'), '--no-doxygen')

	# post-process html files
	if 1:
		fixes = [
			CustomTagsFix()
			, SyntaxHighlightingFix()
			, IndexPageFix()
			, ModifiersFix1()
			, ModifiersFix2()
			, ExtDocLinksFix()
			, EnableIfFix()
			, ExternalLinksFix()
			, TemplateTemplateFix()
		]
		files = [path.split(f) for f in utils.get_all_files(html_dir, any=('*.html', '*.htm'))]
		if files:
			with futures.ThreadPoolExecutor(max_workers=min(len(files), num_threads)) as executor:
				jobs = { executor.submit(postprocess_file, dir, file, fixes) : file for dir, file in files }
				for job in futures.as_completed(jobs):
					if _threadError:
						executor.shutdown(False)
						break
					else:
						file = jobs[job]
						print('Finished processing {}.'.format(file))
			if _threadError:
				return 1
Exemple #2
0
def main():
    # feature mode
    ap = argparse.ArgumentParser()

    # Add the arguments to the parser
    ap.add_argument(
        "-f",
        "--feature",
        required=True,
        help="The feature to perform: 'convolutions' or 'template_matching'")

    ap.add_argument("-m",
                    "--mode",
                    required=True,
                    help="The mode of operation: 'train' or 'test'")

    ap.add_argument("-i",
                    "--image",
                    required=False,
                    help="The image to perform the convolution on")

    args = vars(ap.parse_args())

    feature = args['feature']
    mode = args['mode']

    if feature == 'optimise':
        optimise_parameters()

    if feature == config.CONVOLUTIONS_ARG:
        image_dir = args['image']
        if image_dir is None:
            raise Exception(
                "Please enter the path to the image to perform the convolution on."
            )

        if not os.path.exists(image_dir):
            raise Exception(
                "The image at the specified directory was not found.")

        convolute(image_dir)

    if feature == config.TEMPLATE_MATCHING_ARG:
        # Perform template matching
        if mode == config.TRAINING_ARG:
            utils.delete_directory(config.TEMPLATE_OUTPUT_DIR)
            return template_matching(config.TRAINING_DIR,
                                     config.TEMPLATE_OUTPUT_DIR)

        image = test_template_matching(config.TESTING_DIR,
                                       config.TEMPLATE_OUTPUT_DIR)[0]
        cv2.imshow('test-2', image)
        cv2.waitKey(0)
        cv2.destroyAllWindows()
Exemple #3
0
def optimise_parameters():
    pyramid_levels = [3, 4, 5]
    # pyramid_levels = [x for x in range(3,6)]
    rotations = [[x for x in range(0, 360, rot)] for rot in range(20, 35, 5)]
    gaussian_parameters = [[5, 5, 15]]

    # Create results directory
    utils.create_directory(config.RESULTS_DIR)

    for level in pyramid_levels:
        for rots in rotations:
            for g_n, gaussian in enumerate(gaussian_parameters):
                step_size = rots[1] - rots[0]
                row, col, dev = gaussian
                g = utils.gaussian_kernel(row, col, dev)
                utils.delete_directory(config.TEMPLATE_OUTPUT_DIR)
                print(
                    'training rotation {} level {} gaussian {}-{}-{}'.format(
                        step_size, level, row, col, dev), rots, level)

                start = time.time()

                template_matching(config.TRAINING_DIR,
                                  config.TEMPLATE_OUTPUT_DIR, level, rots, g)
                new_dir = config.RESULTS_DIR + 'level{}-rot{}-g-{}-{}-{}/'.format(
                    level, step_size, row, col, dev)
                utils.create_directory(new_dir)
                print('testing', rots, level)
                images = test_template_matching(config.TESTING_DIR,
                                                config.TEMPLATE_OUTPUT_DIR)
                end = time.time()
                time_elapsed = end - start
                utils.write_to_file(new_dir + 'time.txt', time_elapsed)

                for idx, im in enumerate(images):
                    cv2.imwrite(new_dir + '{}.png'.format(idx), im)

    return True
Exemple #4
0
 def clean(self):
     delete_directory(self.root)