g2o
Loading...
Searching...
No Matches
parameter_cameraparameters.cpp
Go to the documentation of this file.
1// g2o - General Graph Optimization
2// Copyright (C) 2011 H. Strasdat
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
28
30
31namespace g2o {
32
34 : focal_length(1.), principle_point(Vector2(0., 0.)), baseline(0.5) {}
35
37 const Vector2& principle_point,
38 double baseline)
39 : focal_length(focal_length),
40 principle_point(principle_point),
41 baseline(baseline) {}
42
43bool CameraParameters::read(std::istream& is) {
44 is >> focal_length;
45 is >> principle_point[0];
46 is >> principle_point[1];
47 is >> baseline;
48 return true;
49}
50
51bool CameraParameters::write(std::ostream& os) const {
52 os << focal_length << " ";
53 os << principle_point.x() << " ";
54 os << principle_point.y() << " ";
55 os << baseline << " ";
56 return true;
57}
58
59Vector2 CameraParameters::cam_map(const Vector3& trans_xyz) const {
60 Vector2 proj = project(trans_xyz);
61 Vector2 res;
62 res[0] = proj[0] * focal_length + principle_point[0];
63 res[1] = proj[1] * focal_length + principle_point[1];
64 return res;
65}
66
68 Vector2 uv_left = cam_map(trans_xyz);
69 double proj_x_right = (trans_xyz[0] - baseline) / trans_xyz[2];
70 double u_right = proj_x_right * focal_length + principle_point[0];
71 return Vector3(uv_left[0], uv_left[1], u_right);
72}
73
74} // namespace g2o
Vector3 stereocam_uvu_map(const Vector3 &trans_xyz) const
bool write(std::ostream &os) const
write the data to a stream
Vector2 cam_map(const Vector3 &trans_xyz) const
bool read(std::istream &is)
read the data from a stream
VectorN< 3 > Vector3
Definition eigen_types.h:51
G2O_TYPES_SLAM3D_API Vector2 project(const Vector3 &)
VectorN< 2 > Vector2
Definition eigen_types.h:50