Skip to content

Commit

Permalink
Merge pull request #24 from adisingh50/master
Browse files Browse the repository at this point in the history
Added Pybind Wrapper for COLMAP's Homography Decomposition Function
  • Loading branch information
mihaidusmanu committed Dec 2, 2021
2 parents f61f11c + c1d17e0 commit 564cd21
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 0 deletions.
54 changes: 54 additions & 0 deletions homography_decomposition.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
#include <iostream>
#include <fstream>

#include "colmap/base/homography_matrix.h"

using namespace colmap;

#include <pybind11/pybind11.h>
#include <pybind11/stl.h>
#include <pybind11/eigen.h>

namespace py = pybind11;

/**
* Recover the most probable pose from the inputted homography matrix.
*
* @param H 3x3 homography matrix.
* @param K1 3x3 intrinsics matrix for first camera.
* @param K2 3x3 intrinsics matrix for second camera.
* @param points1 First set of corresponding points: normalized beforehand.
* @param points2 Second set of corresponding points: normalized beforehand.
* @return The most probable rotation matrix (3x3), translation vector (3x1), normal vector (3x1),
* and triangulated 3D points.
*/
py::dict homography_decomposition_estimation (
const Eigen::Matrix3d H,
const Eigen::Matrix3d K1,
const Eigen::Matrix3d K2,
const std::vector<Eigen::Vector2d> points1,
const std::vector<Eigen::Vector2d> points2
) {
SetPRNGSeed(0);

// Check that both vectors have the same size.
assert(points1.size() == points2.size());

Eigen::Matrix3d R;
Eigen::Vector3d t;
Eigen::Vector3d n;
std::vector<Eigen::Vector3d> points3D;

// Homography Decomposition Estimation
PoseFromHomographyMatrix(H, K1, K2, points1, points2, &R, &t, &n, &points3D);

// Success output dictionary.
py::dict success_dict;
success_dict["success"] = true;
success_dict["R"] = R;
success_dict["t"] = t;
success_dict["n"] = n;
success_dict["points3D"] = points3D;

return success_dict;
}
10 changes: 10 additions & 0 deletions main.cc
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ namespace py = pybind11;
#include "generalized_absolute_pose.cc"
#include "essential_matrix.cc"
#include "fundamental_matrix.cc"
#include "homography_decomposition.cc"
#include "transformations.cc"
#include "sift.cc"
#include "pose_refinement.cc"
Expand Down Expand Up @@ -56,6 +57,15 @@ PYBIND11_MODULE(pycolmap, m) {
py::arg("confidence") = 0.9999,
"LORANSAC + 7-point algorithm.");

// Homography Decomposition.
m.def("homography_decomposition", &homography_decomposition_estimation,
py::arg("H"),
py::arg("K1"),
py::arg("K2"),
py::arg("points1"),
py::arg("points2"),
"Analytical Homography Decomposition.");

// Image-to-world and world-to-image.
m.def("image_to_world", &image_to_world, "Image to world transformation.");
m.def("world_to_image", &world_to_image, "World to image transformation.");
Expand Down

0 comments on commit 564cd21

Please sign in to comment.