OSVR-Core
CameraDistortionModel.h
Go to the documentation of this file.
1 
11 // Copyright 2015 Sensics, Inc.
12 //
13 // Licensed under the Apache License, Version 2.0 (the "License");
14 // you may not use this file except in compliance with the License.
15 // You may obtain a copy of the License at
16 //
17 // http://www.apache.org/licenses/LICENSE-2.0
18 //
19 // Unless required by applicable law or agreed to in writing, software
20 // distributed under the License is distributed on an "AS IS" BASIS,
21 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
22 // See the License for the specific language governing permissions and
23 // limitations under the License.
24 
25 #ifndef INCLUDED_CameraDistortionModel_h_GUID_9A7F6C37_8AE6_40AC_DB51_C9B7B21F9871
26 #define INCLUDED_CameraDistortionModel_h_GUID_9A7F6C37_8AE6_40AC_DB51_C9B7B21F9871
27 
28 // Internal Includes
29 // - none
30 
31 // Library/third-party includes
33 
34 // Standard includes
35 // - none
36 
37 namespace osvr {
38 namespace vbtracker {
40  public:
41  EIGEN_MAKE_ALIGNED_OPERATOR_NEW
42  CameraDistortionModel(Eigen::Vector2d const &focalLengths,
43  Eigen::Vector2d const &centerOfProjectionPixels,
44  Eigen::Vector3d const &k)
45  : m_fl(focalLengths), m_c(centerOfProjectionPixels), m_k(k) {}
46  Eigen::Vector2d undistortPoint(Eigen::Vector2d const &pointd) const {
47  Eigen::Vector2d normalizedDistorted =
48  ((pointd - m_c).array() / m_fl.array()).matrix();
49  double r2 = normalizedDistorted.squaredNorm();
50  Eigen::Vector2d normalizedUndistorted =
51  normalizedDistorted *
52  (1 + m_k[0] * r2 + m_k[1] * r2 * r2 + m_k[2] * r2 * r2 * r2);
53  Eigen::Vector2d undistorted =
54  (normalizedUndistorted.array() * m_fl.array()).matrix() + m_c;
55  return undistorted;
56  }
57 
58  private:
59  Eigen::Vector2d m_fl;
61  Eigen::Vector2d m_c;
62  Eigen::Vector3d m_k;
63  };
64 } // namespace vbtracker
65 } // namespace osvr
66 #endif // INCLUDED_CameraDistortionModel_h_GUID_9A7F6C37_8AE6_40AC_DB51_C9B7B21F9871
The main namespace for all C++ elements of the framework, internal and external.
Definition: namespace_osvr.dox:3
Header wrapping include of <Eigen/Core> and <Eigen/Geometry> for warning quieting.
Definition: CameraDistortionModel.h:39