g2o
Toggle main menu visibility
Loading...
Searching...
No Matches
g2o
types
sba
vertex_cam.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 "
vertex_cam.h
"
28
29
#include "
g2o/stuff/logger.h
"
30
31
namespace
g2o
{
32
33
// constructor
34
VertexCam::VertexCam
() {}
35
36
bool
VertexCam::read
(std::istream& is) {
37
// first the position and orientation (vector3 and quaternion)
38
Vector3
t;
39
internal::readVector
(is, t);
40
Quaternion
r;
41
internal::readVector
(is, r.coeffs());
42
r.normalize();
// recover nummeric precision
43
44
// form the camera object
45
SBACam
cam(r, t);
46
47
// now fx, fy, cx, cy, baseline
48
double
fx;
49
50
// try to read one value
51
is >> fx;
52
if
(is.good()) {
53
double
fy, cx, cy, tx;
54
is >> fy >> cx >> cy >> tx;
55
cam.
setKcam
(fx, fy, cx, cy, tx);
56
}
else
{
57
is.clear();
58
G2O_WARN
(
"cam not defined, using defaults"
);
59
cam.
setKcam
(300, 300, 320, 320,
cst
(0.1));
60
}
61
62
setEstimate
(cam);
63
return
true
;
64
}
65
66
bool
VertexCam::write
(std::ostream& os)
const
{
67
const
SBACam
& cam =
estimate
();
68
69
// first the position and orientation (vector3 and quaternion)
70
internal::writeVector
(os, cam.
translation
());
71
internal::writeVector
(os, cam.
rotation
().coeffs());
72
73
// now fx, fy, cx, cy, baseline
74
os << cam.
Kcam
(0, 0) <<
" "
;
75
os << cam.
Kcam
(1, 1) <<
" "
;
76
os << cam.
Kcam
(0, 2) <<
" "
;
77
os << cam.
Kcam
(1, 2) <<
" "
;
78
os << cam.
baseline
<<
" "
;
79
return
os.good();
80
}
81
82
}
// namespace g2o
g2o::BaseVertex< 6, SBACam >::estimate
const EstimateType & estimate() const
Definition
base_vertex.h:127
g2o::SBACam
Definition
sbacam.h:46
g2o::SBACam::Kcam
Matrix3 Kcam
Definition
sbacam.h:51
g2o::SBACam::baseline
double baseline
Definition
sbacam.h:52
g2o::SBACam::setKcam
void setKcam(double fx, double fy, double cx, double cy, double tx)
Definition
sbacam.cpp:92
g2o::SE3Quat::rotation
const Quaternion & rotation() const
Definition
se3quat.h:93
g2o::SE3Quat::translation
const Vector3 & translation() const
Definition
se3quat.h:89
g2o::VertexCam::read
virtual bool read(std::istream &is)
read the vertex from a stream, i.e., the internal state of the vertex
Definition
vertex_cam.cpp:36
g2o::VertexCam::write
virtual bool write(std::ostream &os) const
write the vertex to a stream
Definition
vertex_cam.cpp:66
g2o::VertexCam::setEstimate
virtual void setEstimate(const SBACam &cam)
Definition
vertex_cam.h:53
g2o::VertexCam::VertexCam
VertexCam()
Definition
vertex_cam.cpp:34
G2O_WARN
#define G2O_WARN(...)
logger.h
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::cst
constexpr double cst(long double v)
Definition
misc.h:60
g2o::Quaternion
Eigen::Quaternion< double > Quaternion
Definition
eigen_types.h:81
vertex_cam.h
Generated on
for g2o by
1.17.0