farm-ng-core
camera_model.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 "sophus/common/common.h"
12 #include "sophus/common/enum.h"
14 #include "sophus/image/image.h"
16 #include "sophus/lie/se3.h"
23 
24 #include <Eigen/Dense>
25 
26 #include <numeric>
27 #include <variant>
28 
29 namespace sophus {
30 
31 /// Subsamples pixel down, factor of 0.5.
32 ///
33 /// See for details:
34 /// https://docs.google.com/document/d/1xmhCMWklP2UoQMGaMqFnsoPWoeMvBfXN7S8-ie9k0UA/edit#heading=h.97r8rr8owwpc
35 template <class TScalar>
36 auto subsampleDown(Eigen::Matrix<TScalar, 2, 1> const& in)
37  -> Eigen::Matrix<TScalar, 2, 1> {
38  return TScalar(0.5) * in;
39 }
40 
41 /// Subsamples pixel up, factor of 2.0.
42 ///
43 /// See for details:
44 /// https://docs.google.com/document/d/1xmhCMWklP2UoQMGaMqFnsoPWoeMvBfXN7S8-ie9k0UA/edit#heading=h.97r8rr8owwpc
45 template <class TScalar>
46 auto subsampleUp(Eigen::Matrix<TScalar, 2, 1> const& in)
47  -> Eigen::Matrix<TScalar, 2, 1> {
48  return TScalar(2.0) * in;
49 }
50 
51 /// Bins pixel down, factor of 0.5.
52 ///
53 /// See for details:
54 /// https://docs.google.com/document/d/1xmhCMWklP2UoQMGaMqFnsoPWoeMvBfXN7S8-ie9k0UA/edit#heading=h.elfm6123mecj
55 template <class TScalar>
56 auto binDown(Eigen::Matrix<TScalar, 2, 1> const& in)
57  -> Eigen::Matrix<TScalar, 2, 1> {
58  Eigen::Matrix<TScalar, 2, 1> out;
59  // Map left image border from -0.5 to 0.0, then scale down, then
60  // map the left image border from 0.0 back to -0.5
61  out[0] = TScalar(0.5) * (in[0] + 0.5) - 0.5; // cx
62  out[1] = TScalar(0.5) * (in[1] + 0.5) - 0.5; // cy
63  return out;
64 }
65 
66 /// Bins pixel up, factor of 2.0.
67 ///
68 /// See for details:
69 /// https://docs.google.com/document/d/1xmhCMWklP2UoQMGaMqFnsoPWoeMvBfXN7S8-ie9k0UA/edit#heading=h.elfm6123mecj
70 template <class TScalar>
71 auto binUp(Eigen::Matrix<TScalar, 2, 1> const& in)
72  -> Eigen::Matrix<TScalar, 2, 1> {
73  Eigen::Matrix<TScalar, 2, 1> out;
74  // Map left image border from -0.5 to 0.0, then scale up, then
75  // map the left image border from 0.0 back to -0.5
76  out[0] = TScalar(2.0) * (in[0] + 0.5) - 0.5; // cx
77  out[1] = TScalar(2.0) * (in[1] + 0.5) - 0.5; // cy
78  return out;
79 }
80 
81 /// Camera model class template for pinhole-like camera projections.
82 template <class TScalar, class TDistortion, class TProj = ProjectionZ1>
83 class CameraModelT {
84  public:
85  using Distortion = TDistortion;
86  using Proj = TProj;
87  static int constexpr kNumDistortionParams = Distortion::kNumDistortionParams;
88  static int constexpr kNumParams = Distortion::kNumParams;
89  static constexpr const std::string_view kProjectionModel =
90  Distortion::kProjectionModel;
91 
92  using PointCamera = Eigen::Matrix<TScalar, 3, 1>;
93  using PixelImage = Eigen::Matrix<TScalar, 2, 1>;
94  using ProjInCameraLifted = Eigen::Matrix<TScalar, 2, 1>;
95  using Params = Eigen::Matrix<TScalar, kNumParams, 1>;
96  using DistorationParams = Eigen::Matrix<TScalar, kNumDistortionParams, 1>;
97 
98  /// Constructs camera model from image size and set up parameters.
99  CameraModelT(ImageSize const& image_size, Params const& params)
100  : image_size_(image_size), params_(params) {}
101 
102  CameraModelT() : image_size_({0, 0}) {
103  params_.setZero();
104  params_.template head<2>().setOnes();
105  }
106 
107  /// Returns camera model from raw data pointer. To be used within ceres
108  /// optimization only.
109  static auto fromData(TScalar const* const ptr) -> CameraModelT {
110  CameraModelT out;
111  Eigen::Map<Eigen::Matrix<TScalar, kNumParams, 1> const> map(
112  ptr, kNumParams, 1);
113  out.params_ = map;
114  return out;
115  }
116 
117  /// Focal length.
118  [[nodiscard]] auto focalLength() const -> PixelImage {
119  return params_.template head<2>();
120  }
121 
122  /// Focal length.
123  void setFocalLength(PixelImage const& focal_length) {
124  params_.template head<2>() = focal_length;
125  }
126 
127  [[nodiscard]] auto principalPoint() const -> PixelImage {
128  return params_.template segment<2>(2);
129  }
130 
131  /// Focal length.
132  void setPrincipalPoint(PixelImage const& principal_point) {
133  params_.template segment<2>(2) = principal_point;
134  }
135 
136  /// Returns distortion parameters by value.
137  [[nodiscard]] auto distortionParams() const -> DistorationParams {
138  return params_.template tail<kNumDistortionParams>();
139  }
140 
141  /// Parameters mutator
142  auto params() -> Eigen::Matrix<TScalar, kNumParams, 1>& { return params_; }
143 
144  /// Parameters accessor
145  [[nodiscard]] auto params() const
146  -> Eigen::Matrix<TScalar, kNumParams, 1> const& {
147  return params_;
148  }
149 
150  /// Subsamples pixel down, factor of 0.5.
151  ///
152  /// See for details:
153  /// https://docs.google.com/document/d/1xmhCMWklP2UoQMGaMqFnsoPWoeMvBfXN7S8-ie9k0UA/edit#heading=h.97r8rr8owwpc
154  ///
155  /// If the original width [height] is odd, the new width [height] will be:
156  /// (width+1)/2 [height+1)/2].
157  [[nodiscard]] auto subsampleDown() const -> CameraModelT {
158  Params params = this->params_;
159  params[0] = TScalar(0.5) * params[0]; // fx
160  params[1] = TScalar(0.5) * params[1]; // fy
161  params.template segment<2>(2) = ::sophus::subsampleDown(
162  params.template segment<2>(2).eval()); // cx, cy
163  return CameraModelT(half(image_size_), params);
164  }
165 
166  /// Subsamples pixel up, factor of 2.0.
167  ///
168  /// See for details:
169  /// https://docs.google.com/document/d/1xmhCMWklP2UoQMGaMqFnsoPWoeMvBfXN7S8-ie9k0UA/edit#heading=h.97r8rr8owwpc
170  [[nodiscard]] auto subsampleUp() const -> CameraModelT {
171  Params params = this->params_;
172  params[0] = TScalar(2.0) * params[0]; // fx
173  params[1] = TScalar(2.0) * params[1]; // fy
174  params.template segment<2>(2) =
175  ::sophus::subsampleUp(params.template segment<2>(2).eval()); // cx, cy
176  return CameraModelT(
177  {image_size_.width * 2, image_size_.height * 2}, params);
178  }
179 
180  /// Bins pixel down, factor of 0.5.
181  ///
182  /// See for details:
183  /// https://docs.google.com/document/d/1xmhCMWklP2UoQMGaMqFnsoPWoeMvBfXN7S8-ie9k0UA/edit#heading=h.elfm6123mecj
184  ///
185  /// If the original width [height] is odd, the new width [height] will be:
186  /// (width+1)/2 [height+1)/2].
187  [[nodiscard]] auto binDown() const -> CameraModelT {
188  Params params = this->params_;
189  params[0] = TScalar(0.5) * params[0]; // fx
190  params[1] = TScalar(0.5) * params[1]; // fy
191  params.template segment<2>(2) =
192  ::sophus::binDown(params.template segment<2>(2).eval()); // cx, cy
193  return CameraModelT(half(image_size_), params);
194  }
195 
196  /// Bins pixel up, factor of 2.0.
197  ///
198  /// See for details:
199  /// https://docs.google.com/document/d/1xmhCMWklP2UoQMGaMqFnsoPWoeMvBfXN7S8-ie9k0UA/edit#heading=h.elfm6123mecj
200  [[nodiscard]] auto binUp() const -> CameraModelT {
201  Params params = this->params_;
202  params[0] = TScalar(2.0) * params[0]; // fx
203  params[1] = TScalar(2.0) * params[1]; // fy
204  params.template segment<2>(2) =
205  ::sophus::binUp(params.template segment<2>(2).eval()); // cx, cy
206  return CameraModelT(
207  {image_size_.width * 2, image_size_.height * 2}, params);
208  }
209 
210  [[nodiscard]] auto scale(ImageSize const& image_size) const -> CameraModelT {
211  Params params = this->params_;
212  params[0] = TScalar(image_size.width) / TScalar(image_size_.width) *
213  params[0]; // fx
214  params[1] = TScalar(image_size.height) / TScalar(image_size_.height) *
215  params[1]; // fy
216  params[2] = TScalar(image_size.width) / TScalar(image_size_.width) *
217  params[2]; // cx
218  params[3] = TScalar(image_size.height) / TScalar(image_size_.height) *
219  params[3]; // cy
220  return CameraModelT({image_size.width, image_size.height}, params);
221  }
222 
223  /// Region of interest given `top_left` and ``roi_size`.
224  [[nodiscard]] auto roi(Eigen::Vector2i const& top_left, ImageSize roi_size)
225  const -> CameraModelT {
226  Params params = this->params_;
227  params[2] = params[2] - top_left.x(); // cx
228  params[3] = params[3] - top_left.y(); // cy
229  return CameraModelT(roi_size, params);
230  }
231 
232  /// Maps a 2-point in the z=1 plane of the camera to a pixel in the image.
233  [[nodiscard]] auto distort(
234  ProjInCameraLifted const& point2_in_camera_lifted) const -> PixelImage {
235  return Distortion::template distort(params_, point2_in_camera_lifted);
236  }
237 
238  [[nodiscard]] auto dxDistort(PixelImage const& pixel_in_image) const
239  -> Eigen::Matrix<TScalar, 2, 2> {
240  return Distortion::template dxDistort(params_, pixel_in_image);
241  }
242 
243  /// Maps a pixel in the image to a 2-point in the z=1 plane of the camera.
244  [[nodiscard]] auto undistort(PixelImage const& pixel_in_image) const
245  -> ProjInCameraLifted {
246  return Distortion::template undistort(params_, pixel_in_image);
247  }
248 
249  [[nodiscard]] auto undistortTable() const -> MutImage<Eigen::Vector2f> {
250  MutImage<Eigen::Vector2f> table(image_size_);
251  for (int v = 0; v < table.height(); ++v) {
252  Eigen::Vector2f* row_ptr = table.rowPtrMut(v);
253  for (int u = 0; u < table.width(); ++u) {
254  row_ptr[u] = this->undistort(PixelImage(u, v)).template cast<float>();
255  }
256  }
257  return table;
258  }
259 
260  /// Projects 3-point in camera frame to a pixel in the image.
261  [[nodiscard]] auto camProj(PointCamera const& point_in_camera) const
262  -> PixelImage {
263  return Distortion::template distort(params_, Proj::proj(point_in_camera));
264  }
265 
266  [[nodiscard]] auto dxCamProjX(PointCamera const& point_in_camera) const
267  -> Eigen::Matrix<TScalar, 2, 3> {
268  ProjInCameraLifted point_in_lifted = Proj::proj(point_in_camera);
269  return dxDistort(point_in_lifted) * Proj::dxProjX(point_in_camera);
270  }
271 
272  /// Unprojects pixel in the image to point in camera frame.
273  ///
274  /// The point is projected onto the xy-plane at z = `depth_z`.
275  [[nodiscard]] auto camUnproj(
276  PixelImage const& pixel_in_image, double depth_z) const -> PointCamera {
277  return Proj::unproj(
278  Distortion::template undistort(params_, pixel_in_image), depth_z);
279  }
280 
281  /// Raw data access. To be used in ceres optimization only.
282  auto data() -> TScalar* { return params_.data(); }
283 
284  /// Accessor of image size.
285  [[nodiscard]] auto imageSize() const -> ImageSize const& {
286  return image_size_;
287  }
288 
289  /// Returns true if obs is within image.
290  ///
291  /// Note: Positive border makes the image frame smaller.
292  [[nodiscard]] auto contains(Eigen::Vector2i const& obs, int border = 0) const
293  -> bool {
294  return this->image_size_.contains(obs, border);
295  }
296 
297  /// Returns true if obs is within image.
298  ///
299  /// Note: Positive border makes the image frame smaller.
300  [[nodiscard]] auto contains(
301  PixelImage const& obs, TScalar border = TScalar(0)) const -> bool {
302  return this->image_size_.contains(obs, border);
303  }
304 
305  /// cast to different scalar type.
306  template <typename TScalar2>
307  [[nodiscard]] auto cast() const
308  -> CameraModelT<TScalar2, TDistortion, TProj> {
310  image_size_, params_.template cast<TScalar2>());
311  }
312 
313  private:
314  ImageSize image_size_;
315  Eigen::Matrix<TScalar, kNumParams, 1> params_;
316 };
317 
318 /// Camera model projection type.
320  CameraDistortionType,
321  (pinhole, brown_conrady, kannala_brandt_k3, orthographic));
322 
323 /// Pinhole camera model.
325 
326 /// Brown Conrady camera model.
327 using BrownConradyModel =
329 
330 /// KannalaBrandt camera model with k0, k1, k2, k3.
331 using KannalaBrandtK3Model =
333 
334 using OrthographicModel =
336 
337 /// Variant of camera models.
338 using CameraDistortionVariant = std::variant<
339  PinholeModel,
343 
344 static_assert(
345  std::variant_size_v<CameraDistortionVariant> ==
346  getCount(CameraDistortionType()),
347  "When the variant CameraDistortionVariant is updated, one needs to "
348  "update the enum CameraDistortionType as well, and vice versa.");
349 
350 /// Concrete camera model class.
351 class CameraModel {
352  public:
354  : model_(PinholeModel({0, 0}, Eigen::Vector4d(1.0, 1.0, 0.0, 0.0))) {}
355 
356  /// Constructs camera model from `frame_name` and concrete projection model.
357  template <class TTransformModelT>
358  CameraModel(TTransformModelT model) : model_(model) {}
359 
360  /// Constructs camera model from `frame_name`, `image_size`, `projection_type`
361  /// flag and `params` vector.
362  ///
363  /// Precondition: ``params.size()`` must match the number of parameters of the
364  /// specified `projection_type` (TransformModel::kNumParams).
365  CameraModel(
366  ImageSize image_size,
367  CameraDistortionType projection_type,
368  Eigen::VectorXd const& params);
369 
370  /// Creates default pinhole model from `image_size`.
371  static auto createDefaultPinholeModel(ImageSize image_size) -> CameraModel;
372 
373  /// Returns true if this camera remains default-initialized with zero image
374  /// dimensions.
375  [[nodiscard]] auto isEmpty() const -> bool {
376  return imageSize() == ImageSize(0, 0);
377  }
378 
379  /// Returns name of the camera distortion model.
380  [[nodiscard]] auto distortionModelName() const -> std::string_view;
381 
382  /// Distortion variant mutator.
383  auto modelVariant() -> CameraDistortionVariant& { return model_; }
384 
385  /// Distortion variant accessor.
386  [[nodiscard]] auto modelVariant() const -> CameraDistortionVariant const& {
387  return model_;
388  }
389 
390  /// Camera transform flag
391  [[nodiscard]] auto distortionType() const -> CameraDistortionType;
392 
393  [[nodiscard]] auto focalLength() const -> Eigen::Vector2d;
394 
395  /// Focal length.
396  void setFocalLength(Eigen::Vector2d const& focal_length);
397 
398  [[nodiscard]] auto principalPoint() const -> Eigen::Vector2d;
399 
400  /// Focal length.
401  void setPrincipalPoint(Eigen::Vector2d const& principal_point);
402 
403  /// Returns `params` vector by value.
404  [[nodiscard]] auto params() const -> Eigen::VectorXd;
405 
406  /// Sets `params` vector.
407  ///
408  /// Precontion: ``params.size()`` must match the number of parameters of the
409  /// specified `projection_type` (TransformModel::kNumParams).
410  void setParams(Eigen::VectorXd const& params);
411 
412  /// Returns distortion parameters vector by value.
413  [[nodiscard]] auto distortionParams() const -> Eigen::VectorXd;
414 
415  /// Given a point in 3D space in the camera frame, compute the corresponding
416  /// pixel coordinates in the image.
417  [[nodiscard]] auto camProj(Eigen::Vector3d const& point_camera) const
418  -> Eigen::Vector2d;
419 
420  /// Maps a 2-point in the z=1 plane of the camera to a (distorted) pixel in
421  /// the image.
422  [[nodiscard]] auto distort(
423  Eigen::Vector2d const& point2_in_camera_lifted) const -> Eigen::Vector2d;
424 
425  [[nodiscard]] auto dxDistort(
426  Eigen::Vector2d const& point2_in_camera_lifted) const -> Eigen::Matrix2d;
427 
428  /// Maps a pixel in the image to a 2-point in the z=1 plane of the camera.
429  [[nodiscard]] auto undistort(Eigen::Vector2d const& pixel_image) const
430  -> Eigen::Vector2d;
431 
432  [[nodiscard]] auto undistortTable() const -> MutImage<Eigen::Vector2f>;
433 
434  /// Derivative of camProj(x) with respect to x=0.
435  [[nodiscard]] auto dxCamProjX(Eigen::Vector3d const& point_in_camera) const
436  -> Eigen::Matrix<double, 2, 3>;
437 
438  /// Derivative of camProj(exp(x) * point) with respect to x=0.
439  [[nodiscard]] auto dxCamProjExpXPointAt0(
440  Eigen::Vector3d const& point_in_camera) const
441  -> Eigen::Matrix<double, 2, 6>;
442 
443  /// Given pixel coordinates in the distorted image, and a corresponding
444  /// depth, reproject to a 3d point in the camera's reference frame.
445  [[nodiscard]] auto camUnproj(
446  Eigen::Vector2d const& pixel_image, double depth_z) const
447  -> Eigen::Vector3d;
448 
449  /// Subsamples pixel down, factor of 0.5.
450  ///
451  /// See for details:
452  /// https://docs.google.com/document/d/1xmhCMWklP2UoQMGaMqFnsoPWoeMvBfXN7S8-ie9k0UA/edit#heading=h.97r8rr8owwpc
453  ///
454  /// If the original width [height] is odd, the new width [height] will be:
455  /// (width+1)/2 [height+1)/2].
456  [[nodiscard]] auto subsampleDown() const -> CameraModel;
457 
458  /// Subsamples pixel up, factor of 2.0.
459  [[nodiscard]] auto subsampleUp() const -> CameraModel;
460 
461  /// Bins pixel down, factor of 0.5.
462  ///
463  /// See for details:
464  /// https://docs.google.com/document/d/1xmhCMWklP2UoQMGaMqFnsoPWoeMvBfXN7S8-ie9k0UA/edit#heading=h.elfm6123mecj
465  ///
466  /// If the original width [height] is odd, the new width [height] will be:
467  /// (width+1)/2 [height+1)/2].
468  [[nodiscard]] auto binDown() const -> CameraModel;
469 
470  /// Bins pixel up, factor of 2.0.
471  ///
472  /// See for details:
473  /// https://docs.google.com/document/d/1xmhCMWklP2UoQMGaMqFnsoPWoeMvBfXN7S8-ie9k0UA/edit#heading=h.elfm6123mecj
474  [[nodiscard]] auto binUp() const -> CameraModel;
475 
476  /// Image size accessor
477  [[nodiscard]] auto imageSize() const -> ImageSize const&;
478 
479  /// Region of interest given `top_left` and ``roi_size`.
480  [[nodiscard]] auto roi(
481  Eigen::Vector2i const& top_left, ImageSize roi_size) const -> CameraModel;
482 
483  /// Returns true if obs is within image.
484  ///
485  /// Note: Positive border makes the image frame smaller.
486  [[nodiscard]] auto contains(Eigen::Vector2i const& obs, int border = 0) const
487  -> bool;
488 
489  /// Returns true if obs is within image.
490  ///
491  /// Positive border makes the image frame smaller.
492  [[nodiscard]] auto contains(
493  Eigen::Vector2d const& obs, double border = 0) const -> bool;
494 
495  [[nodiscard]] auto scale(ImageSize image_size) const -> CameraModel;
496 
497  private:
499 };
500 
501 /// Creates default pinhole model from `image_size`.
503 
504 /// Creates default orthographic model from `image_size`.
506 
507 } // namespace sophus
kannala_brandt.h
sophus::binDown
auto binDown(Eigen::Matrix< TScalar, 2, 1 > const &in) -> Eigen::Matrix< TScalar, 2, 1 >
Bins pixel down, factor of 0.5.
Definition: camera_model.h:56
sophus::CameraModelT::subsampleDown
auto subsampleDown() const -> CameraModelT
Subsamples pixel down, factor of 0.5.
Definition: camera_model.h:157
sophus::unproj
auto unproj(Eigen::MatrixBase< TPoint > const &p, const typename TPoint::Scalar &z=1.0) -> Eigen::Vector< typename TPoint::Scalar, TPoint::RowsAtCompileTime+1 >
Maps point on the z=1 plane (a,b) to homogeneous representation of the same point: (z*a,...
Definition: homogeneous.h:31
Eigen
Definition: params.h:72
sophus::CameraModelT::dxCamProjX
auto dxCamProjX(PointCamera const &point_in_camera) const -> Eigen::Matrix< TScalar, 2, 3 >
Definition: camera_model.h:266
sophus::CameraModel::focalLength
auto focalLength() const -> Eigen::Vector2d
Definition: camera_model.cpp:60
affine.h
sophus::CameraModelT::CameraModelT
CameraModelT()
Definition: camera_model.h:102
sophus::CameraModelT::kProjectionModel
static constexpr const std::string_view kProjectionModel
Definition: camera_model.h:89
sophus::CameraModelT::CameraModelT
CameraModelT(ImageSize const &image_size, Params const &params)
Constructs camera model from image size and set up parameters.
Definition: camera_model.h:99
sophus::CameraModelT::contains
auto contains(Eigen::Vector2i const &obs, int border=0) const -> bool
Returns true if obs is within image.
Definition: camera_model.h:292
sophus::CameraModelT::setFocalLength
void setFocalLength(PixelImage const &focal_length)
Focal length.
Definition: camera_model.h:123
sophus::CameraModelT::undistortTable
auto undistortTable() const -> MutImage< Eigen::Vector2f >
Definition: camera_model.h:249
sophus::binUp
auto binUp(Eigen::Matrix< TScalar, 2, 1 > const &in) -> Eigen::Matrix< TScalar, 2, 1 >
Bins pixel up, factor of 2.0.
Definition: camera_model.h:71
sophus::CameraModelT::kNumDistortionParams
static constexpr int kNumDistortionParams
Definition: camera_model.h:87
sophus::CameraModelT
Camera model class template for pinhole-like camera projections.
Definition: camera_model.h:83
sophus::half
auto half(ImageSize image_size) -> ImageSize
If the original width [height] is odd, the new width [height] will be: (width+1)/2 [height+1)/2].
Definition: image_size.cpp:29
sophus::CameraModel::undistort
auto undistort(Eigen::Vector2d const &pixel_image) const -> Eigen::Vector2d
Maps a pixel in the image to a 2-point in the z=1 plane of the camera.
Definition: camera_model.cpp:129
image.h
sophus
Image MutImage, owning images types.
Definition: num_diff.h:20
sophus::CameraModel::distortionModelName
auto distortionModelName() const -> std::string_view
Returns name of the camera distortion model.
Definition: camera_model.cpp:46
sophus::BrownConradyModel
CameraModelT< double, BrownConradyTransform, ProjectionZ1 > BrownConradyModel
Brown Conrady camera model.
Definition: camera_model.h:328
sophus::KannalaBrandtK3Model
CameraModelT< double, KannalaBrandtK3Transform, ProjectionZ1 > KannalaBrandtK3Model
KannalaBrandt camera model with k0, k1, k2, k3.
Definition: camera_model.h:332
sophus::CameraModel::CameraModel
CameraModel(TTransformModelT model)
Constructs camera model from frame_name and concrete projection model.
Definition: camera_model.h:358
sophus::CameraModelT::subsampleUp
auto subsampleUp() const -> CameraModelT
Subsamples pixel up, factor of 2.0.
Definition: camera_model.h:170
sophus::CameraModel::undistortTable
auto undistortTable() const -> MutImage< Eigen::Vector2f >
Definition: camera_model.cpp:136
sophus::CameraModel
Concrete camera model class.
Definition: camera_model.h:351
sophus::CameraModel::setPrincipalPoint
void setPrincipalPoint(Eigen::Vector2d const &principal_point)
Focal length.
Definition: camera_model.cpp:77
sophus::CameraModelT::scale
auto scale(ImageSize const &image_size) const -> CameraModelT
Definition: camera_model.h:210
sophus::CameraModelT::cast
auto cast() const -> CameraModelT< TScalar2, TDistortion, TProj >
cast to different scalar type.
Definition: camera_model.h:307
sophus::CameraModel::dxCamProjExpXPointAt0
auto dxCamProjExpXPointAt0(Eigen::Vector3d const &point_in_camera) const -> Eigen::Matrix< double, 2, 6 >
Derivative of camProj(exp(x) * point) with respect to x=0.
Definition: camera_model.cpp:154
sophus::subsampleDown
auto subsampleDown(Eigen::Matrix< TScalar, 2, 1 > const &in) -> Eigen::Matrix< TScalar, 2, 1 >
Subsamples pixel down, factor of 0.5.
Definition: camera_model.h:36
brown_conrady.h
sophus::CameraModelT::fromData
static auto fromData(TScalar const *const ptr) -> CameraModelT
Returns camera model from raw data pointer. To be used within ceres optimization only.
Definition: camera_model.h:109
point_transform.h
sophus::dxProjX
auto dxProjX(InverseDepthPoint3< TT > const &) -> Eigen::Matrix< TT, 2, 3 >
Returns point derivative of inverse depth point projection:
Definition: point_transform.h:29
sophus::CameraModel::roi
auto roi(Eigen::Vector2i const &top_left, ImageSize roi_size) const -> CameraModel
Region of interest given top_left and `roi_size.
Definition: camera_model.cpp:189
sophus::CameraModel::dxDistort
auto dxDistort(Eigen::Vector2d const &point2_in_camera_lifted) const -> Eigen::Matrix2d
Definition: camera_model.cpp:120
sophus::CameraModel::subsampleDown
auto subsampleDown() const -> CameraModel
Subsamples pixel down, factor of 0.5.
Definition: camera_model.cpp:165
sophus::CameraModel::modelVariant
auto modelVariant() -> CameraDistortionVariant &
Distortion variant mutator.
Definition: camera_model.h:383
sophus::CameraModelT< double, AffineTransform, ProjectionZ1 >::PixelImage
Eigen::Matrix< double, 2, 1 > PixelImage
Definition: camera_model.h:93
sophus::CameraModelT::undistort
auto undistort(PixelImage const &pixel_in_image) const -> ProjInCameraLifted
Maps a pixel in the image to a 2-point in the z=1 plane of the camera.
Definition: camera_model.h:244
sophus::CameraModel::setFocalLength
void setFocalLength(Eigen::Vector2d const &focal_length)
Focal length.
Definition: camera_model.cpp:65
sophus::CameraModelT::binUp
auto binUp() const -> CameraModelT
Bins pixel up, factor of 2.0.
Definition: camera_model.h:200
sophus::CameraModelT< double, AffineTransform, ProjectionZ1 >::Params
Eigen::Matrix< double, kNumParams, 1 > Params
Definition: camera_model.h:95
sophus::CameraModelT::params
auto params() -> Eigen::Matrix< TScalar, kNumParams, 1 > &
Parameters mutator.
Definition: camera_model.h:142
sophus::CameraModel::contains
auto contains(Eigen::Vector2i const &obs, int border=0) const -> bool
Returns true if obs is within image.
Definition: camera_model.cpp:200
sophus::CameraModelT< double, AffineTransform, ProjectionZ1 >::PointCamera
Eigen::Matrix< double, 3, 1 > PointCamera
Definition: camera_model.h:92
sophus::CameraModelT::dxDistort
auto dxDistort(PixelImage const &pixel_in_image) const -> Eigen::Matrix< TScalar, 2, 2 >
Definition: camera_model.h:238
sophus::CameraModel::isEmpty
auto isEmpty() const -> bool
Returns true if this camera remains default-initialized with zero image dimensions.
Definition: camera_model.h:375
sophus::MutImage
A image with write access to pixels and exclusive ownership. There is no copy constr / copy assignmen...
Definition: image_view.h:32
sophus::CameraModelT::camUnproj
auto camUnproj(PixelImage const &pixel_in_image, double depth_z) const -> PointCamera
Unprojects pixel in the image to point in camera frame.
Definition: camera_model.h:275
sophus::CameraModel::distortionParams
auto distortionParams() const -> Eigen::VectorXd
Returns distortion parameters vector by value.
Definition: camera_model.cpp:85
sophus::CameraModelT::params
auto params() const -> Eigen::Matrix< TScalar, kNumParams, 1 > const &
Parameters accessor.
Definition: camera_model.h:145
sophus::CameraModelT::camProj
auto camProj(PointCamera const &point_in_camera) const -> PixelImage
Projects 3-point in camera frame to a pixel in the image.
Definition: camera_model.h:261
sophus::CameraModelT::focalLength
auto focalLength() const -> PixelImage
Focal length.
Definition: camera_model.h:118
sophus::SOPHUS_ENUM
SOPHUS_ENUM(NumberType,(fixed_point, floating_point))
sophus::PinholeModel
CameraModelT< double, AffineTransform, ProjectionZ1 > PinholeModel
Pinhole camera model.
Definition: camera_model.h:324
sophus::CameraModel::imageSize
auto imageSize() const -> ImageSize const &
Image size accessor.
Definition: camera_model.cpp:207
homogeneous.h
sophus::CameraModelT::data
auto data() -> TScalar *
Raw data access. To be used in ceres optimization only.
Definition: camera_model.h:282
se3.h
sophus::CameraModel::binDown
auto binDown() const -> CameraModel
Bins pixel down, factor of 0.5.
Definition: camera_model.cpp:177
sophus::CameraModelT::distort
auto distort(ProjInCameraLifted const &point2_in_camera_lifted) const -> PixelImage
Maps a 2-point in the z=1 plane of the camera to a pixel in the image.
Definition: camera_model.h:233
projection_z1.h
sophus::CameraModelT::contains
auto contains(PixelImage const &obs, TScalar border=TScalar(0)) const -> bool
Returns true if obs is within image.
Definition: camera_model.h:300
sophus::CameraModelT< double, AffineTransform, ProjectionZ1 >::ProjInCameraLifted
Eigen::Matrix< double, 2, 1 > ProjInCameraLifted
Definition: camera_model.h:94
sophus::CameraModel::params
auto params() const -> Eigen::VectorXd
Returns params vector by value.
Definition: camera_model.cpp:55
common.h
sophus::CameraModelT::imageSize
auto imageSize() const -> ImageSize const &
Accessor of image size.
Definition: camera_model.h:285
projection_ortho.h
sophus::CameraModel::scale
auto scale(ImageSize image_size) const -> CameraModel
Definition: camera_model.cpp:244
sophus::CameraModel::distortionType
auto distortionType() const -> CameraDistortionType
Camera transform flag.
Definition: camera_model.cpp:220
sophus::CameraModel::distort
auto distort(Eigen::Vector2d const &point2_in_camera_lifted) const -> Eigen::Vector2d
Maps a 2-point in the z=1 plane of the camera to a (distorted) pixel in the image.
Definition: camera_model.cpp:111
sophus::subsampleUp
auto subsampleUp(Eigen::Matrix< TScalar, 2, 1 > const &in) -> Eigen::Matrix< TScalar, 2, 1 >
Subsamples pixel up, factor of 2.0.
Definition: camera_model.h:46
sophus::CameraDistortionVariant
std::variant< PinholeModel, BrownConradyModel, KannalaBrandtK3Model, OrthographicModel > CameraDistortionVariant
Variant of camera models.
Definition: camera_model.h:342
sophus::CameraModel::createDefaultPinholeModel
static auto createDefaultPinholeModel(ImageSize image_size) -> CameraModel
Creates default pinhole model from image_size.
Definition: camera_model.cpp:239
sophus::CameraModel::dxCamProjX
auto dxCamProjX(Eigen::Vector3d const &point_in_camera) const -> Eigen::Matrix< double, 2, 3 >
Derivative of camProj(x) with respect to x=0.
Definition: camera_model.cpp:145
sophus::CameraModel::camUnproj
auto camUnproj(Eigen::Vector2d const &pixel_image, double depth_z) const -> Eigen::Vector3d
Given pixel coordinates in the distorted image, and a corresponding depth, reproject to a 3d point in...
Definition: camera_model.cpp:102
sophus::CameraModel::binUp
auto binUp() const -> CameraModel
Bins pixel up, factor of 2.0.
Definition: camera_model.cpp:183
sophus::ImageSize::height
int height
Vertical height of images, i.e. number of rows.
Definition: image_size.h:56
sophus::ImageSize::width
int width
Horizontal width of images, i.e. number of columns.
Definition: image_size.h:53
sophus::CameraModel::setParams
void setParams(Eigen::VectorXd const &params)
Sets params vector.
Definition: camera_model.cpp:91
sophus::CameraModel::modelVariant
auto modelVariant() const -> CameraDistortionVariant const &
Distortion variant accessor.
Definition: camera_model.h:386
sophus::proj
auto proj(InverseDepthPoint3< TT > const &inverse_depth_point) -> Eigen::Matrix< TT, 2, 1 >
Projects 3-point (a,b,psi) = (x/z,y/z,1/z) through the origin (0,0,0) onto the plane z=1....
Definition: point_transform.h:20
sophus::CameraModelT::principalPoint
auto principalPoint() const -> PixelImage
Definition: camera_model.h:127
sophus::createDefaultOrthoModel
auto createDefaultOrthoModel(ImageSize image_size) -> OrthographicModel
Creates default orthographic model from image_size.
Definition: camera_model.cpp:261
sophus::CameraModel::CameraModel
CameraModel()
Definition: camera_model.h:353
sophus::CameraModelT::roi
auto roi(Eigen::Vector2i const &top_left, ImageSize roi_size) const -> CameraModelT
Region of interest given top_left and `roi_size.
Definition: camera_model.h:224
enum.h
sophus::CameraModelT::distortionParams
auto distortionParams() const -> DistorationParams
Returns distortion parameters by value.
Definition: camera_model.h:137
sophus::AffineTransform
Definition: affine.h:15
image_size.h
sophus::CameraModelT< double, AffineTransform, ProjectionZ1 >::DistorationParams
Eigen::Matrix< double, kNumDistortionParams, 1 > DistorationParams
Definition: camera_model.h:96
sophus::ImageSize
Image size, hence its width and height.
Definition: image_size.h:21
sophus::ImageSize::contains
auto contains(Eigen::Vector2i const &obs, int border=0) const -> bool
Returns true if obs is within image.
Definition: image_size.cpp:13
sophus::CameraModelT::binDown
auto binDown() const -> CameraModelT
Bins pixel down, factor of 0.5.
Definition: camera_model.h:187
sophus::CameraModel::subsampleUp
auto subsampleUp() const -> CameraModel
Subsamples pixel up, factor of 2.0.
Definition: camera_model.cpp:171
sophus::CameraModelT::setPrincipalPoint
void setPrincipalPoint(PixelImage const &principal_point)
Focal length.
Definition: camera_model.h:132
sophus::CameraModel::camProj
auto camProj(Eigen::Vector3d const &point_camera) const -> Eigen::Vector2d
Given a point in 3D space in the camera frame, compute the corresponding pixel coordinates in the ima...
Definition: camera_model.cpp:95
sophus::ProjectionZ1
Definition: projection_z1.h:15
sophus::CameraModel::principalPoint
auto principalPoint() const -> Eigen::Vector2d
Definition: camera_model.cpp:71
sophus::CameraModelT::kNumParams
static constexpr int kNumParams
Definition: camera_model.h:88