def calibrate(star_to_pixel, image_size, annotate_image=None):
    print "Loading database..."
    db = stardb.StarDatabase(stardb.hip_star_gen('data/hip_main.dat'))

    world_points = dict(
        (star_name, tuple(10000. * numpy.array(db[star_name].vec).flatten()))
            for star_name in star_to_pixel.keys())

    image_points = dict((name, (pos[0] - (image_size[0] / 2),
                                (image_size[1] / 2) - pos[1]))
                            for name, pos in star_to_pixel.iteritems())
    
    print "Solving"
    return fit_lm.solve(world_points, [image_points],
                 annotate_images=[annotate_image],
                 initial_matrices=[numpy.identity(4)],
                 change_ps=True, change_bd=True, change_pos=False)
Esempio n. 2
0
    if args.xy_list is None and args.cat_file is None:
        print "%f: Generating augmented xy-list" % time.clock()
        args.xy_list = "temp.axy"
        rc = subprocess.call(["augment-xylist",
                              "-i",
                              args.input_image,
                              "-o",
                              args.xy_list])
        if rc != 0:
            raise Exception("augment-xylist returned %u" % rc)

    print "%f: Loading input image" % time.clock()
    image = cv.LoadImage(args.input_image, True)

    print "%f: Building star database..." % time.clock()
    star_db = stardb.StarDatabase(stardb.hip_star_gen('data/hip_main.dat'))

    print "%f: Building asterism database..." % time.clock()
    ast_db = AsterismDatabase(asterisms_gen(star_db))

    print "%f: Aligning image" % time.clock()
    ps = args.pixel_scale * min(image.width, image.height) / 2592.
    bd = args.barrel_distortion * (2592. / min(image.width, image.height))**2
    cam_model = camera.BarrelDistortionCameraModel(ps, bd, image.width, image.height)
    if args.xy_list is not None:
        image_stars = stardb.xy_list_star_gen(args.xy_list, cam_model)
    elif args.cat_file is not None:
        image_stars = stardb.cat_star_gen(args.cat_file, cam_model)
    else:
        raise Exception("No xy points specified")