MVE - Multi-View Environment mve-devel
Loading...
Searching...
No Matches
camera_pose.h
Go to the documentation of this file.
1/*
2 * Copyright (C) 2015, Simon Fuhrmann
3 * TU Darmstadt - Graphics, Capture and Massively Parallel Computing
4 * All rights reserved.
5 *
6 * This software may be modified and distributed under the terms
7 * of the BSD 3-Clause license. See the LICENSE.txt file for details.
8 */
9
10#ifndef SFM_POSE_HEADER
11#define SFM_POSE_HEADER
12
13#include <vector>
14
15#include "math/vector.h"
16#include "math/matrix.h"
17#include "math/matrix_tools.h"
18#include "sfm/defines.h"
19#include "sfm/correspondence.h"
20
22
40{
41public:
42 CameraPose (void);
43
45 void init_canonical_form (void);
47 void fill_p_matrix (math::Matrix<double, 3, 4>* result) const;
49 void set_k_matrix (double flen, double px, double py);
51 double get_focal_length (void) const;
53 void fill_camera_pos (math::Vector<double, 3>* camera_pos) const;
55 bool is_valid (void) const;
56
57public:
61};
62
63/* ------------------------ Implementation ------------------------ */
64
65inline
66CameraPose::CameraPose (void)
67 : K(0.0)
68 , R(0.0)
69 , t(0.0)
70{
71}
72
73inline void
75{
77 this->t.fill(0.0);
78}
79
80inline void
82{
83 math::Matrix<double, 3, 3> KR = this->K * this->R;
84 math::Matrix<double, 3, 1> Kt(*(this->K * this->t));
85 *P = KR.hstack(Kt);
86}
87
88inline void
89CameraPose::set_k_matrix (double flen, double px, double py)
90{
91 this->K.fill(0.0);
92 this->K[0] = flen; this->K[2] = px;
93 this->K[4] = flen; this->K[5] = py;
94 this->K[8] = 1.0;
95}
96
97inline double
99{
100 return (this->K[0] + this->K[4]) / 2.0;
101}
102
103inline void
105{
106 *camera_pos = -this->R.transposed().mult(this->t);
107}
108
109inline bool
111{
112 return this->K[0] != 0.0;
113}
114
116
117#endif /* SFM_POSE_HEADER */
Matrix class for arbitrary dimensions and types.
Definition matrix.h:54
Matrix< T, N, M+O > hstack(Matrix< T, N, O > const &other) const
Stacks this (left) and another matrix (right) horizontally.
Definition matrix.h:341
Matrix< T, M, N > transposed(void) const
Returns a transposed copy of self by treating rows as columns.
Definition matrix.h:448
Matrix< T, N, M > & fill(T const &value)
Fills all vector elements with the given value.
Definition matrix.h:294
Vector class for arbitrary dimensions and types.
Definition vector.h:87
Vector< T, N > & fill(T const &value)
Fills all vector elements with the given value.
Definition vector.h:381
Matrix< T, N, N > & matrix_set_identity(Matrix< T, N, N > *mat)
Sets the given square matrix to the identity matrix.
#define SFM_NAMESPACE_END
Definition defines.h:14
#define SFM_NAMESPACE_BEGIN
Definition defines.h:13
The camera pose is the 3x4 matrix P = K [R | t].
Definition camera_pose.h:40
math::Matrix< double, 3, 3 > R
Definition camera_pose.h:59
bool is_valid(void) const
Returns true if K matrix is valid (non-zero focal length).
void fill_p_matrix(math::Matrix< double, 3, 4 > *result) const
Returns the P matrix as the product K [R | t].
Definition camera_pose.h:81
void set_k_matrix(double flen, double px, double py)
Initializes the K matrix from focal length and principal point.
Definition camera_pose.h:89
double get_focal_length(void) const
Returns the focal length as average of x and y focal length.
Definition camera_pose.h:98
void fill_camera_pos(math::Vector< double, 3 > *camera_pos) const
Returns the camera position (requires valid camera).
void init_canonical_form(void)
Initializes R with identity and t with zeros.
Definition camera_pose.h:74
math::Matrix< double, 3, 3 > K
Definition camera_pose.h:58
math::Vector< double, 3 > t
Definition camera_pose.h:60