NASA Astrobee Robot Software  0.19.1
Flight software for the Astrobee robots operating inside the International Space Station.
distorter.h
Go to the documentation of this file.
1 /* Copyright (c) 2017, United States Government, as represented by the
2  * Administrator of the National Aeronautics and Space Administration.
3  *
4  * All rights reserved.
5  *
6  * The Astrobee platform is licensed under the Apache License, Version 2.0
7  * (the "License"); you may not use this file except in compliance with the
8  * License. You may obtain a copy of the License at
9  *
10  * http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing, software
13  * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
14  * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
15  * License for the specific language governing permissions and limitations
16  * under the License.
17  */
18 #ifndef VISION_COMMON_DISTORTER_H_
19 #define VISION_COMMON_DISTORTER_H_
20 
21 #include <Eigen/Core>
22 
23 #include <opencv2/opencv.hpp>
24 
25 #include <vector>
26 
27 namespace vision_common {
28 template <int NUM_PARAMS, typename DISTORTER>
29 class Distorter {
30  public:
31  Eigen::Vector2d Distort(const Eigen::VectorXd& distortion, const Eigen::Matrix3d& intrinsics,
32  const Eigen::Vector2d& undistorted_point) const {
33  return static_cast<DISTORTER const*>(this)->Distort(distortion.data(), intrinsics, undistorted_point);
34  }
35 
36  virtual Eigen::Vector2d Undistort(const Eigen::Vector2d& distorted_point, const Eigen::Matrix3d& intrinsics,
37  const Eigen::VectorXd& distortion) const = 0;
38 
39  std::vector<Eigen::Vector2d> Undistort(const std::vector<Eigen::Vector2d>& distorted_points,
40  const Eigen::Matrix3d& intrinsics, const Eigen::VectorXd& distortion) const {
41  std::vector<Eigen::Vector2d> undistorted_points;
42  for (const auto& distorted_point : distorted_points) {
43  undistorted_points.emplace_back(Undistort(distorted_point, intrinsics, distortion));
44  }
45  return undistorted_points;
46  }
47 
48  virtual cv::Mat Undistort(const cv::Mat& distorted_image, const Eigen::Matrix3d& intrinsics,
49  const Eigen::VectorXd& distortion) const = 0;
50 
51  static constexpr int kNumParams = NUM_PARAMS;
52 };
53 } // namespace vision_common
54 
55 #endif // VISION_COMMON_DISTORTER_H_
vive_localization::NUM_PARAMS
@ NUM_PARAMS
Definition: vive.h:64
vision_common
Definition: brisk_feature_detector_and_matcher.h:25
vision_common::Distorter
Definition: distorter.h:29
vision_common::Distorter::Distort
Eigen::Vector2d Distort(const Eigen::VectorXd &distortion, const Eigen::Matrix3d &intrinsics, const Eigen::Vector2d &undistorted_point) const
Definition: distorter.h:31
vision_common::Distorter::Undistort
std::vector< Eigen::Vector2d > Undistort(const std::vector< Eigen::Vector2d > &distorted_points, const Eigen::Matrix3d &intrinsics, const Eigen::VectorXd &distortion) const
Definition: distorter.h:39
vision_common::Distorter::Undistort
virtual Eigen::Vector2d Undistort(const Eigen::Vector2d &distorted_point, const Eigen::Matrix3d &intrinsics, const Eigen::VectorXd &distortion) const =0
vision_common::Distorter::kNumParams
static constexpr int kNumParams
Definition: distorter.h:51