Berkeley SfM
camera_extrinsics.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2015, The Regents of the University of California (Regents).
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  * 1. Redistributions of source code must retain the above copyright
10  * notice, this list of conditions and the following disclaimer.
11  *
12  * 2. Redistributions in binary form must reproduce the above
13  * copyright notice, this list of conditions and the following
14  * disclaimer in the documentation and/or other materials provided
15  * with the distribution.
16  *
17  * 3. Neither the name of the copyright holder nor the names of its
18  * contributors may be used to endorse or promote products derived
19  * from this software without specific prior written permission.
20  *
21  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS AS IS
22  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
25  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
26  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
27  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
28  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
29  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
30  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
31  * POSSIBILITY OF SUCH DAMAGE.
32  *
33  * Please contact the author(s) of this library if you have any questions.
34  * Authors: Erik Nelson ( eanelson@eecs.berkeley.edu )
35  * David Fridovich-Keil ( dfk@eecs.berkeley.edu )
36  */
37 
38 ///////////////////////////////////////////////////////////////////////////////
39 //
40 // This class defines a camera's extrinsic parameters according to the OpenCV
41 // camera model:
42 // http://docs.opencv.org/modules/calib3d/doc/camera_calibration_and_3d_reconstruction.html
43 //
44 // The default camera frame is the same as the default world frame.
45 //
46 // +Z
47 // ^
48 // |
49 // |
50 // |
51 // |
52 // World -------->+Y
53 // /
54 // /
55 // /
56 // /
57 // v
58 // +X
59 //
60 ///////////////////////////////////////////////////////////////////////////////
61 
62 #ifndef BSFM_CAMERA_CAMERA_EXTRINSICS_H
63 #define BSFM_CAMERA_CAMERA_EXTRINSICS_H
64 
65 #include <Eigen/Core>
66 
67 #include "../pose/pose.h"
68 #include "../util/types.h"
69 
70 namespace bsfm {
71 
72 using Eigen::Matrix3d;
73 using Eigen::Matrix4d;
74 using Eigen::Vector3d;
75 
77 
78 public:
79  // Constructor. Initialize to identity.
81 
82  // Constructor. Initialize world_to_camera_.
83  CameraExtrinsics(const Pose& world_to_camera);
84 
85  // Set world_to_camera_.
86  void SetWorldToCamera(const Pose& world_to_camera);
87 
88  // Extract poses.
89  Pose WorldToCamera() const;
90  Pose CameraToWorld() const;
91 
92  // Rotate the world-to-camera frame.
93  void SetRotation(const Matrix3d& rotation);
94  void SetRotation(double phi, double theta, double psi);
95  void Rotate(const Matrix3d& delta);
96  void Rotate(double dphi, double dtheta, double dpsi);
97  Matrix3d Rotation() const;
98 
99  // Translate the world-to-camera frame. All inputs correspond to the
100  // coordinates of the camera in world-frame.
101  void SetTranslation(const Vector3d& translation);
102  void SetTranslation(double wx, double wy, double wz);
103  void Translate(const Vector3d& delta);
104  void Translate(double dx, double dy, double dz);
105  void TranslateX(double dx);
106  void TranslateY(double dy);
107  void TranslateZ(double dz);
108  Vector3d Translation() const;
109 
110  // The extrinsics matrix is 3x4 matrix: [R | t].
111  Matrix34d Rt() const;
112 
113  // Convert a world frame point into the camera frame.
114  void WorldToCamera(double wx, double wy, double wz,
115  double* cx, double* cy, double* cz) const;
116 
117  // Convert a camera frame point into the world frame.
118  void CameraToWorld(double cx, double cy, double cz,
119  double* wx, double* wy, double* wz) const;
120 
121 private:
123 
124 }; //\class CameraExtrinsics
125 
126 } //\namespace bsfm
127 
128 #endif
void SetTranslation(const Vector3d &translation)
void SetRotation(const Matrix3d &rotation)
Vector3d Translation() const
void Translate(const Vector3d &delta)
void Rotate(const Matrix3d &delta)
void SetWorldToCamera(const Pose &world_to_camera)
Definition: camera.cpp:50
::Eigen::Matrix< double, 3, 4 > Matrix34d
Definition: types.h:87
Matrix3d Rotation() const