Exemplo n.º 1
0
out_inliers = torch.zeros(log_probs.size())  # inlier mask of estimated model
out_gradients = torch.zeros(
    log_probs.size())  # gradient tensor (only used during training)
rand_seed = 0  # random seed to by used in C++

# run NG-RANSAC
if opt.fmat:

    # === CASE FUNDAMENTAL MATRIX =========================================

    # undo normalization of x and y image coordinates
    util.denormalize_pts(correspondences[0:2], img1.shape)
    util.denormalize_pts(correspondences[2:4], img2.shape)

    incount = ngransac.find_fundamental_mat(correspondences, probs, rand_seed,
                                            opt.hyps, opt.threshold,
                                            opt.refine, out_model, out_inliers,
                                            out_gradients)
else:

    # === CASE ESSENTIAL MATRIX =========================================

    incount = ngransac.find_essential_mat(correspondences, probs, rand_seed,
                                          opt.hyps, opt.threshold, out_model,
                                          out_inliers, out_gradients)

print("\n=== Model found by NG-RANSAC: =======\n")
print(out_model.numpy())

print("\nNG-RANSAC Inliers: ", int(incount))

# create a visualization of the matching, comparing results of RANSAC and NG-RANSAC
Exemplo n.º 2
0
                    0, 10000)  # provide a random seed for C++

                if opt.fmat:

                    # === CASE FUNDAMENTAL MATRIX =========================================

                    # restore pixel coordinates
                    util.denormalize_pts(correspondences[b, 0:2], im_size1[b])
                    util.denormalize_pts(correspondences[b, 2:4], im_size2[b])

                    F = torch.zeros((3, 3))

                    #run NG-RANSAC
                    start_time = time.time()
                    incount = ngransac.find_fundamental_mat(
                        correspondences[b], probs[b], rand_seed, opt.hyps,
                        opt.threshold, opt.refine, F, inliers, gradients)
                    ransac_time += time.time() - start_time

                    # essential matrix from fundamental matrix (for evaluation via relative pose)
                    E = K2[b].transpose(0, 1).mm(F.mm(K1[b]))

                    pts1 = correspondences[b, 0:2].numpy()
                    pts2 = correspondences[b, 2:4].numpy()

                    # evaluation of F matrix via correspondences
                    valid, F1, epi_inliers, epi_error = util.f_error(
                        pts1, pts2, F.numpy(), gt_F[b].numpy(), opt.threshold)

                    if valid:
                        avg_F1 += F1