OSVR-Core
UndistortMeasurements.h
Go to the documentation of this file.
1 
11 // Copyright 2016 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_UndistortMeasurements_h_GUID_EBA50677_306F_4985_BC70_393C58140FE4
26 #define INCLUDED_UndistortMeasurements_h_GUID_EBA50677_306F_4985_BC70_393C58140FE4
27 
28 // Internal Includes
29 #include "LedMeasurement.h"
30 #include "cvToEigen.h"
31 #include "CameraParameters.h"
32 #include "CameraDistortionModel.h"
33 
34 // Library/third-party includes
36 
37 // Standard includes
38 #include <vector>
39 #include <algorithm>
40 
41 namespace osvr {
42 namespace vbtracker {
44  inline LedMeasurementVec
45  undistortLeds(LedMeasurementVec const &distortedMeasurements,
46  CameraParameters const &camParams) {
47  LedMeasurementVec ret;
48  ret.resize(distortedMeasurements.size());
49  auto distortionModel = CameraDistortionModel{
50  Eigen::Vector2d{camParams.focalLengthX(), camParams.focalLengthY()},
51  cvToVector(camParams.principalPoint()),
52  Eigen::Vector3d{camParams.k1(), camParams.k2(), camParams.k3()}};
53  auto ledUndistort = [&distortionModel](LedMeasurement const &meas) {
54  LedMeasurement ret{meas};
55  Eigen::Vector2d undistorted = distortionModel.undistortPoint(
56  cvToVector(meas.loc).cast<double>());
57  ret.loc = vecToPoint(undistorted.cast<float>());
58  return ret;
59  };
60  std::transform(begin(distortedMeasurements), end(distortedMeasurements),
61  begin(ret), ledUndistort);
62  return ret;
63  }
64 } // namespace vbtracker
65 } // namespace osvr
66 #endif // INCLUDED_UndistortMeasurements_h_GUID_EBA50677_306F_4985_BC70_393C58140FE4
The main namespace for all C++ elements of the framework, internal and external.
Definition: namespace_osvr.dox:3
Definition: CameraParameters.h:41
Header wrapping include of <Eigen/Core> and <Eigen/Geometry> for warning quieting.
cv::Point2f loc
Location in image space - should be undistorted when passed to the Led class.
Definition: LedMeasurement.h:77
t_< detail::transform_< List, Fun >> transform
Given a list and an alias class, apply the alias class to each element in the list and return the res...
Definition: Transform.h:54
LedMeasurementVec undistortLeds(LedMeasurementVec const &distortedMeasurements, CameraParameters const &camParams)
Perform the undistortion of LED measurements.
Definition: UndistortMeasurements.h:45
Header.
Definition: LedMeasurement.h:41
Definition: CameraDistortionModel.h:39