g2o
Toggle main menu visibility
Loading...
Searching...
No Matches
g2o
types
sba
edge_project_p2mc.cpp
Go to the documentation of this file.
1
// g2o - General Graph Optimization
2
// Copyright (C) 2011 Kurt Konolige
3
// All rights reserved.
4
//
5
// Redistribution and use in source and binary forms, with or without
6
// modification, are permitted provided that the following conditions are
7
// met:
8
//
9
// * Redistributions of source code must retain the above copyright notice,
10
// this list of conditions and the following disclaimer.
11
// * Redistributions in binary form must reproduce the above copyright
12
// notice, this list of conditions and the following disclaimer in the
13
// documentation and/or other materials provided with the distribution.
14
//
15
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
16
// IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
17
// TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
18
// PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
19
// HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
20
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
21
// TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
22
// PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
23
// LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
24
// NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25
// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26
27
#include "
edge_project_p2mc.h
"
28
29
namespace
g2o
{
30
31
// point to camera projection, monocular
32
EdgeProjectP2MC::EdgeProjectP2MC
()
33
:
BaseBinaryEdge
<2,
Vector2
,
VertexPointXYZ
,
VertexCam
>() {
34
information
().setIdentity();
35
}
36
37
bool
EdgeProjectP2MC::read
(std::istream& is) {
38
// measured keypoint
39
internal::readVector
(is,
_measurement
);
40
return
readInformationMatrix
(is);
41
}
42
43
bool
EdgeProjectP2MC::write
(std::ostream& os)
const
{
44
internal::writeVector
(os,
measurement
());
45
writeInformationMatrix
(os);
46
return
os.good();
47
}
48
49
void
EdgeProjectP2MC::computeError
() {
50
// from <Point> to <Cam>
51
const
VertexPointXYZ
* point =
52
static_cast<
const
VertexPointXYZ
*
>
(
_vertices
[0]);
53
const
VertexCam
* cam =
static_cast<
const
VertexCam
*
>
(
_vertices
[1]);
54
55
// calculate the projection
56
const
Vector3
& pt = point->
estimate
();
57
Vector4
ppt(pt(0), pt(1), pt(2), 1);
58
Vector3
p = cam->
estimate
().
w2i
* ppt;
59
Vector2
perr;
60
perr = p.head<2>() / p(2);
61
62
// error, which is backwards from the normal observed - calculated
63
// _measurement is the measured projection
64
_error
= perr -
_measurement
;
65
}
66
67
void
EdgeProjectP2MC::linearizeOplus
() {
68
VertexCam
* vc =
static_cast<
VertexCam
*
>
(
_vertices
[1]);
69
const
SBACam
& cam = vc->
estimate
();
70
71
VertexPointXYZ
* vp =
static_cast<
VertexPointXYZ
*
>
(
_vertices
[0]);
72
Vector4
pt, trans;
73
pt.head<3>() = vp->
estimate
();
74
pt(3) = 1.0;
75
trans.head<3>() = cam.
translation
();
76
trans(3) = 1.0;
77
78
// first get the world point in camera coords
79
Vector3
pc = cam.
w2n
* pt;
80
81
// Jacobians wrt camera parameters
82
// set d(quat-x) values [ pz*dpx/dx - px*dpz/dx ] / pz^2
83
double
px = pc(0);
84
double
py = pc(1);
85
double
pz = pc(2);
86
double
ipz2 = 1.0 / (pz * pz);
87
if
(
g2o_isnan
(ipz2)) {
88
std::cout <<
"[SetJac] infinite jac"
<< std::endl;
89
abort();
90
}
91
92
double
ipz2fx = ipz2 * cam.
Kcam
(0, 0);
// Fx
93
double
ipz2fy = ipz2 * cam.
Kcam
(1, 1);
// Fy
94
95
// check for local vars
96
Vector3
pwt =
97
(pt - trans)
98
.head<3>();
// transform translations, use differential rotation
99
100
// dx
101
Vector3
dp = cam.
dRdx
* pwt;
// dR'/dq * [pw - t]
102
_jacobianOplusXj
(0, 3) = (pz * dp(0) - px * dp(2)) * ipz2fx;
103
_jacobianOplusXj
(1, 3) = (pz * dp(1) - py * dp(2)) * ipz2fy;
104
// dy
105
dp = cam.
dRdy
* pwt;
// dR'/dq * [pw - t]
106
_jacobianOplusXj
(0, 4) = (pz * dp(0) - px * dp(2)) * ipz2fx;
107
_jacobianOplusXj
(1, 4) = (pz * dp(1) - py * dp(2)) * ipz2fy;
108
// dz
109
dp = cam.
dRdz
* pwt;
// dR'/dq * [pw - t]
110
_jacobianOplusXj
(0, 5) = (pz * dp(0) - px * dp(2)) * ipz2fx;
111
_jacobianOplusXj
(1, 5) = (pz * dp(1) - py * dp(2)) * ipz2fy;
112
113
// set d(t) values [ pz*dpx/dx - px*dpz/dx ] / pz^2
114
dp = -cam.
w2n
.col(0);
// dpc / dx
115
_jacobianOplusXj
(0, 0) = (pz * dp(0) - px * dp(2)) * ipz2fx;
116
_jacobianOplusXj
(1, 0) = (pz * dp(1) - py * dp(2)) * ipz2fy;
117
dp = -cam.
w2n
.col(1);
// dpc / dy
118
_jacobianOplusXj
(0, 1) = (pz * dp(0) - px * dp(2)) * ipz2fx;
119
_jacobianOplusXj
(1, 1) = (pz * dp(1) - py * dp(2)) * ipz2fy;
120
dp = -cam.
w2n
.col(2);
// dpc / dz
121
_jacobianOplusXj
(0, 2) = (pz * dp(0) - px * dp(2)) * ipz2fx;
122
_jacobianOplusXj
(1, 2) = (pz * dp(1) - py * dp(2)) * ipz2fy;
123
124
// Jacobians wrt point parameters
125
// set d(t) values [ pz*dpx/dx - px*dpz/dx ] / pz^2
126
dp = cam.
w2n
.col(0);
// dpc / dx
127
_jacobianOplusXi
(0, 0) = (pz * dp(0) - px * dp(2)) * ipz2fx;
128
_jacobianOplusXi
(1, 0) = (pz * dp(1) - py * dp(2)) * ipz2fy;
129
dp = cam.
w2n
.col(1);
// dpc / dy
130
_jacobianOplusXi
(0, 1) = (pz * dp(0) - px * dp(2)) * ipz2fx;
131
_jacobianOplusXi
(1, 1) = (pz * dp(1) - py * dp(2)) * ipz2fy;
132
dp = cam.
w2n
.col(2);
// dpc / dz
133
_jacobianOplusXi
(0, 2) = (pz * dp(0) - px * dp(2)) * ipz2fx;
134
_jacobianOplusXi
(1, 2) = (pz * dp(1) - py * dp(2)) * ipz2fy;
135
}
136
137
}
// namespace g2o
g2o::BaseBinaryEdge< 2, Vector2, VertexPointXYZ, VertexCam >::_jacobianOplusXj
BaseFixedSizedEdge< D, Vector2, VertexPointXYZ, VertexCam >::template JacobianType< D, VertexCam::Dimension > & _jacobianOplusXj
Definition
base_binary_edge.h:48
g2o::BaseBinaryEdge< 2, Vector2, VertexPointXYZ, VertexCam >::BaseBinaryEdge
BaseBinaryEdge()
Definition
base_binary_edge.h:41
g2o::BaseBinaryEdge< 2, Vector2, VertexPointXYZ, VertexCam >::_jacobianOplusXi
BaseFixedSizedEdge< D, Vector2, VertexPointXYZ, VertexCam >::template JacobianType< D, VertexPointXYZ::Dimension > & _jacobianOplusXi
Definition
base_binary_edge.h:45
g2o::BaseEdge< D, Vector2 >::writeInformationMatrix
bool writeInformationMatrix(std::ostream &os) const
Definition
base_edge.h:165
g2o::BaseEdge< D, Vector2 >::readInformationMatrix
bool readInformationMatrix(std::istream &is)
Definition
base_edge.h:173
g2o::BaseEdge< D, Vector2 >::measurement
EIGEN_STRONG_INLINE const Measurement & measurement() const
Definition
base_edge.h:119
g2o::BaseEdge< D, Vector2 >::information
EIGEN_STRONG_INLINE const InformationType & information() const
Definition
base_edge.h:107
g2o::BaseEdge< D, Vector2 >::_measurement
Measurement _measurement
Definition
base_edge.h:146
g2o::BaseEdge< D, Vector2 >::_error
ErrorVector _error
Definition
base_edge.h:149
g2o::BaseVertex::estimate
const EstimateType & estimate() const
return the current estimate of the vertex
Definition
base_vertex.h:127
g2o::EdgeProjectP2MC::EdgeProjectP2MC
EIGEN_MAKE_ALIGNED_OPERATOR_NEW EdgeProjectP2MC()
Definition
edge_project_p2mc.cpp:32
g2o::EdgeProjectP2MC::computeError
virtual void computeError()
return the error estimate as a 2-vector
Definition
edge_project_p2mc.cpp:49
g2o::EdgeProjectP2MC::linearizeOplus
virtual void linearizeOplus()
Jacobian for monocular projection.
Definition
edge_project_p2mc.cpp:67
g2o::EdgeProjectP2MC::write
virtual bool write(std::ostream &os) const
write the vertex to a stream
Definition
edge_project_p2mc.cpp:43
g2o::EdgeProjectP2MC::read
virtual bool read(std::istream &is)
read the vertex from a stream, i.e., the internal state of the vertex
Definition
edge_project_p2mc.cpp:37
g2o::HyperGraph::Edge::_vertices
VertexContainer _vertices
Definition
hyper_graph.h:221
g2o::SBACam
Definition
sbacam.h:46
g2o::SBACam::Kcam
Matrix3 Kcam
Definition
sbacam.h:51
g2o::SBACam::w2i
Eigen::Matrix< double, 3, 4 > w2i
Definition
sbacam.h:56
g2o::SBACam::dRdx
Matrix3 dRdx
Definition
sbacam.h:60
g2o::SBACam::w2n
Eigen::Matrix< double, 3, 4 > w2n
Definition
sbacam.h:55
g2o::SBACam::dRdy
Matrix3 dRdy
Definition
sbacam.h:60
g2o::SBACam::dRdz
Matrix3 dRdz
Definition
sbacam.h:60
g2o::SE3Quat::translation
const Vector3 & translation() const
Definition
se3quat.h:89
g2o::VertexCam
SBACam Vertex, (x,y,z,qw,qx,qy,qz) the parameterization for the increments constructed is a 6d vector...
Definition
vertex_cam.h:43
g2o::VertexPointXYZ
Vertex for a tracked point in space.
Definition
vertex_pointxyz.h:38
edge_project_p2mc.h
g2o_isnan
#define g2o_isnan(x)
Definition
macros.h:100
g2o::internal::writeVector
bool writeVector(std::ostream &os, const Eigen::DenseBase< Derived > &b)
Definition
io_helper.h:36
g2o::internal::readVector
bool readVector(std::istream &is, Eigen::DenseBase< Derived > &b)
Definition
io_helper.h:42
g2o
Definition
dl_wrapper.cpp:55
g2o::Vector3
VectorN< 3 > Vector3
Definition
eigen_types.h:51
g2o::Vector4
VectorN< 4 > Vector4
Definition
eigen_types.h:52
g2o::Vector2
VectorN< 2 > Vector2
Definition
eigen_types.h:50
Generated on
for g2o by
1.17.0