-
Notifications
You must be signed in to change notification settings - Fork 16
/
triangulation.h
153 lines (126 loc) · 6.75 KB
/
triangulation.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
// Copyright (c) 2017-2023 California Institute of Technology ("Caltech"). U.S.
// Government sponsorship acknowledged. All rights reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
#pragma once
#include "basic-geometry.h"
// All of these return (0,0,0) if the rays are parallel or divergent, or if the
// intersection is behind either of the two cameras. No gradients are reported
// in that case
// Basic closest-approach-in-3D routine. This is the "Mid" method in
// "Triangulation: Why Optimize?", Seong Hun Lee and Javier Civera
// https://arxiv.org/abs/1907.11917
mrcal_point3_t
mrcal_triangulate_geometric(// outputs
// These all may be NULL
mrcal_point3_t* dm_dv0,
mrcal_point3_t* dm_dv1,
mrcal_point3_t* dm_dt01,
// inputs
// not-necessarily normalized vectors in the camera-0
// coord system
const mrcal_point3_t* v0,
const mrcal_point3_t* v1,
const mrcal_point3_t* t01);
// Minimize L2 pinhole reprojection error. Described in "Triangulation Made
// Easy", Peter Lindstrom, IEEE Conference on Computer Vision and Pattern
// Recognition, 2010. This is the "L2 img 5-iteration" method (but with only 2
// iterations) in "Triangulation: Why Optimize?", Seong Hun Lee and Javier
// Civera. https://arxiv.org/abs/1907.11917
// Lindstrom's paper recommends 2 iterations
mrcal_point3_t
mrcal_triangulate_lindstrom(// outputs
// These all may be NULL
mrcal_point3_t* dm_dv0,
mrcal_point3_t* dm_dv1,
mrcal_point3_t* dm_dRt01,
// inputs
// not-necessarily normalized vectors in the LOCAL
// coordinate system. This is different from the other
// triangulation routines
const mrcal_point3_t* v0_local,
const mrcal_point3_t* v1_local,
const mrcal_point3_t* Rt01);
// Minimize L1 angle error. Described in "Closed-Form Optimal Two-View
// Triangulation Based on Angular Errors", Seong Hun Lee and Javier Civera. ICCV
// 2019. This is the "L1 ang" method in "Triangulation: Why Optimize?", Seong
// Hun Lee and Javier Civera. https://arxiv.org/abs/1907.11917
mrcal_point3_t
mrcal_triangulate_leecivera_l1(// outputs
// These all may be NULL
mrcal_point3_t* dm_dv0,
mrcal_point3_t* dm_dv1,
mrcal_point3_t* dm_dt01,
// inputs
// not-necessarily normalized vectors in the camera-0
// coord system
const mrcal_point3_t* v0,
const mrcal_point3_t* v1,
const mrcal_point3_t* t01);
// Minimize L-infinity angle error. Described in "Closed-Form Optimal Two-View
// Triangulation Based on Angular Errors", Seong Hun Lee and Javier Civera. ICCV
// 2019. This is the "L-infinity ang" method in "Triangulation: Why Optimize?",
// Seong Hun Lee and Javier Civera. https://arxiv.org/abs/1907.11917
mrcal_point3_t
mrcal_triangulate_leecivera_linf(// outputs
// These all may be NULL
mrcal_point3_t* dm_dv0,
mrcal_point3_t* dm_dv1,
mrcal_point3_t* dm_dt01,
// inputs
// not-necessarily normalized vectors in the camera-0
// coord system
const mrcal_point3_t* v0,
const mrcal_point3_t* v1,
const mrcal_point3_t* t01);
// The "Mid2" method in "Triangulation: Why Optimize?", Seong Hun Lee and Javier
// Civera. https://arxiv.org/abs/1907.11917
mrcal_point3_t
mrcal_triangulate_leecivera_mid2(// outputs
// These all may be NULL
mrcal_point3_t* dm_dv0,
mrcal_point3_t* dm_dv1,
mrcal_point3_t* dm_dt01,
// inputs
// not-necessarily normalized vectors in the camera-0
// coord system
const mrcal_point3_t* v0,
const mrcal_point3_t* v1,
const mrcal_point3_t* t01);
// The "wMid2" method in "Triangulation: Why Optimize?", Seong Hun Lee and Javier
// Civera. https://arxiv.org/abs/1907.11917
mrcal_point3_t
mrcal_triangulate_leecivera_wmid2(// outputs
// These all may be NULL
mrcal_point3_t* dm_dv0,
mrcal_point3_t* dm_dv1,
mrcal_point3_t* dm_dt01,
// inputs
// not-necessarily normalized vectors in the camera-0
// coord system
const mrcal_point3_t* v0,
const mrcal_point3_t* v1,
const mrcal_point3_t* t01);
// I don't implement triangulate_leecivera_l2() yet because it requires
// computing an SVD, which is far slower than what the rest of these functions
// do
double
_mrcal_triangulated_error(// outputs
mrcal_point3_t* _derr_dv1,
mrcal_point3_t* _derr_dt01,
// inputs
// not-necessarily normalized vectors in the camera-0
// coord system
const mrcal_point3_t* _v0,
const mrcal_point3_t* _v1,
const mrcal_point3_t* _t01);
bool
_mrcal_triangulate_leecivera_mid2_is_convergent(// inputs
// not-necessarily normalized vectors in the camera-0
// coord system
const mrcal_point3_t* _v0,
const mrcal_point3_t* _v1,
const mrcal_point3_t* _t01);