SLProject  4.2.000
A platform independent 3D computer graphics framework for desktop OS, Android, iOS and online in web browsers
WAIFrame.h
Go to the documentation of this file.
1 /**
2  * \file WAIFrame.h
3  * \date Dez 2017
4  * \authors Raúl Mur-Artal, Marcus Hudritsch, Michael Goettlicher
5  * \copyright http://opensource.org/licenses/GPL-3.0
6  * \remarks Please use clangformat to format the code. See more code style on
7  * https://github.com/cpvrlab/SLProject4/wiki/SLProject-Coding-Style
8 
9 */
10 /**
11  * This file is part of ORB-SLAM2.
12  *
13  * Copyright (C) 2014-2016 Raúl Mur-Artal <raulmur at unizar dot es> (University of Zaragoza)
14  * For more information see <https://github.com/raulmur/ORB_SLAM2>
15  *
16  * ORB-SLAM2 is free software: you can redistribute it and/or modify
17  * it under the terms of the GNU General Public License as published by
18  * the Free Software Foundation, either version 3 of the License, or
19  * (at your option) any later version.
20  *
21  * ORB-SLAM2 is distributed in the hope that it will be useful,
22  * but WITHOUT ANY WARRANTY; without even the implied warranty of
23  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24  * GNU General Public License for more details.
25  *
26  * You should have received a copy of the GNU General Public License
27  * along with ORB-SLAM2. If not, see <http://www.gnu.org/licenses/>.
28  */
29 
30 #ifndef WAIFRAME_H
31 #define WAIFRAME_H
32 
33 #include <WAIHelper.h>
34 
35 #include <opencv2/opencv.hpp>
36 #include <WAIOrbVocabulary.h>
37 #include <orb_slam/ORBextractor.h>
38 #include <vector>
39 
40 class WAIMapPoint;
41 class WAIKeyFrame;
42 
43 #define FRAME_GRID_ROWS 36 //48
44 #define FRAME_GRID_COLS 64
45 
46 using namespace ORB_SLAM2;
47 
49 {
50 public:
51  WAIFrame();
52  //!copy constructor
53  WAIFrame(const WAIFrame& frame);
54  //!constructor used for detection in tracking
55  WAIFrame(const cv::Mat& imGray, const double& timeStamp, KPextractor* extractor, cv::Mat& K, cv::Mat& distCoef, WAIOrbVocabulary* vocabulary, bool retainImg = false);
56 
57  // Extract feature points on the image
58  void ExtractFeaturePoints(const cv::Mat& im);
59 
60  // Compute Bag of Words representation.
61  void ComputeBoW();
62 
63  // Set the camera pose. (world wrt camera)
64  void SetPose(cv::Mat Tcw);
65 
66  // Computes rotation, translation and camera center matrices from the camera pose.
67  void UpdatePoseMatrices();
68 
69  // Returns the camera center.
70  inline cv::Mat GetCameraCenter()
71  {
72  return mOw.clone();
73  }
74 
75  // Returns inverse of rotation
76  inline cv::Mat GetRotationInverse()
77  {
78  return mRwc.clone();
79  }
80 
81  //ghm1: added
82  inline cv::Mat GetTranslationCW()
83  {
84  return mtcw.clone();
85  }
86 
87  //ghm1: added
88  inline cv::Mat GetRotationCW()
89  {
90  return mRcw.clone();
91  }
92 
93  // Check if a MapPoint is in the frustum of the camera
94  // and fill variables of the MapPoint to be used by the tracking
95  bool isInFrustum(WAIMapPoint* pMP, float viewingCosLimit);
96 
97  // Compute the cell of a keypoint (return false if outside the grid)
98  bool PosInGrid(const cv::KeyPoint& kp, int& posX, int& posY);
99 
100  std::vector<size_t> GetFeaturesInArea(const float& x, const float& y, const float& r, const int minLevel = -1, const int maxLevel = -1) const;
101 
102 public:
103  // Vocabulary used for relocalization.
104  WAIOrbVocabulary* mVocabulary = NULL;
105 
106  // Feature extractor. The right is used only in the stereo case.
107  KPextractor* mpORBextractorLeft = NULL;
108 
109  // Frame timestamp.
110  double mTimeStamp;
111 
112  // Calibration matrix and OpenCV distortion parameters.
113  cv::Mat mK;
114  static float fx;
115  static float fy;
116  static float cx;
117  static float cy;
118  static float invfx;
119  static float invfy;
120  cv::Mat mDistCoef;
121 
122  // Number of KeyPoints.
123  int N = 0;
124 
125  // Vector of keypoints (original for visualization) and undistorted (actually used by the system).
126  // In the stereo case, mvKeysUn is redundant as images must be rectified.
127  // In the RGB-D case, RGB images can be distorted.
128  std::vector<cv::KeyPoint> mvKeys;
129  std::vector<cv::KeyPoint> mvKeysUn;
130 
131  // Corresponding stereo coordinate and depth for each keypoint.
132  // "Monocular" keypoints have a negative value.
133  std::vector<float> mvuRight;
134  std::vector<float> mvDepth;
135 
136  // Bag of Words Vector structures.
137  WAIBowVector mBowVec; //ghm1: used for search of relocalization candidates similar to current frame
139 
140  // ORB descriptor, each row associated to a keypoint.
141  cv::Mat mDescriptors;
142 
143  // MapPoints associated to keypoints, NULL pointer if no association.
144  //ghm1: this is a vector in the size of the number of detected keypoints in this frame. It is
145  //initialized with a NULL pointer. If the matcher could associate a map point with with keypoint i, then
146  //mvpMapPoints[i] will contain the pointer to this associated mapPoint.
147  std::vector<WAIMapPoint*> mvpMapPoints;
148 
149  // Keypoints are assigned to cells in a grid to reduce matching complexity when projecting MapPoints.
150  static float mfGridElementWidthInv;
152  std::vector<std::size_t> mGrid[FRAME_GRID_COLS][FRAME_GRID_ROWS];
153 
154  // Camera pose.
155  cv::Mat mTcw;
156 
157  // Current and Next Frame id.
158  static long unsigned int nNextId;
159  long unsigned int mnId = -1;
160 
161  // Reference Keyframe.
162  //ghm1: the reference keyframe is changed after initialization (pKFini),
163  //in UpdateLocalKeyFrames it gets assigned the keyframe which observes the most points in the current local map (pKFmax) and
164  //if a new Keyframe is created in CreateNewKeyFrame() this is automatically the new reference keyframe
165  WAIKeyFrame* mpReferenceKF = NULL;
166 
167  // Scale pyramid info.
171  std::vector<float> mvScaleFactors;
172  std::vector<float> mvInvScaleFactors;
173  std::vector<float> mvLevelSigma2;
174  std::vector<float> mvInvLevelSigma2;
175 
176  // Undistorted Image Bounds (computed once).
177  static float mnMinX;
178  static float mnMaxX;
179  static float mnMinY;
180  static float mnMaxY;
181 
183 
184  //frame image
185  cv::Mat imgGray;
186 
187 private:
188  // Undistort keypoints given OpenCV distortion parameters.
189  // Only for the RGB-D case. Stereo must be already rectified!
190  // (called in the constructor).
191  void UndistortKeyPoints();
192 
193  // Computes image bounds for the undistorted image (called in the constructor).
194  void ComputeImageBounds(const cv::Mat& imLeft);
195 
196  // Assign keypoints to the grid for speed up feature matching (called in the constructor).
197  void AssignFeaturesToGrid();
198 
199  // Rotation, translation and camera center
200  cv::Mat mRcw;
201  cv::Mat mtcw;
202  cv::Mat mRwc;
203  cv::Mat mOw; //==mtwc
204 };
205 
206 #endif // WAIFRAME_H
#define FRAME_GRID_COLS
Definition: WAIFrame.h:44
#define FRAME_GRID_ROWS
Definition: WAIFrame.h:43
#define WAI_API
Definition: WAIHelper.h:36
cv::Mat mTcw
Definition: WAIFrame.h:155
float mfScaleFactor
Definition: WAIFrame.h:169
static float cx
Definition: WAIFrame.h:116
WAIFeatVector mFeatVec
Definition: WAIFrame.h:138
static float fx
Definition: WAIFrame.h:114
cv::Mat mDescriptors
Definition: WAIFrame.h:141
cv::Mat GetCameraCenter()
Definition: WAIFrame.h:70
cv::Mat mtcw
Definition: WAIFrame.h:201
cv::Mat mRcw
Definition: WAIFrame.h:200
int mnScaleLevels
Definition: WAIFrame.h:168
std::vector< float > mvScaleFactors
Definition: WAIFrame.h:171
static float mnMaxX
Definition: WAIFrame.h:178
static float fy
Definition: WAIFrame.h:115
static float cy
Definition: WAIFrame.h:117
cv::Mat mDistCoef
Definition: WAIFrame.h:120
std::vector< float > mvDepth
Definition: WAIFrame.h:134
std::vector< float > mvLevelSigma2
Definition: WAIFrame.h:173
static float mnMinY
Definition: WAIFrame.h:179
std::vector< WAIMapPoint * > mvpMapPoints
Definition: WAIFrame.h:147
WAIBowVector mBowVec
Definition: WAIFrame.h:137
static float mfGridElementHeightInv
Definition: WAIFrame.h:151
cv::Mat imgGray
Definition: WAIFrame.h:185
static float invfx
Definition: WAIFrame.h:118
std::vector< float > mvInvScaleFactors
Definition: WAIFrame.h:172
std::vector< cv::KeyPoint > mvKeys
Definition: WAIFrame.h:128
static float mnMaxY
Definition: WAIFrame.h:180
static long unsigned int nNextId
Definition: WAIFrame.h:158
std::vector< float > mvInvLevelSigma2
Definition: WAIFrame.h:174
cv::Mat GetRotationCW()
Definition: WAIFrame.h:88
cv::Mat GetRotationInverse()
Definition: WAIFrame.h:76
cv::Mat mK
Definition: WAIFrame.h:113
static float mnMinX
Definition: WAIFrame.h:177
static float mfGridElementWidthInv
Definition: WAIFrame.h:150
cv::Mat GetTranslationCW()
Definition: WAIFrame.h:82
std::vector< cv::KeyPoint > mvKeysUn
Definition: WAIFrame.h:129
cv::Mat mRwc
Definition: WAIFrame.h:202
float mfLogScaleFactor
Definition: WAIFrame.h:170
double mTimeStamp
Definition: WAIFrame.h:110
static bool mbInitialComputations
Definition: WAIFrame.h:182
std::vector< float > mvuRight
Definition: WAIFrame.h:133
cv::Mat mOw
Definition: WAIFrame.h:203
static float invfy
Definition: WAIFrame.h:119
AR Keyframe node class.
Definition: WAIKeyFrame.h:60