Initializer.h 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. /**
  2. * This file is part of ORB-SLAM3
  3. *
  4. * Copyright (C) 2017-2020 Carlos Campos, Richard Elvira, Juan J. Gómez Rodríguez, José M.M. Montiel and Juan D. Tardós, University of Zaragoza.
  5. * Copyright (C) 2014-2016 Raúl Mur-Artal, José M.M. Montiel and Juan D. Tardós, University of Zaragoza.
  6. *
  7. * ORB-SLAM3 is free software: you can redistribute it and/or modify it under the terms of the GNU General Public
  8. * License as published by the Free Software Foundation, either version 3 of the License, or
  9. * (at your option) any later version.
  10. *
  11. * ORB-SLAM3 is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even
  12. * the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU General Public License along with ORB-SLAM3.
  16. * If not, see <http://www.gnu.org/licenses/>.
  17. */
  18. #ifndef INITIALIZER_H
  19. #define INITIALIZER_H
  20. #include<opencv2/opencv.hpp>
  21. #include "Frame.h"
  22. #include <unordered_set>
  23. namespace ORB_SLAM3
  24. {
  25. class Map;
  26. // THIS IS THE INITIALIZER FOR MONOCULAR SLAM. NOT USED IN THE STEREO OR RGBD CASE.
  27. class Initializer
  28. {
  29. typedef pair<int,int> Match;
  30. public:
  31. // Fix the reference frame
  32. Initializer(const Frame &ReferenceFrame, float sigma = 1.0, int iterations = 200);
  33. // Computes in parallel a fundamental matrix and a homography
  34. // Selects a model and tries to recover the motion and the structure from motion
  35. bool Initialize(const Frame &CurrentFrame, const vector<int> &vMatches12, cv::Mat &R21,
  36. cv::Mat &t21, vector<cv::Point3f> &vP3D, vector<bool> &vbTriangulated);
  37. private:
  38. void FindHomography(vector<bool> &vbMatchesInliers, float &score, cv::Mat &H21);
  39. void FindFundamental(vector<bool> &vbInliers, float &score, cv::Mat &F21);
  40. cv::Mat ComputeH21(const vector<cv::Point2f> &vP1, const vector<cv::Point2f> &vP2);
  41. cv::Mat ComputeF21(const vector<cv::Point2f> &vP1, const vector<cv::Point2f> &vP2);
  42. float CheckHomography(const cv::Mat &H21, const cv::Mat &H12, vector<bool> &vbMatchesInliers, float sigma);
  43. float CheckFundamental(const cv::Mat &F21, vector<bool> &vbMatchesInliers, float sigma);
  44. bool ReconstructF(vector<bool> &vbMatchesInliers, cv::Mat &F21, cv::Mat &K,
  45. cv::Mat &R21, cv::Mat &t21, vector<cv::Point3f> &vP3D, vector<bool> &vbTriangulated, float minParallax, int minTriangulated);
  46. bool ReconstructH(vector<bool> &vbMatchesInliers, cv::Mat &H21, cv::Mat &K,
  47. cv::Mat &R21, cv::Mat &t21, vector<cv::Point3f> &vP3D, vector<bool> &vbTriangulated, float minParallax, int minTriangulated);
  48. void Triangulate(const cv::KeyPoint &kp1, const cv::KeyPoint &kp2, const cv::Mat &P1, const cv::Mat &P2, cv::Mat &x3D);
  49. void Normalize(const vector<cv::KeyPoint> &vKeys, vector<cv::Point2f> &vNormalizedPoints, cv::Mat &T);
  50. // void Normalize(const vector<cv::Point2f> &vKeys, vector<cv::Point2f> &vNormalizedPoints, cv::Mat &T);
  51. int CheckRT(const cv::Mat &R, const cv::Mat &t, const vector<cv::KeyPoint> &vKeys1, const vector<cv::KeyPoint> &vKeys2,
  52. const vector<Match> &vMatches12, vector<bool> &vbInliers,
  53. const cv::Mat &K, vector<cv::Point3f> &vP3D, float th2, vector<bool> &vbGood, float &parallax);
  54. void DecomposeE(const cv::Mat &E, cv::Mat &R1, cv::Mat &R2, cv::Mat &t);
  55. // Keypoints from Reference Frame (Frame 1)
  56. vector<cv::KeyPoint> mvKeys1;
  57. // Keypoints from Current Frame (Frame 2)
  58. vector<cv::KeyPoint> mvKeys2;
  59. // Current Matches from Reference to Current
  60. vector<Match> mvMatches12;
  61. vector<bool> mvbMatched1;
  62. // Calibration
  63. cv::Mat mK;
  64. // Standard Deviation and Variance
  65. float mSigma, mSigma2;
  66. // Ransac max iterations
  67. int mMaxIterations;
  68. // Ransac sets
  69. vector<vector<size_t> > mvSets;
  70. GeometricCamera* mpCamera;
  71. };
  72. } //namespace ORB_SLAM
  73. #endif // INITIALIZER_H