farm-ng-core
projection_z1.h
Go to the documentation of this file.
1 // Copyright (c) 2011, Hauke Strasdat
2 // Copyright (c) 2012, Steven Lovegrove
3 // Copyright (c) 2021, farm-ng, inc.
4 //
5 // Use of this source code is governed by an MIT-style
6 // license that can be found in the LICENSE file or at
7 // https://opensource.org/licenses/MIT.
8 
9 #pragma once
10 
11 #include <Eigen/Core>
12 
13 namespace sophus {
14 
15 struct ProjectionZ1 {
16  template <class TPoints, int kRows>
17  using WithRows = Eigen::
18  Matrix<typename TPoints::Scalar, kRows, TPoints::ColsAtCompileTime>;
19 
20  // Project one or more 3-points from the camera frame into the canonical
21  // z=1 plane through perspective division. For N points, a 3xN matrix must be
22  // provided where each column is a point to be transformed. The result will
23  // be a 2xN matrix. N may be dynamically sized, but the input columns must be
24  // statically determined as 3 at compile time.
25  template <class TDerived>
26  static auto proj(Eigen::MatrixBase<TDerived> const& points_in_camera)
28  static_assert(TDerived::RowsAtCompileTime == 3);
29  return points_in_camera.template topRows<2>() *
30  points_in_camera.template bottomRows<1>().asDiagonal().inverse();
31  }
32 
33  template <class TDerived>
34  static auto unproj(
35  Eigen::MatrixBase<TDerived> const& points_in_cam_canonical,
36  typename TDerived::Scalar extension =
37  static_cast<typename TDerived::Scalar>(1.0))
39  static_assert(TDerived::RowsAtCompileTime == 2);
41  unprojected.template topRows<2>() = points_in_cam_canonical * extension;
42  unprojected.template bottomRows<1>() =
44  points_in_cam_canonical.cols(), extension);
45  return unprojected;
46  }
47 
48  /// Returns point derivative of inverse depth point projection:
49  ///
50  /// Dx proj(x) with x = (a,b,psi) being an inverse depth point.
51  template <class TScalar>
52  static auto dxProjX(Eigen::Matrix<TScalar, 3, 1> const& p)
53  -> Eigen::Matrix<TScalar, 2, 3> {
54  Eigen::Matrix<TScalar, 2, 3> dx;
55 
56  TScalar z_inv = 1 / p.z();
57  TScalar z_sq = p.z() * p.z();
58  // clang-format off
59  dx <<
60  z_inv, 0, -p.x()/z_sq,
61  0, z_inv, -p.y()/z_sq;
62 
63  return dx;
64  }
65 };
66 
67 }
sophus::ProjectionZ1::WithRows
Eigen::Matrix< typename TPoints::Scalar, kRows, TPoints::ColsAtCompileTime > WithRows
Definition: projection_z1.h:18
sophus::ProjectionZ1::dxProjX
static auto dxProjX(Eigen::Matrix< TScalar, 3, 1 > const &p) -> Eigen::Matrix< TScalar, 2, 3 >
Returns point derivative of inverse depth point projection:
Definition: projection_z1.h:52
sophus
Image MutImage, owning images types.
Definition: num_diff.h:20
sophus::ProjectionZ1::unproj
static auto unproj(Eigen::MatrixBase< TDerived > const &points_in_cam_canonical, typename TDerived::Scalar extension=static_cast< typename TDerived::Scalar >(1.0)) -> WithRows< Eigen::MatrixBase< TDerived >, 3 >
Definition: projection_z1.h:34
sophus::ProjectionZ1::proj
static auto proj(Eigen::MatrixBase< TDerived > const &points_in_camera) -> WithRows< Eigen::MatrixBase< TDerived >, 2 >
Definition: projection_z1.h:26
sophus::ProjectionZ1
Definition: projection_z1.h:15