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
Point2 measured(-17, 30)
static Point2 project2(const CalibratedCamera &camera, const Point3 &point)
static Point2 project(const Pose3 &pose, const Unit3 &pointAtInfinity, const Cal3_S2::shared_ptr &cal)
int RealScalar int RealScalar int RealScalar * pc
static double depth
Calibrated camera with spherical projection.
Definition: BFloat16.h:88
EIGEN_STRONG_INLINE Packet4f print(const Packet4f &a)
static Point3 backproject(const Pose3 &pose, const Point2 &point, const double &depth)
Represents a 3D point on a unit sphere.
Definition: Unit3.h:42
Array< double, 1, 3 > e(1./3., 0.5, 2.)
RealScalar s
const Pose3 & pose() const
return pose, constant version
traits
Definition: chartTesting.h:28
static const Pose3 pose(Rot3(Vector3(1, -1, -1).asDiagonal()), Point3(0, 0, 0.5))
float * p
static double error
Definition: testRot3.cpp:37
const G double tol
Definition: Group.h:86
Vector3 Point3
Definition: Point3.h:38
Vector2 errorVector(const Unit3 &q, OptionalJacobian< 2, 2 > H_p={}, OptionalJacobian< 2, 2 > H_q={}) const
Definition: Unit3.cpp:209
static const CalibratedCamera camera(kDefaultPose)


gtsam
Author(s):
autogenerated on Tue Jul 4 2023 02:36:19