farm-ng-core
affine.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/Dense>
12 
13 namespace sophus {
14 
16  public:
17  static int constexpr kNumDistortionParams = 0;
18  static int constexpr kNumParams = 4;
19  static constexpr const std::string_view kProjectionModel =
20  "Pinhole:fx,fy,cx,cy";
21 
22  template <class TScalar>
23  using ProjInCameraZ1Plane = Eigen::Matrix<TScalar, 2, 1>;
24  template <class TScalar>
25  using PixelImage = Eigen::Matrix<TScalar, 2, 1>;
26  template <class TScalar>
27  using Params = Eigen::Matrix<TScalar, kNumParams, 1>;
28  template <class TScalar>
29  using DistorationParams = Eigen::Matrix<TScalar, kNumDistortionParams, 1>;
30 
31  template <class TParamsTypeT, class TPointTypeT>
32  static auto distort(
33  Eigen::MatrixBase<TParamsTypeT> const& params,
34  Eigen::MatrixBase<TPointTypeT> const& proj_point_in_camera_z1_plane)
36  static_assert(
37  TParamsTypeT::ColsAtCompileTime == 1, "params must be a column-vector");
38  static_assert(
39  TParamsTypeT::RowsAtCompileTime == kNumParams,
40  "params must have exactly kNumParams rows");
41  static_assert(
42  TPointTypeT::ColsAtCompileTime == 1,
43  "point_camera must be a column-vector");
44  static_assert(
45  TPointTypeT::RowsAtCompileTime == 2,
46  "point_camera must have exactly 2 columns");
47 
49  proj_point_in_camera_z1_plane[0] * params[0] + params[2],
50  proj_point_in_camera_z1_plane[1] * params[1] + params[3]);
51  }
52 
53  template <class TScalar>
54  static auto undistort(
55  Params<TScalar> const& params, PixelImage<TScalar> const& pixel_image)
57  TScalar proj_x_in_camera_z1_plane =
58  (pixel_image.x() - TScalar(params[2])) / TScalar(params[0]);
59  TScalar proj_y_in_camera_z1_plane =
60  (pixel_image.y() - TScalar(params[3])) / TScalar(params[1]);
62  proj_x_in_camera_z1_plane, proj_y_in_camera_z1_plane);
63  }
64 
65  template <class TParamsTypeT, class TPointTypeT>
66  static auto dxDistort(
67  Eigen::MatrixBase<TParamsTypeT> const& params,
68  Eigen::MatrixBase<TPointTypeT> const& /*proj_point_in_camera_z1_plane*/)
69  -> Eigen::Matrix<typename TPointTypeT::Scalar, 2, 2> {
70  static_assert(
71  TParamsTypeT::ColsAtCompileTime == 1, "params must be a column-vector");
72  static_assert(
73  TParamsTypeT::RowsAtCompileTime == kNumParams,
74  "params must have exactly kNumParams rows");
75  static_assert(
76  TPointTypeT::ColsAtCompileTime == 1,
77  "point_camera must be a column-vector");
78  static_assert(
79  TPointTypeT::RowsAtCompileTime == 2,
80  "point_camera must have exactly 2 columns");
81 
82  Eigen::Matrix<typename TPointTypeT::Scalar, 2, 2> dx;
83 
84  // clang-format off
85  dx << //
86  params[0], 0,
87  0, params[1];
88  // clang-format on
89  return dx;
90  }
91 };
92 
93 } // namespace sophus
sophus
Image MutImage, owning images types.
Definition: num_diff.h:20
sophus::AffineTransform::DistorationParams
Eigen::Matrix< TScalar, kNumDistortionParams, 1 > DistorationParams
Definition: affine.h:29
sophus::AffineTransform::PixelImage
Eigen::Matrix< TScalar, 2, 1 > PixelImage
Definition: affine.h:25
sophus::AffineTransform::kNumDistortionParams
static constexpr int kNumDistortionParams
Definition: affine.h:17
sophus::AffineTransform::ProjInCameraZ1Plane
Eigen::Matrix< TScalar, 2, 1 > ProjInCameraZ1Plane
Definition: affine.h:23
sophus::AffineTransform::kProjectionModel
static constexpr const std::string_view kProjectionModel
Definition: affine.h:19
sophus::AffineTransform::kNumParams
static constexpr int kNumParams
Definition: affine.h:18
sophus::AffineTransform::undistort
static auto undistort(Params< TScalar > const &params, PixelImage< TScalar > const &pixel_image) -> ProjInCameraZ1Plane< TScalar >
Definition: affine.h:54
sophus::AffineTransform::dxDistort
static auto dxDistort(Eigen::MatrixBase< TParamsTypeT > const &params, Eigen::MatrixBase< TPointTypeT > const &) -> Eigen::Matrix< typename TPointTypeT::Scalar, 2, 2 >
Definition: affine.h:66
sophus::AffineTransform
Definition: affine.h:15
sophus::AffineTransform::Params
Eigen::Matrix< TScalar, kNumParams, 1 > Params
Definition: affine.h:27
sophus::AffineTransform::distort
static auto distort(Eigen::MatrixBase< TParamsTypeT > const &params, Eigen::MatrixBase< TPointTypeT > const &proj_point_in_camera_z1_plane) -> PixelImage< typename TPointTypeT::Scalar >
Definition: affine.h:32