ViewerAR.h 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  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 VIEWERAR_H
  19. #define VIEWERAR_H
  20. #include <mutex>
  21. #include <opencv2/core/core.hpp>
  22. #include <pangolin/pangolin.h>
  23. #include <string>
  24. #include"../../../include/System.h"
  25. namespace ORB_SLAM3
  26. {
  27. class Plane
  28. {
  29. public:
  30. Plane(const std::vector<MapPoint*> &vMPs, const cv::Mat &Tcw);
  31. Plane(const float &nx, const float &ny, const float &nz, const float &ox, const float &oy, const float &oz);
  32. void Recompute();
  33. //normal
  34. cv::Mat n;
  35. //origin
  36. cv::Mat o;
  37. //arbitrary orientation along normal
  38. float rang;
  39. //transformation from world to the plane
  40. cv::Mat Tpw;
  41. pangolin::OpenGlMatrix glTpw;
  42. //MapPoints that define the plane
  43. std::vector<MapPoint*> mvMPs;
  44. //camera pose when the plane was first observed (to compute normal direction)
  45. cv::Mat mTcw, XC;
  46. };
  47. class ViewerAR
  48. {
  49. public:
  50. ViewerAR();
  51. void SetFPS(const float fps){
  52. mFPS = fps;
  53. mT=1e3/fps;
  54. }
  55. void SetSLAM(ORB_SLAM3::System* pSystem){
  56. mpSystem = pSystem;
  57. }
  58. // Main thread function.
  59. void Run();
  60. void SetCameraCalibration(const float &fx_, const float &fy_, const float &cx_, const float &cy_){
  61. fx = fx_; fy = fy_; cx = cx_; cy = cy_;
  62. }
  63. void SetImagePose(const cv::Mat &im, const cv::Mat &Tcw, const int &status,
  64. const std::vector<cv::KeyPoint> &vKeys, const std::vector<MapPoint*> &vMPs);
  65. void GetImagePose(cv::Mat &im, cv::Mat &Tcw, int &status,
  66. std::vector<cv::KeyPoint> &vKeys, std::vector<MapPoint*> &vMPs);
  67. private:
  68. //SLAM
  69. ORB_SLAM3::System* mpSystem;
  70. void PrintStatus(const int &status, const bool &bLocMode, cv::Mat &im);
  71. void AddTextToImage(const std::string &s, cv::Mat &im, const int r=0, const int g=0, const int b=0);
  72. void LoadCameraPose(const cv::Mat &Tcw);
  73. void DrawImageTexture(pangolin::GlTexture &imageTexture, cv::Mat &im);
  74. void DrawCube(const float &size, const float x=0, const float y=0, const float z=0);
  75. void DrawPlane(int ndivs, float ndivsize);
  76. void DrawPlane(Plane* pPlane, int ndivs, float ndivsize);
  77. void DrawTrackedPoints(const std::vector<cv::KeyPoint> &vKeys, const std::vector<MapPoint*> &vMPs, cv::Mat &im);
  78. Plane* DetectPlane(const cv::Mat Tcw, const std::vector<MapPoint*> &vMPs, const int iterations=50);
  79. // frame rate
  80. float mFPS, mT;
  81. float fx,fy,cx,cy;
  82. // Last processed image and computed pose by the SLAM
  83. std::mutex mMutexPoseImage;
  84. cv::Mat mTcw;
  85. cv::Mat mImage;
  86. int mStatus;
  87. std::vector<cv::KeyPoint> mvKeys;
  88. std::vector<MapPoint*> mvMPs;
  89. };
  90. }
  91. #endif // VIEWERAR_H