ekf_cal  0.4.0
A Kalman filter-based sensor calibration package
camera.hpp
1 // Copyright 2022 Jacob Hartzer
2 //
3 // This program is free software: you can redistribute it and/or modify
4 // it under the terms of the GNU General Public License as published by
5 // the Free Software Foundation, either version 3 of the License, or
6 // (at your option) any later version.
7 //
8 // This program is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 // GNU General Public License for more details.
12 //
13 // You should have received a copy of the GNU General Public License
14 // along with this program. If not, see <https://www.gnu.org/licenses/>.
15 
16 #ifndef SENSORS__CAMERA_HPP_
17 #define SENSORS__CAMERA_HPP_
18 
19 #include <eigen3/Eigen/Eigen>
20 
21 #include <algorithm>
22 #include <map>
23 #include <memory>
24 #include <string>
25 #include <vector>
26 
27 #include <opencv2/opencv.hpp>
28 
29 #include "ekf/types.hpp"
30 #include "sensors/camera_message.hpp"
31 #include "sensors/sensor.hpp"
32 #include "trackers/feature_tracker.hpp"
33 #include "trackers/fiducial_tracker.hpp"
34 
35 
40 class Camera : public Sensor
41 {
42 public:
46  typedef struct Parameters : public Sensor::Parameters
47  {
48  bool is_extrinsic{false};
49  Eigen::Vector3d pos_c_in_b{0.0, 0.0, 0.0};
50  Eigen::Quaterniond ang_c_to_b{1.0, 0.0, 0.0, 0.0};
51  double pos_stability {1e-9};
52  double ang_stability {1e-9};
53  Eigen::VectorXd variance {{0, 0, 0, 0, 0, 0}};
54  std::string tracker;
55  std::string fiducial;
58 
63  explicit Camera(Camera::Parameters cam_params);
64 
69  void AddTracker(std::shared_ptr<FeatureTracker> tracker);
70 
75  void AddFiducial(std::shared_ptr<FiducialTracker> fiducial);
76 
81  void Callback(std::shared_ptr<CameraMessage> camera_message);
82 
83  cv::Mat m_out_img{0, 0, CV_8UC1};
84 
85 protected:
86  unsigned int GenerateFrameID();
87 
88  std::shared_ptr<EKF> m_ekf;
89 
90 private:
91  std::map<unsigned int, std::shared_ptr<FeatureTracker>> m_trackers;
92  std::map<unsigned int, std::shared_ptr<FiducialTracker>> m_fiducials;
93 
94  std::vector<double> m_rad_distortion_k{0.0, 0.0, 0.0};
95  std::vector<double> m_tan_distortion_d{0.0, 0.0};
96 };
97 
98 #endif // SENSORS__CAMERA_HPP_
Camera Sensor Class.
Definition: camera.hpp:41
cv::Mat m_out_img
Published output test image.
Definition: camera.hpp:83
Camera::Parameters Parameters
Camera initialization parameters structure.
std::shared_ptr< EKF > m_ekf
EKF to update.
Definition: camera.hpp:88
void Callback(std::shared_ptr< CameraMessage > camera_message)
Callback method for camera.
Definition: camera.cpp:57
void AddTracker(std::shared_ptr< FeatureTracker > tracker)
Method to add tracker object to camera sensor.
Definition: camera.cpp:104
unsigned int GenerateFrameID()
Definition: camera.cpp:98
void AddFiducial(std::shared_ptr< FiducialTracker > fiducial)
Method to add fiducial object to camera sensor.
Definition: camera.cpp:109
Camera(Camera::Parameters cam_params)
Camera sensor constructor.
Definition: camera.cpp:37
Camera intrinsics data structure.
Definition: types.hpp:49
Pure base sensor class.
Definition: sensor.hpp:32
Camera initialization parameters structure.
Definition: camera.hpp:47
Eigen::Vector3d pos_c_in_b
Camera initial position offset.
Definition: camera.hpp:49
std::string fiducial
Fiducial name.
Definition: camera.hpp:55
bool is_extrinsic
Flag for extrinsic calibration.
Definition: camera.hpp:48
Eigen::Quaterniond ang_c_to_b
Camera initial angular offset.
Definition: camera.hpp:50
Eigen::VectorXd variance
Initial state variance.
Definition: camera.hpp:53
double pos_stability
Position stability.
Definition: camera.hpp:51
Intrinsics intrinsics
Camera intrinsics.
Definition: camera.hpp:56
std::string tracker
Tracker name.
Definition: camera.hpp:54
double ang_stability
Angular stability.
Definition: camera.hpp:52
Sensor parameter structure.
Definition: sensor.hpp:38