SensorData.h
Go to the documentation of this file.
1 /*
2 Copyright (c) 2010-2016, Mathieu Labbe - IntRoLab - Universite de Sherbrooke
3 All rights reserved.
4 
5 Redistribution and use in source and binary forms, with or without
6 modification, are permitted provided that the following conditions are met:
7  * Redistributions of source code must retain the above copyright
8  notice, this list of conditions and the following disclaimer.
9  * Redistributions in binary form must reproduce the above copyright
10  notice, this list of conditions and the following disclaimer in the
11  documentation and/or other materials provided with the distribution.
12  * Neither the name of the Universite de Sherbrooke nor the
13  names of its contributors may be used to endorse or promote products
14  derived from this software without specific prior written permission.
15 
16 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
17 ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18 WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19 DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY
20 DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21 (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22 LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
23 ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25 SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 */
27 
28 #ifndef SENSORDATA_H_
29 #define SENSORDATA_H_
30 
32 #include <rtabmap/core/Transform.h>
35 #include <rtabmap/core/Transform.h>
37 #include <opencv2/core/core.hpp>
38 #include <opencv2/features2d/features2d.hpp>
39 #include <rtabmap/core/LaserScan.h>
40 #include <rtabmap/core/IMU.h>
41 
42 namespace rtabmap
43 {
44 
49 {
50 public:
51  // empty constructor
52  SensorData();
53 
54  // Appearance-only constructor
55  SensorData(
56  const cv::Mat & image,
57  int id = 0,
58  double stamp = 0.0,
59  const cv::Mat & userData = cv::Mat());
60 
61  // Mono constructor
62  SensorData(
63  const cv::Mat & image,
64  const CameraModel & cameraModel,
65  int id = 0,
66  double stamp = 0.0,
67  const cv::Mat & userData = cv::Mat());
68 
69  // RGB-D constructor
70  SensorData(
71  const cv::Mat & rgb,
72  const cv::Mat & depth,
73  const CameraModel & cameraModel,
74  int id = 0,
75  double stamp = 0.0,
76  const cv::Mat & userData = cv::Mat());
77 
78  // RGB-D constructor + laser scan
79  SensorData(
80  const LaserScan & laserScan,
81  const cv::Mat & rgb,
82  const cv::Mat & depth,
83  const CameraModel & cameraModel,
84  int id = 0,
85  double stamp = 0.0,
86  const cv::Mat & userData = cv::Mat());
87 
88  // Multi-cameras RGB-D constructor
89  SensorData(
90  const cv::Mat & rgb,
91  const cv::Mat & depth,
92  const std::vector<CameraModel> & cameraModels,
93  int id = 0,
94  double stamp = 0.0,
95  const cv::Mat & userData = cv::Mat());
96 
97  // Multi-cameras RGB-D constructor + laser scan
98  SensorData(
99  const LaserScan & laserScan,
100  const cv::Mat & rgb,
101  const cv::Mat & depth,
102  const std::vector<CameraModel> & cameraModels,
103  int id = 0,
104  double stamp = 0.0,
105  const cv::Mat & userData = cv::Mat());
106 
107  // Stereo constructor
108  SensorData(
109  const cv::Mat & left,
110  const cv::Mat & right,
111  const StereoCameraModel & cameraModel,
112  int id = 0,
113  double stamp = 0.0,
114  const cv::Mat & userData = cv::Mat());
115 
116  // Stereo constructor + laser scan
117  SensorData(
118  const LaserScan & laserScan,
119  const cv::Mat & left,
120  const cv::Mat & right,
121  const StereoCameraModel & cameraModel,
122  int id = 0,
123  double stamp = 0.0,
124  const cv::Mat & userData = cv::Mat());
125 
126  // IMU constructor
127  SensorData(
128  const IMU & imu,
129  int id = 0,
130  double stamp = 0.0);
131 
132  virtual ~SensorData();
133 
134  bool isValid() const {
135  return !(_id == 0 &&
136  _stamp == 0.0 &&
137  _imageRaw.empty() &&
138  _imageCompressed.empty() &&
139  _depthOrRightRaw.empty() &&
140  _depthOrRightCompressed.empty() &&
141  _laserScanRaw.isEmpty() &&
142  _laserScanCompressed.isEmpty() &&
143  _cameraModels.size() == 0 &&
144  !_stereoCameraModel.isValidForProjection() &&
145  _userDataRaw.empty() &&
146  _userDataCompressed.empty() &&
147  _keypoints.size() == 0 &&
148  _descriptors.empty() &&
149  imu_.empty());
150  }
151 
152  int id() const {return _id;}
153  void setId(int id) {_id = id;}
154  double stamp() const {return _stamp;}
155  void setStamp(double stamp) {_stamp = stamp;}
156 
157  const cv::Mat & imageCompressed() const {return _imageCompressed;}
158  const cv::Mat & depthOrRightCompressed() const {return _depthOrRightCompressed;}
159  const LaserScan & laserScanCompressed() const {return _laserScanCompressed;}
160 
161  const cv::Mat & imageRaw() const {return _imageRaw;}
162  const cv::Mat & depthOrRightRaw() const {return _depthOrRightRaw;}
163  const LaserScan & laserScanRaw() const {return _laserScanRaw;}
164  void setImageRaw(const cv::Mat & imageRaw) {_imageRaw = imageRaw;}
165  void setDepthOrRightRaw(const cv::Mat & depthOrImageRaw) {_depthOrRightRaw =depthOrImageRaw;}
166  void setLaserScanRaw(const LaserScan & laserScanRaw) {_laserScanRaw =laserScanRaw;}
167  void setCameraModel(const CameraModel & model) {_cameraModels.clear(); _cameraModels.push_back(model);}
168  void setCameraModels(const std::vector<CameraModel> & models) {_cameraModels = models;}
169  void setStereoCameraModel(const StereoCameraModel & stereoCameraModel) {_stereoCameraModel = stereoCameraModel;}
170 
171  //for convenience
172  cv::Mat depthRaw() const {return _depthOrRightRaw.type()!=CV_8UC1?_depthOrRightRaw:cv::Mat();}
173  cv::Mat rightRaw() const {return _depthOrRightRaw.type()==CV_8UC1?_depthOrRightRaw:cv::Mat();}
174 
175  void uncompressData();
176  void uncompressData(
177  cv::Mat * imageRaw,
178  cv::Mat * depthOrRightRaw,
179  LaserScan * laserScanRaw = 0,
180  cv::Mat * userDataRaw = 0,
181  cv::Mat * groundCellsRaw = 0,
182  cv::Mat * obstacleCellsRaw = 0,
183  cv::Mat * emptyCellsRaw = 0);
184  void uncompressDataConst(
185  cv::Mat * imageRaw,
186  cv::Mat * depthOrRightRaw,
187  LaserScan * laserScanRaw = 0,
188  cv::Mat * userDataRaw = 0,
189  cv::Mat * groundCellsRaw = 0,
190  cv::Mat * obstacleCellsRaw = 0,
191  cv::Mat * emptyCellsRaw = 0) const;
192 
193  const std::vector<CameraModel> & cameraModels() const {return _cameraModels;}
194  const StereoCameraModel & stereoCameraModel() const {return _stereoCameraModel;}
195 
196  void setUserDataRaw(const cv::Mat & userDataRaw); // only set raw
204  void setUserData(const cv::Mat & userData);
205  const cv::Mat & userDataRaw() const {return _userDataRaw;}
206  const cv::Mat & userDataCompressed() const {return _userDataCompressed;}
207 
208  // detect automatically if raw or compressed. If raw, the data will be compressed.
209  void setOccupancyGrid(
210  const cv::Mat & ground,
211  const cv::Mat & obstacles,
212  const cv::Mat & empty,
213  float cellSize,
214  const cv::Point3f & viewPoint);
215  // remove raw occupancy grids
216  void clearOccupancyGridRaw() {_groundCellsRaw = cv::Mat(); _obstacleCellsRaw = cv::Mat();}
217  const cv::Mat & gridGroundCellsRaw() const {return _groundCellsRaw;}
218  const cv::Mat & gridGroundCellsCompressed() const {return _groundCellsCompressed;}
219  const cv::Mat & gridObstacleCellsRaw() const {return _obstacleCellsRaw;}
220  const cv::Mat & gridObstacleCellsCompressed() const {return _obstacleCellsCompressed;}
221  const cv::Mat & gridEmptyCellsRaw() const {return _emptyCellsRaw;}
222  const cv::Mat & gridEmptyCellsCompressed() const {return _emptyCellsCompressed;}
223  float gridCellSize() const {return _cellSize;}
224  const cv::Point3f & gridViewPoint() const {return _viewPoint;}
225 
226  void setFeatures(const std::vector<cv::KeyPoint> & keypoints, const std::vector<cv::Point3f> & keypoints3D, const cv::Mat & descriptors);
227  const std::vector<cv::KeyPoint> & keypoints() const {return _keypoints;}
228  const std::vector<cv::Point3f> & keypoints3D() const {return _keypoints3D;}
229  const cv::Mat & descriptors() const {return _descriptors;}
230 
231  void setGroundTruth(const Transform & pose) {groundTruth_ = pose;}
232  const Transform & groundTruth() const {return groundTruth_;}
233 
234  void setGlobalPose(const Transform & pose, const cv::Mat & covariance) {globalPose_ = pose; globalPoseCovariance_ = covariance;}
235  const Transform & globalPose() const {return globalPose_;}
236  const cv::Mat & globalPoseCovariance() const {return globalPoseCovariance_;}
237 
238  void setGPS(const GPS & gps)
239  {
240  gps_ = gps;
241  }
242  const GPS & gps() const {return gps_;}
243 
244  void setIMU(const IMU & imu)
245  {
246  imu_ = imu;
247  }
248  const IMU & imu() const {return imu_;}
249 
250  long getMemoryUsed() const; // Return memory usage in Bytes
251  void clearCompressedData() {_imageCompressed=cv::Mat(); _depthOrRightCompressed=cv::Mat(); _laserScanCompressed.clear(); _userDataCompressed=cv::Mat();}
252 
253  bool isPointVisibleFromCameras(const cv::Point3f & pt) const; // assuming point is in robot frame
254 
255 private:
256  int _id;
257  double _stamp;
258 
259  cv::Mat _imageCompressed; // compressed image
260  cv::Mat _depthOrRightCompressed; // compressed image
261  LaserScan _laserScanCompressed; // compressed data
262 
263  cv::Mat _imageRaw; // CV_8UC1 or CV_8UC3
264  cv::Mat _depthOrRightRaw; // depth CV_16UC1 or CV_32FC1, right image CV_8UC1
266 
267  std::vector<CameraModel> _cameraModels;
269 
270  // user data
271  cv::Mat _userDataCompressed; // compressed data
272  cv::Mat _userDataRaw;
273 
274  // occupancy grid
280  cv::Mat _emptyCellsRaw;
281  float _cellSize;
282  cv::Point3f _viewPoint;
283 
284  // features
285  std::vector<cv::KeyPoint> _keypoints;
286  std::vector<cv::Point3f> _keypoints3D;
287  cv::Mat _descriptors;
288 
290 
292  cv::Mat globalPoseCovariance_; // 6x6 double
293 
295 
297 };
298 
299 }
300 
301 
302 #endif /* SENSORDATA_H_ */
cv::Mat RTABMAP_EXP uncompressData(const cv::Mat &bytes)
cv::Mat _userDataCompressed
Definition: SensorData.h:271
std::vector< cv::Point3f > _keypoints3D
Definition: SensorData.h:286
const LaserScan & laserScanCompressed() const
Definition: SensorData.h:159
Transform groundTruth_
Definition: SensorData.h:289
LaserScan _laserScanCompressed
Definition: SensorData.h:261
cv::Mat _emptyCellsRaw
Definition: SensorData.h:280
cv::Mat _depthOrRightRaw
Definition: SensorData.h:264
cv::Mat _obstacleCellsRaw
Definition: SensorData.h:279
void setGlobalPose(const Transform &pose, const cv::Mat &covariance)
Definition: SensorData.h:234
const cv::Mat & descriptors() const
Definition: SensorData.h:229
cv::Mat _groundCellsCompressed
Definition: SensorData.h:275
float gridCellSize() const
Definition: SensorData.h:223
const std::vector< cv::KeyPoint > & keypoints() const
Definition: SensorData.h:227
void setCameraModels(const std::vector< CameraModel > &models)
Definition: SensorData.h:168
void setGPS(const GPS &gps)
Definition: SensorData.h:238
void setId(int id)
Definition: SensorData.h:153
const cv::Mat & gridObstacleCellsCompressed() const
Definition: SensorData.h:220
const cv::Mat & gridGroundCellsRaw() const
Definition: SensorData.h:217
const cv::Mat & gridGroundCellsCompressed() const
Definition: SensorData.h:218
const LaserScan & laserScanRaw() const
Definition: SensorData.h:163
const Transform & groundTruth() const
Definition: SensorData.h:232
const cv::Mat & gridEmptyCellsCompressed() const
Definition: SensorData.h:222
cv::Mat _emptyCellsCompressed
Definition: SensorData.h:277
const cv::Mat & imageRaw() const
Definition: SensorData.h:161
const cv::Mat & globalPoseCovariance() const
Definition: SensorData.h:236
cv::Mat rightRaw() const
Definition: SensorData.h:173
void setImageRaw(const cv::Mat &imageRaw)
Definition: SensorData.h:164
std::vector< cv::KeyPoint > _keypoints
Definition: SensorData.h:285
void setCameraModel(const CameraModel &model)
Definition: SensorData.h:167
bool isValid() const
Definition: SensorData.h:134
#define RTABMAP_EXP
Definition: RtabmapExp.h:38
void clearOccupancyGridRaw()
Definition: SensorData.h:216
const cv::Mat & depthOrRightCompressed() const
Definition: SensorData.h:158
cv::Mat globalPoseCovariance_
Definition: SensorData.h:292
const Transform & globalPose() const
Definition: SensorData.h:235
cv::Mat _obstacleCellsCompressed
Definition: SensorData.h:276
void clearCompressedData()
Definition: SensorData.h:251
LaserScan _laserScanRaw
Definition: SensorData.h:265
const GPS & gps() const
Definition: SensorData.h:242
const cv::Mat & depthOrRightRaw() const
Definition: SensorData.h:162
const cv::Mat & userDataRaw() const
Definition: SensorData.h:205
int id() const
Definition: SensorData.h:152
double stamp() const
Definition: SensorData.h:154
const cv::Mat & userDataCompressed() const
Definition: SensorData.h:206
const cv::Mat & gridEmptyCellsRaw() const
Definition: SensorData.h:221
const IMU & imu() const
Definition: SensorData.h:248
cv::Mat _depthOrRightCompressed
Definition: SensorData.h:260
const std::vector< CameraModel > & cameraModels() const
Definition: SensorData.h:193
cv::Mat _imageCompressed
Definition: SensorData.h:259
cv::Point3f _viewPoint
Definition: SensorData.h:282
StereoCameraModel _stereoCameraModel
Definition: SensorData.h:268
const StereoCameraModel & stereoCameraModel() const
Definition: SensorData.h:194
std::vector< CameraModel > _cameraModels
Definition: SensorData.h:267
void setStamp(double stamp)
Definition: SensorData.h:155
const cv::Mat & imageCompressed() const
Definition: SensorData.h:157
Transform globalPose_
Definition: SensorData.h:291
void setIMU(const IMU &imu)
Definition: SensorData.h:244
void setGroundTruth(const Transform &pose)
Definition: SensorData.h:231
void setStereoCameraModel(const StereoCameraModel &stereoCameraModel)
Definition: SensorData.h:169
void setDepthOrRightRaw(const cv::Mat &depthOrImageRaw)
Definition: SensorData.h:165
const cv::Point3f & gridViewPoint() const
Definition: SensorData.h:224
const std::vector< cv::Point3f > & keypoints3D() const
Definition: SensorData.h:228
cv::Mat depthRaw() const
Definition: SensorData.h:172
cv::Mat _groundCellsRaw
Definition: SensorData.h:278
const cv::Mat & gridObstacleCellsRaw() const
Definition: SensorData.h:219
void setLaserScanRaw(const LaserScan &laserScanRaw)
Definition: SensorData.h:166


rtabmap
Author(s): Mathieu Labbe
autogenerated on Wed Jun 5 2019 22:41:32