def fitter_main(args, fitter): world_points = gen_target.get_targets() optlist, _ = getopt.getopt(args[1:], "i:o:") in_file_name = None out_file_name = None for opt, param in optlist: if opt == "-i": in_file_name = param if opt == "-o": out_file_name = param if not in_file_name: raise Exception("Usage: %s -i <input image> [-o <output image>]" % args[0]) print "Loading image (black and white)" image = cv.LoadImage(in_file_name, False) print "Loading image (colour)" color_image = cv.LoadImage(in_file_name, True) print "Finding labelled circles" image_features = find_circles.find_labelled_circles(image, annotate_image=color_image, find_ellipses=True) print "Solving" R, T, pixel_scale = fitter.solve(world_points, image_features, pixel_scale=2986.3, annotate_image=color_image) print R, T, pixel_scale err = calc_reprojection_error(R, T, pixel_scale, world_points, image_features) print "Reprojection error: %f" % err draw_reprojected(R, T, pixel_scale, world_points, color_image) if out_file_name: cv.SaveImage(out_file_name, color_image)
print "---" print matrix([[px2 - px1, py2 - py1]]) J = make_barrel_distortion_jacobian(bd, sx, sy) print (J * matrix([[dsx, dsy, dbd]]).T).T class CalibrateParser(argparse.ArgumentParser): def __init__(self): super(CalibrateParser, self).__init__(description='Calibrate a camera') self.add_argument('-i', '--input-images', nargs='+', help='Input image', required=True) if __name__ == "__main__": args = CalibrateParser().parse_args() world_circles = gen_target.get_targets() in_file_names = args.input_images out_file_names = ["calibrated-%u.png" % i for i in range(len(in_file_names))] print in_file_names if not in_file_names: raise Exception("Usage: %s -i <input image> [-o <output image>]" % sys.argv[0]) print "Loading images (black and white)" images = [cv.LoadImage(in_file_name, False) for in_file_name in in_file_names] print "Loading image (colour)" color_images = [cv.LoadImage(in_file_name, True) for in_file_name in in_file_names] print "Finding labelled circles" image_circles = [find_circles.find_labelled_circles(image,