GeometricCamera.h 4.1 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 CAMERAMODELS_GEOMETRICCAMERA_H
  19. #define CAMERAMODELS_GEOMETRICCAMERA_H
  20. #include <opencv2/core/core.hpp>
  21. #include <opencv2/imgproc/imgproc.hpp>
  22. #include <opencv2/features2d/features2d.hpp>
  23. #include <boost/serialization/serialization.hpp>
  24. #include <boost/serialization/access.hpp>
  25. #include <boost/serialization/base_object.hpp>
  26. #include <boost/serialization/export.hpp>
  27. #include <boost/serialization/vector.hpp>
  28. #include <boost/serialization/assume_abstract.hpp>
  29. #include <Eigen/Geometry>
  30. namespace ORB_SLAM3 {
  31. class GeometricCamera {
  32. public:
  33. GeometricCamera() {}
  34. GeometricCamera(const std::vector<float> &_vParameters) : mvParameters(_vParameters) {}
  35. ~GeometricCamera() {}
  36. virtual cv::Point2f project(const cv::Point3f &p3D) = 0;
  37. virtual cv::Point2f project(const cv::Matx31f &m3D) = 0;
  38. virtual cv::Point2f project(const cv::Mat& m3D) = 0;
  39. virtual Eigen::Vector2d project(const Eigen::Vector3d & v3D) = 0;
  40. virtual cv::Mat projectMat(const cv::Point3f& p3D) = 0;
  41. virtual float uncertainty2(const Eigen::Matrix<double,2,1> &p2D) = 0;
  42. virtual cv::Point3f unproject(const cv::Point2f &p2D) = 0;
  43. virtual cv::Mat unprojectMat(const cv::Point2f &p2D) = 0;
  44. virtual cv::Matx31f unprojectMat_(const cv::Point2f &p2D) = 0;
  45. virtual cv::Mat projectJac(const cv::Point3f &p3D) = 0;
  46. virtual Eigen::Matrix<double,2,3> projectJac(const Eigen::Vector3d& v3D) = 0;
  47. virtual cv::Mat unprojectJac(const cv::Point2f &p2D) = 0;
  48. virtual bool ReconstructWithTwoViews(const std::vector<cv::KeyPoint>& vKeys1, const std::vector<cv::KeyPoint>& vKeys2, const std::vector<int> &vMatches12,
  49. cv::Mat &R21, cv::Mat &t21, std::vector<cv::Point3f> &vP3D, std::vector<bool> &vbTriangulated) = 0;
  50. virtual cv::Mat toK() = 0;
  51. virtual cv::Matx33f toK_() = 0;
  52. virtual bool epipolarConstrain(GeometricCamera* otherCamera, const cv::KeyPoint& kp1, const cv::KeyPoint& kp2, const cv::Mat& R12, const cv::Mat& t12, const float sigmaLevel, const float unc) = 0;
  53. virtual bool epipolarConstrain_(GeometricCamera* otherCamera, const cv::KeyPoint& kp1, const cv::KeyPoint& kp2, const cv::Matx33f& R12, const cv::Matx31f& t12, const float sigmaLevel, const float unc) = 0;
  54. float getParameter(const int i){return mvParameters[i];}
  55. void setParameter(const float p, const size_t i){mvParameters[i] = p;}
  56. size_t size(){return mvParameters.size();}
  57. virtual bool matchAndtriangulate(const cv::KeyPoint& kp1, const cv::KeyPoint& kp2, GeometricCamera* pOther,
  58. cv::Mat& Tcw1, cv::Mat& Tcw2,
  59. const float sigmaLevel1, const float sigmaLevel2,
  60. cv::Mat& x3Dtriangulated) = 0;
  61. unsigned int GetId() { return mnId; }
  62. unsigned int GetType() { return mnType; }
  63. const unsigned int CAM_PINHOLE = 0;
  64. const unsigned int CAM_FISHEYE = 1;
  65. static long unsigned int nNextId;
  66. protected:
  67. std::vector<float> mvParameters;
  68. unsigned int mnId;
  69. unsigned int mnType;
  70. };
  71. }
  72. #endif //CAMERAMODELS_GEOMETRICCAMERA_H