TwoViewReconstruction.h 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  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 TwoViewReconstruction_H
  19. #define TwoViewReconstruction_H
  20. #include<opencv2/opencv.hpp>
  21. #include <unordered_set>
  22. namespace ORB_SLAM3
  23. {
  24. class TwoViewReconstruction
  25. {
  26. typedef std::pair<int,int> Match;
  27. public:
  28. // Fix the reference frame
  29. TwoViewReconstruction(cv::Mat& k, float sigma = 1.0, int iterations = 200);
  30. // Computes in parallel a fundamental matrix and a homography
  31. // Selects a model and tries to recover the motion and the structure from motion
  32. bool Reconstruct(const std::vector<cv::KeyPoint>& vKeys1, const std::vector<cv::KeyPoint>& vKeys2, const std::vector<int> &vMatches12,
  33. cv::Mat &R21, cv::Mat &t21, std::vector<cv::Point3f> &vP3D, std::vector<bool> &vbTriangulated);
  34. private:
  35. void FindHomography(std::vector<bool> &vbMatchesInliers, float &score, cv::Mat &H21);
  36. void FindFundamental(std::vector<bool> &vbInliers, float &score, cv::Mat &F21);
  37. cv::Mat ComputeH21(const std::vector<cv::Point2f> &vP1, const std::vector<cv::Point2f> &vP2);
  38. cv::Mat ComputeF21(const std::vector<cv::Point2f> &vP1, const std::vector<cv::Point2f> &vP2);
  39. float CheckHomography(const cv::Mat &H21, const cv::Mat &H12, std::vector<bool> &vbMatchesInliers, float sigma);
  40. float CheckFundamental(const cv::Mat &F21, std::vector<bool> &vbMatchesInliers, float sigma);
  41. bool ReconstructF(std::vector<bool> &vbMatchesInliers, cv::Mat &F21, cv::Mat &K,
  42. cv::Mat &R21, cv::Mat &t21, std::vector<cv::Point3f> &vP3D, std::vector<bool> &vbTriangulated, float minParallax, int minTriangulated);
  43. bool ReconstructH(std::vector<bool> &vbMatchesInliers, cv::Mat &H21, cv::Mat &K,
  44. cv::Mat &R21, cv::Mat &t21, std::vector<cv::Point3f> &vP3D,std:: vector<bool> &vbTriangulated, float minParallax, int minTriangulated);
  45. void Triangulate(const cv::KeyPoint &kp1, const cv::KeyPoint &kp2, const cv::Mat &P1, const cv::Mat &P2, cv::Mat &x3D);
  46. void Normalize(const std::vector<cv::KeyPoint> &vKeys, std::vector<cv::Point2f> &vNormalizedPoints, cv::Mat &T);
  47. int CheckRT(const cv::Mat &R, const cv::Mat &t, const std::vector<cv::KeyPoint> &vKeys1, const std::vector<cv::KeyPoint> &vKeys2,
  48. const std::vector<Match> &vMatches12, std::vector<bool> &vbInliers,
  49. const cv::Mat &K, std::vector<cv::Point3f> &vP3D, float th2, std::vector<bool> &vbGood, float &parallax);
  50. void DecomposeE(const cv::Mat &E, cv::Mat &R1, cv::Mat &R2, cv::Mat &t);
  51. // Keypoints from Reference Frame (Frame 1)
  52. std::vector<cv::KeyPoint> mvKeys1;
  53. // Keypoints from Current Frame (Frame 2)
  54. std::vector<cv::KeyPoint> mvKeys2;
  55. // Current Matches from Reference to Current
  56. std::vector<Match> mvMatches12;
  57. std::vector<bool> mvbMatched1;
  58. // Calibration
  59. cv::Mat mK;
  60. // Standard Deviation and Variance
  61. float mSigma, mSigma2;
  62. // Ransac max iterations
  63. int mMaxIterations;
  64. // Ransac sets
  65. std::vector<std::vector<size_t> > mvSets;
  66. };
  67. } //namespace ORB_SLAM
  68. #endif // TwoViewReconstruction_H