AliceVision
Photogrammetric Computer Vision Framework
Distortion.hpp
1 // This file is part of the AliceVision project.
2 // Copyright (c) 2016 AliceVision contributors.
3 // Copyright (c) 2012 openMVG contributors.
4 // This Source Code Form is subject to the terms of the Mozilla Public License,
5 // v. 2.0. If a copy of the MPL was not distributed with this file,
6 // You can obtain one at https://mozilla.org/MPL/2.0/.
7 
8 #pragma once
9 
10 #include <aliceVision/camera/cameraCommon.hpp>
11 
12 #include <aliceVision/numeric/numeric.hpp>
13 
14 #include <vector>
15 
16 namespace aliceVision {
17 namespace camera {
18 
24 {
25  public:
26  Distortion() = default;
27 
28  virtual EDISTORTION getType() const = 0;
29 
30  virtual Distortion* clone() const = 0;
31 
32  // not virtual as child classes do not hold any data
33  bool operator==(const Distortion& other) const { return _distortionParams == other._distortionParams; }
34 
35  void setParameters(const std::vector<double>& params)
36  {
37  if (_distortionParams.size() != params.size())
38  {
39  return;
40  }
41 
42  for (std::size_t i = 0; i < _distortionParams.size(); i++)
43  {
44  _distortionParams[i] = params[i];
45  }
46  }
47 
48  inline std::vector<double>& getParameters() { return _distortionParams; }
49 
50  inline const std::vector<double>& getParameters() const { return _distortionParams; }
51 
52  inline std::size_t getDistortionParametersCount() const { return _distortionParams.size(); }
53 
55  virtual Vec2 addDistortion(const Vec2& p) const { return p; }
56 
58  virtual Vec2 removeDistortion(const Vec2& p) const { return p; }
59 
60  virtual double getUndistortedRadius(double r) const { return r; }
61 
62  virtual Eigen::Matrix2d getDerivativeAddDistoWrtPt([[maybe_unused]] const Vec2& p) const { return Eigen::Matrix2d::Identity(); }
63 
64  virtual Eigen::MatrixXd getDerivativeAddDistoWrtDisto([[maybe_unused]] const Vec2& p) const { return Eigen::MatrixXd(0, 0); }
65 
66  virtual Eigen::Matrix2d getDerivativeRemoveDistoWrtPt([[maybe_unused]] const Vec2& p) const { return Eigen::Matrix2d::Identity(); }
67 
68  virtual Eigen::MatrixXd getDerivativeRemoveDistoWrtDisto([[maybe_unused]] const Vec2& p) const { return Eigen::MatrixXd(0, 0); }
69 
70  inline void setLocked(bool lock) { _isLocked = lock; }
71 
72  inline bool isLocked() const { return _isLocked; }
73 
74  virtual ~Distortion() = default;
75 
76  protected:
77  std::vector<double> _distortionParams{};
78  bool _isLocked{false};
79 };
80 
81 } // namespace camera
82 } // namespace aliceVision
aliceVision::camera::Distortion
Abstract class to model the distortion of a camera-lense couple using a set of parameters.
Definition: Distortion.hpp:23
aliceVision
Definition: checkerDetector.cpp:32
aliceVision::camera::Distortion::removeDistortion
virtual Vec2 removeDistortion(const Vec2 &p) const
Remove distortion (return p' such that disto(p') = p)
Definition: Distortion.hpp:58
aliceVision::camera::Distortion::addDistortion
virtual Vec2 addDistortion(const Vec2 &p) const
Add distortion to the point p (assume p is in the camera frame [normalized coordinates])
Definition: Distortion.hpp:55