MSCEqF 1.0
Multi State Constraint Equivariant Filter for visual inertial navigation
Loading...
Searching...
No Matches
camera.hpp
1// Copyright (C) 2023 Alessandro Fornasier.
2// Control of Networked Systems, University of Klagenfurt, Austria.
3//
4// All rights reserved.
5//
6// This software is licensed under the terms of 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// You can contact the authors at <alessandro.fornasier@ieee.org>
19
20#ifndef CAMERA_HPP
21#define CAMERA_HPP
22
23#include <memory>
24#include <opencv2/opencv.hpp>
25
26#include "msceqf/options/msceqf_options.hpp"
27#include "types/fptypes.hpp"
28
29namespace msceqf
30{
35class PinholeCamera
36{
37 public:
38 virtual ~PinholeCamera() = default;
39
46 void undistort(std::vector<Eigen::Vector2f>& uv, const bool& normalize = false);
47
54 virtual void undistort(std::vector<cv::Point2f>& uv_cv, const bool& normalize = false) = 0;
55
62 virtual void undistortImage(const cv::Mat& image, cv::Mat& image_undistorted) = 0;
63
69 void normalize(std::vector<Eigen::Vector2f>& uv);
70
76 void normalize(std::vector<cv::Point2f>& uv);
77
83 void normalize(Eigen::Vector2f& uv);
84
90 void normalize(cv::Point2f& uv);
91
97 void denormalize(std::vector<Eigen::Vector2f>& uv);
98
104 void denormalize(std::vector<cv::Point2f>& uv);
105
111 void denormalize(Eigen::Vector2f& uv);
112
118 void denormalize(cv::Point2f& uv);
119
125 void setIntrinsics(const Vector4& intrinsics);
126
132 const Vector4& intrinsics() const;
133
139 const VectorX& distortionCoefficients() const;
140
141 protected:
142 PinholeCamera(const VectorX& distortion_coefficients,
143 const Vector4 instrinsics,
144 const uint& width,
145 const uint& height);
146
148 PinholeCamera() = delete;
149 PinholeCamera(const PinholeCamera&) = delete;
150 PinholeCamera(PinholeCamera&&) = delete;
151 PinholeCamera& operator=(const PinholeCamera&) = delete;
152 PinholeCamera& operator=(PinholeCamera&&) = delete;
153
155 Vector4 intrinsics_;
156 uint width_;
157 uint height_;
158};
159
164struct RadtanCamera final : public PinholeCamera
165{
166 RadtanCamera(const CameraOptions& opts, const Vector4& intrinsics);
167
174 void undistort(std::vector<cv::Point2f>& uv_cv, const bool& normalize) override;
175
182 void undistortImage(const cv::Mat& image, cv::Mat& image_undistorted) override;
183};
184
185struct EquidistantCamera final : public PinholeCamera
186{
187 EquidistantCamera(const CameraOptions& opts, const Vector4& intrinsics);
188
195 void undistort(std::vector<cv::Point2f>& uv_cv, const bool& normalize) override;
196
203 void undistortImage(const cv::Mat& image, cv::Mat& image_undistorted) override;
204};
205
206using PinholeCameraSharedPtr = std::shared_ptr<PinholeCamera>;
207using PinholeCameraUniquePtr = std::unique_ptr<PinholeCamera>;
208using RadtanCameraSharedPtr = std::shared_ptr<RadtanCamera>;
209using RadtanCameraUniquePtr = std::unique_ptr<RadtanCamera>;
210using EquidistantCameraSharedPtr = std::shared_ptr<EquidistantCamera>;
211using EquidistantCameraUniquePtr = std::unique_ptr<EquidistantCamera>;
212
221template <typename T>
222[[nodiscard]] static PinholeCameraUniquePtr createCamera(const CameraOptions& opts, const Vector4& intrinsics)
223{
224 if constexpr (std::is_base_of_v<PinholeCamera, T>)
225 {
226 return std::make_unique<T>(opts, intrinsics);
227 }
228 else
229 {
230 return nullptr;
231 }
232}
233
234} // namespace msceqf
235
236#endif // CAMERA_HPP
virtual void undistort(std::vector< cv::Point2f > &uv_cv, const bool &normalize=false)=0
Undistort given distorted point in OpenCV format (std::vector<cv::Point2f>).
void normalize(cv::Point2f &uv)
Normalize multiple features uv coordinates in OpenCV format (cv::Point2f).
void setIntrinsics(const Vector4 &intrinsics)
Set the value of the intrinsic parameters.
const Vector4 & intrinsics() const
Get camera intrinsics parameter (fx, fy, cx, cy) as a 4 vector.
uint height_
Image height.
Definition camera.hpp:157
void denormalize(std::vector< cv::Point2f > &uv)
Denormalize multiple features uv coordinates in OpenCV format (std::vector<cv::Point2f>).
const VectorX & distortionCoefficients() const
Get camera distortion coefficients (k1, k2, p1, p2, ...) as a vector.
void normalize(std::vector< Eigen::Vector2f > &uv)
Normalize multiple features uv coordinates in Eigen format (std::vector<Eigen::Vector2f>).
PinholeCamera()=delete
Rule of Five.
virtual void undistortImage(const cv::Mat &image, cv::Mat &image_undistorted)=0
Undistort given image in openCV format (cv::Mat).
uint width_
Image width.
Definition camera.hpp:156
void normalize(std::vector< cv::Point2f > &uv)
Normalize multiple features uv coordinates in OpenCV format (std::vector<cv::Point2f>).
void denormalize(std::vector< Eigen::Vector2f > &uv)
Denormalize multiple features uv coordinates in Eigen format (std::vector<Eigen::Vector2f>).
void normalize(Eigen::Vector2f &uv)
Normalize a single feature uv coordinates in Eigen format (Eigen::Vector2f).
void undistort(std::vector< Eigen::Vector2f > &uv, const bool &normalize=false)
Undistort given distorted point in Eigen format (std::vector<Eigen::Vector2f>).
void denormalize(Eigen::Vector2f &uv)
Denormalize a single feature uv coordinates in Eigen format (Eigen::Vector2f).
Vector4 intrinsics_
Vector of intrinsic paramater (fx, fy, cx, cy).
Definition camera.hpp:155
void denormalize(cv::Point2f &uv)
Denormalize multiple features uv coordinates in OpenCV format (cv::Point2f).
VectorX distortion_coefficients_
Vector of distortion coefficients (k1, k2, p1, p2, ...).
Definition camera.hpp:154
Definition msceqf_options.hpp:169
void undistortImage(const cv::Mat &image, cv::Mat &image_undistorted) override
Undistort given image in openCV format (cv::Mat).
void undistort(std::vector< cv::Point2f > &uv_cv, const bool &normalize) override
Undistort given distorted point in OpenCV format (std::vector<cv::Point2f>).
void undistortImage(const cv::Mat &image, cv::Mat &image_undistorted) override
Undistort given image in openCV format (cv::Mat).
void undistort(std::vector< cv::Point2f > &uv_cv, const bool &normalize) override
Undistort given distorted point in OpenCV format (std::vector<cv::Point2f>).