0]  #zero-indexing creates and removes a dummy batch dimension
probs = torch.exp(log_probs).cpu()

out_model = torch.zeros((3, 3)).float()  # estimated model
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")
Beispiel #2
0
            for b in range(correspondences.size(0)):

                gradients = torch.zeros(
                    probs[b].size()
                )  # not used in test mode, indicates which correspondence have been sampled
                inliers = torch.zeros(
                    probs[b].size())  # inlier mask of winning model
                rand_seed = random.randint(
                    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()