GeometricTools.h 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. /**
  2. * This file is part of ORB-SLAM3
  3. *
  4. * Copyright (C) 2017-2021 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 GEOMETRIC_TOOLS_H
  19. #define GEOMETRIC_TOOLS_H
  20. #include <opencv2/core/core.hpp>
  21. #include <sophus/se3.hpp>
  22. #include <Eigen/Core>
  23. namespace ORB_SLAM3
  24. {
  25. class KeyFrame;
  26. class GeometricTools
  27. {
  28. public:
  29. EIGEN_MAKE_ALIGNED_OPERATOR_NEW
  30. // Compute the Fundamental matrix between KF1 and KF2
  31. static Eigen::Matrix3f ComputeF12(KeyFrame* &pKF1, KeyFrame* &pKF2);
  32. //Triangulate point with KF1 and KF2
  33. static bool Triangulate(Eigen::Vector3f &x_c1, Eigen::Vector3f &x_c2,Eigen::Matrix<float,3,4> &Tc1w ,Eigen::Matrix<float,3,4> &Tc2w , Eigen::Vector3f &x3D);
  34. template<int rows, int cols>
  35. static bool CheckMatrices(const cv::Mat &cvMat, const Eigen::Matrix<float,rows,cols> &eigMat) {
  36. const float epsilon = 1e-3;
  37. // std::cout << cvMat.cols - cols << cvMat.rows - rows << std::endl;
  38. if(rows != cvMat.rows || cols != cvMat.cols) {
  39. std::cout << "wrong cvmat size\n";
  40. return false;
  41. }
  42. for(int i = 0; i < rows; i++)
  43. for(int j = 0; j < cols; j++)
  44. if ((cvMat.at<float>(i,j) > (eigMat(i,j) + epsilon)) ||
  45. (cvMat.at<float>(i,j) < (eigMat(i,j) - epsilon))){
  46. std::cout << "cv mat:\n" << cvMat << std::endl;
  47. std::cout << "eig mat:\n" << eigMat << std::endl;
  48. return false;
  49. }
  50. return true;
  51. }
  52. template<typename T, int rows, int cols>
  53. static bool CheckMatrices( const Eigen::Matrix<T,rows,cols> &eigMat1, const Eigen::Matrix<T,rows,cols> &eigMat2) {
  54. const float epsilon = 1e-3;
  55. for(int i = 0; i < rows; i++)
  56. for(int j = 0; j < cols; j++)
  57. if ((eigMat1(i,j) > (eigMat2(i,j) + epsilon)) ||
  58. (eigMat1(i,j) < (eigMat2(i,j) - epsilon))){
  59. std::cout << "eig mat 1:\n" << eigMat1 << std::endl;
  60. std::cout << "eig mat 2:\n" << eigMat2 << std::endl;
  61. return false;
  62. }
  63. return true;
  64. }
  65. };
  66. }// namespace ORB_SLAM
  67. #endif // GEOMETRIC_TOOLS_H