Skip to content

Commit

Permalink
Port essential and fundamental matrix (cvg#9)
Browse files Browse the repository at this point in the history
* endpoints triangulation as an option. port output folder.

* fix depth-based scoring for endpoints triangulation.

* bind essential and fundamental matrix.
  • Loading branch information
B1ueber2y authored Oct 27, 2022
1 parent 1ee5c3b commit f0d0157
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 6 deletions.
2 changes: 2 additions & 0 deletions limap/triangulation/bindings.cc
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ void bind_functions(py::module &m) {

m.def("get_normal_direction", &getNormalDirection);
m.def("get_direction_from_VP", &getDirectionFromVP);
m.def("compute_essential_matrix", &compute_essential_matrix);
m.def("compute_fundamental_matrix", &compute_fundamental_matrix);
m.def("compute_epipolar_IoU", &compute_epipolar_IoU);
m.def("triangulate_endpoints", &triangulate_endpoints);
m.def("triangulate", &triangulate);
Expand Down
22 changes: 16 additions & 6 deletions limap/triangulation/functions.cc
Original file line number Diff line number Diff line change
Expand Up @@ -39,14 +39,10 @@ V3D getDirectionFromVP(const V3D& vp, const CameraView& view) {
return direc.normalized();
}

double compute_epipolar_IoU(const Line2d& l1, const CameraView& view1,
const Line2d& l2, const CameraView& view2)
M3D compute_essential_matrix(const CameraView& view1, const CameraView& view2)
{
const M3D K1_inv = view1.K_inv();
const M3D R1 = view1.R();
const V3D T1 = view1.T();

const M3D K2_inv = view2.K_inv();
const M3D R2 = view2.R();
const V3D T2 = view2.T();

Expand All @@ -60,7 +56,21 @@ double compute_epipolar_IoU(const Line2d& l1, const CameraView& view1,
tskew(1, 0) = relT[2]; tskew(1, 1) = 0.0; tskew(1, 2) = -relT[0];
tskew(2, 0) = -relT[1]; tskew(2, 1) = relT[0]; tskew(2, 2) = 0.0;
M3D E = tskew * relR;
M3D F = K2_inv.transpose() * E * K1_inv;
return E;
}

M3D compute_fundamental_matrix(const CameraView& view1, const CameraView& view2)
{
M3D E = compute_essential_matrix(view1, view2);
M3D F = view2.K_inv().transpose() * E * view1.K_inv();
return F;
}

double compute_epipolar_IoU(const Line2d& l1, const CameraView& view1,
const Line2d& l2, const CameraView& view2)
{
// fundamental matrix
M3D F = compute_fundamental_matrix(view1, view2);

// epipolar lines
V3D coor_l2 = l2.coords();
Expand Down
3 changes: 3 additions & 0 deletions limap/triangulation/functions.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ V3D getNormalDirection(const Line2d& l, const CameraView& view);
V3D getDirectionFromVP(const V3D& vp, const CameraView& view);

// weak epipolar constraints
M3D compute_essential_matrix(const CameraView& view1, const CameraView& view2);
M3D compute_fundamental_matrix(const CameraView& view1, const CameraView& view2);

// intersect epipolar lines with the matched line on image 2
double compute_epipolar_IoU(const Line2d& l1, const CameraView& view1,
const Line2d& l2, const CameraView& view2);
Expand Down
6 changes: 6 additions & 0 deletions limap/triangulation/triangulation.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,12 @@ def get_normal_direction(l, view):
def get_direction_from_VP(vp, view):
return _tri.get_direction_from_VP(vp, view)

def compute_essential_matrix(view1, view2):
return _tri.compute_essential_matrix(view1, view2)

def compute_fundamental_matrix(view1, view2):
return _tri.compute_fundamental_matrix(view1, view2)

def compute_epipolar_IoU(l1, view1, l2, view2):
return _tri.compute_epipolar_IoU(l1, view1, l2, view2)

Expand Down

0 comments on commit f0d0157

Please sign in to comment.