Skip to content

Commit f0d0157

Browse files
authored
Port essential and fundamental matrix (cvg#9)
* endpoints triangulation as an option. port output folder. * fix depth-based scoring for endpoints triangulation. * bind essential and fundamental matrix.
1 parent 1ee5c3b commit f0d0157

4 files changed

Lines changed: 27 additions & 6 deletions

File tree

limap/triangulation/bindings.cc

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ void bind_functions(py::module &m) {
2121

2222
m.def("get_normal_direction", &getNormalDirection);
2323
m.def("get_direction_from_VP", &getDirectionFromVP);
24+
m.def("compute_essential_matrix", &compute_essential_matrix);
25+
m.def("compute_fundamental_matrix", &compute_fundamental_matrix);
2426
m.def("compute_epipolar_IoU", &compute_epipolar_IoU);
2527
m.def("triangulate_endpoints", &triangulate_endpoints);
2628
m.def("triangulate", &triangulate);

limap/triangulation/functions.cc

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -39,14 +39,10 @@ V3D getDirectionFromVP(const V3D& vp, const CameraView& view) {
3939
return direc.normalized();
4040
}
4141

42-
double compute_epipolar_IoU(const Line2d& l1, const CameraView& view1,
43-
const Line2d& l2, const CameraView& view2)
42+
M3D compute_essential_matrix(const CameraView& view1, const CameraView& view2)
4443
{
45-
const M3D K1_inv = view1.K_inv();
4644
const M3D R1 = view1.R();
4745
const V3D T1 = view1.T();
48-
49-
const M3D K2_inv = view2.K_inv();
5046
const M3D R2 = view2.R();
5147
const V3D T2 = view2.T();
5248

@@ -60,7 +56,21 @@ double compute_epipolar_IoU(const Line2d& l1, const CameraView& view1,
6056
tskew(1, 0) = relT[2]; tskew(1, 1) = 0.0; tskew(1, 2) = -relT[0];
6157
tskew(2, 0) = -relT[1]; tskew(2, 1) = relT[0]; tskew(2, 2) = 0.0;
6258
M3D E = tskew * relR;
63-
M3D F = K2_inv.transpose() * E * K1_inv;
59+
return E;
60+
}
61+
62+
M3D compute_fundamental_matrix(const CameraView& view1, const CameraView& view2)
63+
{
64+
M3D E = compute_essential_matrix(view1, view2);
65+
M3D F = view2.K_inv().transpose() * E * view1.K_inv();
66+
return F;
67+
}
68+
69+
double compute_epipolar_IoU(const Line2d& l1, const CameraView& view1,
70+
const Line2d& l2, const CameraView& view2)
71+
{
72+
// fundamental matrix
73+
M3D F = compute_fundamental_matrix(view1, view2);
6474

6575
// epipolar lines
6676
V3D coor_l2 = l2.coords();

limap/triangulation/functions.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@ V3D getNormalDirection(const Line2d& l, const CameraView& view);
1717
V3D getDirectionFromVP(const V3D& vp, const CameraView& view);
1818

1919
// weak epipolar constraints
20+
M3D compute_essential_matrix(const CameraView& view1, const CameraView& view2);
21+
M3D compute_fundamental_matrix(const CameraView& view1, const CameraView& view2);
22+
2023
// intersect epipolar lines with the matched line on image 2
2124
double compute_epipolar_IoU(const Line2d& l1, const CameraView& view1,
2225
const Line2d& l2, const CameraView& view2);

limap/triangulation/triangulation.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,12 @@ def get_normal_direction(l, view):
88
def get_direction_from_VP(vp, view):
99
return _tri.get_direction_from_VP(vp, view)
1010

11+
def compute_essential_matrix(view1, view2):
12+
return _tri.compute_essential_matrix(view1, view2)
13+
14+
def compute_fundamental_matrix(view1, view2):
15+
return _tri.compute_fundamental_matrix(view1, view2)
16+
1117
def compute_epipolar_IoU(l1, view1, l2, view2):
1218
return _tri.compute_epipolar_IoU(l1, view1, l2, view2)
1319

0 commit comments

Comments
 (0)