SphericalCamera.cpp
Go to the documentation of this file.
1 /* ----------------------------------------------------------------------------
2 
3  * GTSAM Copyright 2010, Georgia Tech Research Corporation,
4  * Atlanta, Georgia 30332-0415
5  * All Rights Reserved
6  * Authors: Frank Dellaert, et al. (see THANKS for the full author list)
7 
8  * See LICENSE for the license information
9 
10  * -------------------------------------------------------------------------- */
11 
20 
21 using namespace std;
22 
23 namespace gtsam {
24 
25 /* ************************************************************************* */
26 bool SphericalCamera::equals(const SphericalCamera& camera, double tol) const {
27  return pose_.equals(camera.pose(), tol);
28 }
29 
30 /* ************************************************************************* */
31 void SphericalCamera::print(const string& s) const { pose_.print(s + ".pose"); }
32 
33 /* ************************************************************************* */
34 pair<Unit3, bool> SphericalCamera::projectSafe(const Point3& pw) const {
35  const Point3 pc = pose().transformTo(pw);
36  Unit3 pu = Unit3::FromPoint3(pc);
37  return make_pair(pu, pc.norm() > 1e-8);
38 }
39 
40 /* ************************************************************************* */
42  OptionalJacobian<2, 3> Dpoint) const {
43  Matrix36 Dtf_pose;
44  Matrix3 Dtf_point; // calculated by transformTo if needed
45  const Point3 pc =
46  pose().transformTo(pw, Dpose ? &Dtf_pose : 0, Dpoint ? &Dtf_point : 0);
47 
48  if (pc.norm() <= 1e-8) throw("point cannot be at the center of the camera");
49 
50  Matrix23 Dunit; // calculated by FromPoint3 if needed
51  Unit3 pu = Unit3::FromPoint3(Point3(pc), Dpoint ? &Dunit : 0);
52 
53  if (Dpose) *Dpose = Dunit * Dtf_pose; // 2x3 * 3x6 = 2x6
54  if (Dpoint) *Dpoint = Dunit * Dtf_point; // 2x3 * 3x3 = 2x3
55  return pu;
56 }
57 
58 /* ************************************************************************* */
60  OptionalJacobian<2, 2> Dpoint) const {
61  Matrix23 Dtf_rot;
62  Matrix2 Dtf_point; // calculated by transformTo if needed
63  const Unit3 pu = pose().rotation().unrotate(pwu, Dpose ? &Dtf_rot : 0,
64  Dpoint ? &Dtf_point : 0);
65 
66  if (Dpose)
67  *Dpose << Dtf_rot, Matrix::Zero(2, 3); // 2x6 (translation part is zero)
68  if (Dpoint) *Dpoint = Dtf_point; // 2x2
69  return pu;
70 }
71 
72 /* ************************************************************************* */
73 Point3 SphericalCamera::backproject(const Unit3& pu, const double depth) const {
74  return pose().transformFrom(depth * pu);
75 }
76 
77 /* ************************************************************************* */
78 Unit3 SphericalCamera::backprojectPointAtInfinity(const Unit3& p) const {
79  return pose().rotation().rotate(p);
80 }
81 
82 /* ************************************************************************* */
84  OptionalJacobian<2, 6> Dcamera,
85  OptionalJacobian<2, 3> Dpoint) const {
86  return project2(point, Dcamera, Dpoint);
87 }
88 
89 /* ************************************************************************* */
90 Vector2 SphericalCamera::reprojectionError(
91  const Point3& point, const Unit3& measured, OptionalJacobian<2, 6> Dpose,
92  OptionalJacobian<2, 3> Dpoint) const {
93  // project point
94  if (Dpose || Dpoint) {
95  Matrix26 H_project_pose;
96  Matrix23 H_project_point;
97  Matrix22 H_error;
98  Unit3 projected = project2(point, H_project_pose, H_project_point);
99  Vector2 error = measured.errorVector(projected, {}, H_error);
100  if (Dpose) *Dpose = H_error * H_project_pose;
101  if (Dpoint) *Dpoint = H_error * H_project_point;
102  return error;
103  } else {
104  return measured.errorVector(project2(point, Dpose, Dpoint));
105  }
106 }
107 
108 /* ************************************************************************* */
109 } // namespace gtsam
Eigen::internal::print
EIGEN_STRONG_INLINE Packet4f print(const Packet4f &a)
Definition: NEON/PacketMath.h:3115
pose
static const Pose3 pose(Rot3(Vector3(1, -1, -1).asDiagonal()), Point3(0, 0, 0.5))
s
RealScalar s
Definition: level1_cplx_impl.h:126
e
Array< double, 1, 3 > e(1./3., 0.5, 2.)
SphericalCamera.h
Calibrated camera with spherical projection.
project2
static Point2 project2(const CalibratedCamera &camera, const Point3 &point)
Definition: testCalibratedCamera.cpp:127
gtsam::SphericalCamera
Definition: SphericalCamera.h:74
measured
Point2 measured(-17, 30)
backproject
static Point3 backproject(const Pose3 &pose, const Point2 &point, const double &depth)
Definition: testCalibratedCamera.cpp:207
gtsam_unstable.tests.test_ProjectionFactorRollingShutter.point
point
Definition: test_ProjectionFactorRollingShutter.py:25
Vector2
Definition: test_operator_overloading.cpp:18
pc
int RealScalar int RealScalar int RealScalar * pc
Definition: level1_cplx_impl.h:119
gtsam::equals
Definition: Testable.h:112
gtsam
traits
Definition: SFMdata.h:40
error
static double error
Definition: testRot3.cpp:37
project
static Point2 project(const Pose3 &pose, const Unit3 &pointAtInfinity, const Cal3_S2::shared_ptr &cal)
Definition: testPinholePose.cpp:188
gtsam::OptionalJacobian
Definition: OptionalJacobian.h:38
std
Definition: BFloat16.h:88
p
float * p
Definition: Tutorial_Map_using.cpp:9
gtsam::tol
const G double tol
Definition: Group.h:79
gtsam::Point3
Vector3 Point3
Definition: Point3.h:38
gtsam::Unit3
Represents a 3D point on a unit sphere.
Definition: Unit3.h:42
camera
static const CalibratedCamera camera(kDefaultPose)
depth
static double depth
Definition: testSphericalCamera.cpp:64


gtsam
Author(s):
autogenerated on Sat Nov 16 2024 04:04:59