# XXX hack try: codegen_args = eval(options.codegen_args) if not isinstance(codegen_args, dict): raise TypeError() except: print 'error: unable to parse the codegen argument' print ' please enclose the dict in double quotes' print ' raw args: >>>%s<<<'%options.codegen_args exit(1) # load codegen from codegen import load_codegen, wrap_codegen, get_codegen_parameters from codegen import InvalidCodegenArgumentsException module_name, codegen_name = options.codegen_impl.split('.') codegen_impl = load_codegen(module_name, codegen_name) if not codegen_impl: print 'error: could not load codegen %s'%codegen_impl exit(1) try: wrapped_impl = wrap_codegen(codegen_impl, block_size, codegen_args) except InvalidCodegenArgumentsException: argstr = ', '.join(get_codegen_parameters(codegen_impl, True)) print 'error: invalid arguments for codegen, needed arguments are [%s]'%argstr exit(1) images = png_images_from_directory(options.source_dir) for i, res in enumerate(process_image_sequence(wrapped_impl, block_size, images)): imageio.write('res_%06i.png'%i, res, 1)
scale_factor = 1.2 min_size = (40, 40) if not os.path.isdir(output_dir): print 'warning: creating outputdir %s'%output_dir os.mkdir(output_dir) for i, image_filename in enumerate(image_filenames): image = imageio.read(image_filename) # process image detected_faces = [] reject_stage = None if use_multiscale: raise Exception('need to implement multiscale edit') detected_faces, reject_stage = detect_faces_multiscale(image, haar_classifier, scale_factor, min_size) else: detected_faces, reject_stage = detect_faces_idle_raport(image, haar_classifier) res = visualisation.draw_faces(image, detected_faces) imageio.write(output_dir + os.path.sep + 'res_%06i.png'%i, res, 3) imageio.write(output_dir + os.path.sep + 'reject_%06i.png'%i, reject_stage, 1) f = open(output_dir + os.path.sep + 'detections_%06i.txt'%i, 'w') f.write('\n'.join(str(x) for x in detected_faces)) f.close()
else: raise ValueError() result.apply_to(image) if __name__ == '__main__': import imageio from argparse import ArgumentParser parser = ArgumentParser(description='Scale image') parser.add_argument('input_file', metavar='image', help='') parser.add_argument('-o', '--out', dest='output_file', nargs='?', help='') parser.add_argument('-m', '--method', dest='method', nargs='?', choices=['prewitt', 'sobel', 'laplace'], default='prewitt', help='') parser.add_argument('-n', '--negative', dest='negative', action='store_true') args = parser.parse_args() input_file = args.input_file output_file = args.output_file or input_file image = imageio.read(input_file) apply_border_detection(image, args.method) if args.negative: negative.apply_negative(image) imageio.write(image, output_file)
print 'failed to wrap codegen' print '@'*100 print 'wrapped codegen' print '\n'.join(str(x) for x in wrapped_impl(codegen.Code())) code = codegen.Code() code.set_generator(wrapped_impl) # load image im_name = 'data' + os.path.sep + 'lena_crop.png' image = imageio.read(im_name) # actually run code print '@'*100 print 'run interpreter' interpreter = interpreter.Interpreter(code, image, block_size, 4, nr_registers) try: interpreter.run_kernel() except Exception, e: print str(e) traceback.print_tb(sys.exc_traceback) pdb.post_mortem(sys.exc_traceback) # write output output_filename = 'test.png' out_image = interpreter.gen_output_image() imageio.write(output_filename, out_image, 1)