Exemplo n.º 1
0
frames_ref = mrcal.rt_from_Rt(Rt_cam0_board_ref)

############# I have perfect observations in q_ref. I corrupt them by noise
# weight has shape (Nframes, Ncameras, Nh, Nw),
weight01 = (np.random.rand(*q_ref.shape[:-1]) + 1.) / 2.  # in [0,1]
weight0 = 0.2
weight1 = 1.0
weight = weight0 + (weight1 - weight0) * weight01

# I want observations of shape (Nframes*Ncameras, Nh, Nw, 3) where each row is
# (x,y,weight)
observations_ref = nps.clump(nps.glue(q_ref, nps.dummy(weight, -1), axis=-1),
                             n=2)

q_noise, observations = sample_dqref(observations_ref,
                                     pixel_uncertainty_stdev,
                                     make_outliers=True)

############# Now I pretend that the noisy observations are all I got, and I run
############# a calibration from those

# Dense observations. All the cameras see all the boards
indices_frame_camera = np.zeros((Nframes * Ncameras, 2), dtype=np.int32)
indices_frame = indices_frame_camera[:, 0].reshape(Nframes, Ncameras)
indices_frame.setfield(nps.outer(np.arange(Nframes, dtype=np.int32),
                                 np.ones((Ncameras, ), dtype=np.int32)),
                       dtype=np.int32)
indices_camera = indices_frame_camera[:, 1].reshape(Nframes, Ncameras)
indices_camera.setfield(nps.outer(np.ones((Nframes, ), dtype=np.int32),
                                  np.arange(Ncameras, dtype=np.int32)),
                        dtype=np.int32)
Exemplo n.º 2
0
indices_frame = indices_frame_camera[:, 0].reshape(Nframes, Ncameras)
indices_frame.setfield(nps.outer(np.arange(Nframes, dtype=np.int32),
                                 np.ones((Ncameras, ), dtype=np.int32)),
                       dtype=np.int32)
indices_camera = indices_frame_camera[:, 1].reshape(Nframes, Ncameras)
indices_camera.setfield(nps.outer(np.ones((Nframes, ), dtype=np.int32),
                                  np.arange(Ncameras, dtype=np.int32)),
                        dtype=np.int32)

indices_frame_camintrinsics_camextrinsics = \
    nps.glue(indices_frame_camera,
             indices_frame_camera[:,(1,)] - 1,
             axis=-1)

# Add a bit of noise to make my baseline not perfect
_, observations_baseline = sample_dqref(observations_ref,
                                        pixel_uncertainty_stdev)
baseline = \
    dict(intrinsics                                = intrinsics_ref,
         extrinsics_rt_fromref                     = extrinsics_ref,
         frames_rt_toref                           = frames_ref,
         points                                    = None,
         observations_board                        = observations_baseline,
         indices_frame_camintrinsics_camextrinsics = indices_frame_camintrinsics_camextrinsics,
         observations_point                        = None,
         indices_point_camintrinsics_camextrinsics = None,
         lensmodel                                 = lensmodel,
         do_optimize_calobject_warp                = True,
         calobject_warp                            = calobject_warp_ref,
         do_optimize_intrinsics_core               = True,
         do_optimize_intrinsics_distortions        = True,
         do_optimize_extrinsics                    = True,
Exemplo n.º 3
0
    testutils.finish()
    sys.exit()

intrinsics_sampled = np.zeros((args.Nsamples, args.Ncameras, Nintrinsics),
                              dtype=float)
extrinsics_sampled_mounted = np.zeros((args.Nsamples, args.Ncameras, 6),
                                      dtype=float)
frames_sampled = np.zeros((args.Nsamples, args.Nframes, 6), dtype=float)
calobject_warp_sampled = np.zeros((args.Nsamples, 2), dtype=float)

for isample in range(args.Nsamples):
    print(f"Sampling {isample+1}/{args.Nsamples}")

    optimization_inputs = copy.deepcopy(optimization_inputs_baseline)
    optimization_inputs['observations_board'] = \
        sample_dqref(observations_true, pixel_uncertainty_stdev)[1]
    mrcal.optimize(**optimization_inputs)

    intrinsics_sampled[isample, ...] = optimization_inputs['intrinsics']
    frames_sampled[isample, ...] = optimization_inputs['frames_rt_toref']
    calobject_warp_sampled[isample,
                           ...] = optimization_inputs['calobject_warp']
    if fixedframes:
        extrinsics_sampled_mounted[
            isample, ...] = optimization_inputs['extrinsics_rt_fromref']
    else:
        # the remaining row is already 0
        extrinsics_sampled_mounted[
            isample, 1:, ...] = optimization_inputs['extrinsics_rt_fromref']