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>
36 #include <opencv2/core/core.hpp>
37 #include <opencv2/features2d/features2d.hpp>
38 #include <rtabmap/core/LaserScan.h>
39 #include <rtabmap/core/IMU.h>
40 #include <rtabmap/core/GPS.h>
41 #include <rtabmap/core/EnvSensor.h>
42 #include <rtabmap/core/Landmark.h>
44 
45 namespace rtabmap
46 {
47 
52 {
53 public:
54  // empty constructor
55  SensorData();
56 
57  // Appearance-only constructor
58  SensorData(
59  const cv::Mat & image,
60  int id = 0,
61  double stamp = 0.0,
62  const cv::Mat & userData = cv::Mat());
63 
64  // Mono constructor
65  SensorData(
66  const cv::Mat & image,
67  const CameraModel & cameraModel,
68  int id = 0,
69  double stamp = 0.0,
70  const cv::Mat & userData = cv::Mat());
71 
72  // RGB-D constructor
73  SensorData(
74  const cv::Mat & rgb,
75  const cv::Mat & depth,
76  const CameraModel & cameraModel,
77  int id = 0,
78  double stamp = 0.0,
79  const cv::Mat & userData = cv::Mat());
80 
81  // RGB-D constructor + laser scan
82  SensorData(
83  const LaserScan & laserScan,
84  const cv::Mat & rgb,
85  const cv::Mat & depth,
86  const CameraModel & cameraModel,
87  int id = 0,
88  double stamp = 0.0,
89  const cv::Mat & userData = cv::Mat());
90 
91  // Multi-cameras RGB-D constructor
92  SensorData(
93  const cv::Mat & rgb,
94  const cv::Mat & depth,
95  const std::vector<CameraModel> & cameraModels,
96  int id = 0,
97  double stamp = 0.0,
98  const cv::Mat & userData = cv::Mat());
99 
100  // Multi-cameras RGB-D constructor + laser scan
101  SensorData(
102  const LaserScan & laserScan,
103  const cv::Mat & rgb,
104  const cv::Mat & depth,
105  const std::vector<CameraModel> & cameraModels,
106  int id = 0,
107  double stamp = 0.0,
108  const cv::Mat & userData = cv::Mat());
109 
110  // Stereo constructor
111  SensorData(
112  const cv::Mat & left,
113  const cv::Mat & right,
114  const StereoCameraModel & cameraModel,
115  int id = 0,
116  double stamp = 0.0,
117  const cv::Mat & userData = cv::Mat());
118 
119  // Stereo constructor + laser scan
120  SensorData(
121  const LaserScan & laserScan,
122  const cv::Mat & left,
123  const cv::Mat & right,
124  const StereoCameraModel & cameraModel,
125  int id = 0,
126  double stamp = 0.0,
127  const cv::Mat & userData = cv::Mat());
128 
129  // IMU constructor
130  SensorData(
131  const IMU & imu,
132  int id = 0,
133  double stamp = 0.0);
134 
135  virtual ~SensorData();
136 
137  bool isValid() const {
138  return !(_id == 0 &&
139  _stamp == 0.0 &&
140  _imageRaw.empty() &&
141  _imageCompressed.empty() &&
142  _depthOrRightRaw.empty() &&
143  _depthOrRightCompressed.empty() &&
144  _laserScanRaw.isEmpty() &&
145  _laserScanCompressed.isEmpty() &&
146  _cameraModels.size() == 0 &&
147  !_stereoCameraModel.isValidForProjection() &&
148  _userDataRaw.empty() &&
149  _userDataCompressed.empty() &&
150  _keypoints.size() == 0 &&
151  _descriptors.empty() &&
152  imu_.empty());
153  }
154 
155  int id() const {return _id;}
156  void setId(int id) {_id = id;}
157  double stamp() const {return _stamp;}
158  void setStamp(double stamp) {_stamp = stamp;}
159 
160  const cv::Mat & imageCompressed() const {return _imageCompressed;}
161  const cv::Mat & depthOrRightCompressed() const {return _depthOrRightCompressed;}
162  const LaserScan & laserScanCompressed() const {return _laserScanCompressed;}
163 
164  const cv::Mat & imageRaw() const {return _imageRaw;}
165  const cv::Mat & depthOrRightRaw() const {return _depthOrRightRaw;}
166  const LaserScan & laserScanRaw() const {return _laserScanRaw;}
167 
173  void setRGBDImage(const cv::Mat & rgb, const cv::Mat & depth, const CameraModel & model, bool clearPreviousData = true);
174  void setRGBDImage(const cv::Mat & rgb, const cv::Mat & depth, const std::vector<CameraModel> & models, bool clearPreviousData = true);
175  void setStereoImage(const cv::Mat & left, const cv::Mat & right, const StereoCameraModel & stereoCameraModel, bool clearPreviousData = true);
176 
182  void setLaserScan(const LaserScan & laserScan, bool clearPreviousData = true);
183 
184  void setCameraModel(const CameraModel & model) {_cameraModels.clear(); _cameraModels.push_back(model);}
185  void setCameraModels(const std::vector<CameraModel> & models) {_cameraModels = models;}
186  void setStereoCameraModel(const StereoCameraModel & stereoCameraModel) {_stereoCameraModel = stereoCameraModel;}
187 
188  //for convenience
189  cv::Mat depthRaw() const {return _depthOrRightRaw.type()!=CV_8UC1?_depthOrRightRaw:cv::Mat();}
190  cv::Mat rightRaw() const {return _depthOrRightRaw.type()==CV_8UC1?_depthOrRightRaw:cv::Mat();}
191 
192  RTABMAP_DEPRECATED(void setImageRaw(const cv::Mat & image), "Use setRGBDImage() or setStereoImage() with clearNotUpdated=false or removeRawData() instead. To be backward compatible, this function doesn't clear compressed data.");
193  RTABMAP_DEPRECATED(void setDepthOrRightRaw(const cv::Mat & image), "Use setRGBDImage() or setStereoImage() with clearNotUpdated=false or removeRawData() instead. To be backward compatible, this function doesn't clear compressed data.");
194  RTABMAP_DEPRECATED(void setLaserScanRaw(const LaserScan & scan), "Use setLaserScan() with clearNotUpdated=false or removeRawData() instead. To be backward compatible, this function doesn't clear compressed data.");
195  RTABMAP_DEPRECATED(void setUserDataRaw(const cv::Mat & data), "Use setUserData() or removeRawData() instead.");
196 
197  void uncompressData();
198  void uncompressData(
199  cv::Mat * imageRaw,
200  cv::Mat * depthOrRightRaw,
201  LaserScan * laserScanRaw = 0,
202  cv::Mat * userDataRaw = 0,
203  cv::Mat * groundCellsRaw = 0,
204  cv::Mat * obstacleCellsRaw = 0,
205  cv::Mat * emptyCellsRaw = 0);
206  void uncompressDataConst(
207  cv::Mat * imageRaw,
208  cv::Mat * depthOrRightRaw,
209  LaserScan * laserScanRaw = 0,
210  cv::Mat * userDataRaw = 0,
211  cv::Mat * groundCellsRaw = 0,
212  cv::Mat * obstacleCellsRaw = 0,
213  cv::Mat * emptyCellsRaw = 0) const;
214 
215  const std::vector<CameraModel> & cameraModels() const {return _cameraModels;}
216  const StereoCameraModel & stereoCameraModel() const {return _stereoCameraModel;}
217 
226  void setUserData(const cv::Mat & userData, bool clearPreviousData = true);
227  const cv::Mat & userDataRaw() const {return _userDataRaw;}
228  const cv::Mat & userDataCompressed() const {return _userDataCompressed;}
229 
230  // detect automatically if raw or compressed. If raw, the data will be compressed.
231  void setOccupancyGrid(
232  const cv::Mat & ground,
233  const cv::Mat & obstacles,
234  const cv::Mat & empty,
235  float cellSize,
236  const cv::Point3f & viewPoint);
237  // remove raw occupancy grids
238  void clearOccupancyGridRaw() {_groundCellsRaw = cv::Mat(); _obstacleCellsRaw = cv::Mat();}
239  const cv::Mat & gridGroundCellsRaw() const {return _groundCellsRaw;}
240  const cv::Mat & gridGroundCellsCompressed() const {return _groundCellsCompressed;}
241  const cv::Mat & gridObstacleCellsRaw() const {return _obstacleCellsRaw;}
242  const cv::Mat & gridObstacleCellsCompressed() const {return _obstacleCellsCompressed;}
243  const cv::Mat & gridEmptyCellsRaw() const {return _emptyCellsRaw;}
244  const cv::Mat & gridEmptyCellsCompressed() const {return _emptyCellsCompressed;}
245  float gridCellSize() const {return _cellSize;}
246  const cv::Point3f & gridViewPoint() const {return _viewPoint;}
247 
248  void setFeatures(const std::vector<cv::KeyPoint> & keypoints, const std::vector<cv::Point3f> & keypoints3D, const cv::Mat & descriptors);
249  const std::vector<cv::KeyPoint> & keypoints() const {return _keypoints;}
250  const std::vector<cv::Point3f> & keypoints3D() const {return _keypoints3D;}
251  const cv::Mat & descriptors() const {return _descriptors;}
252 
253  void addGlobalDescriptor(const GlobalDescriptor & descriptor) {_globalDescriptors.push_back(descriptor);}
254  void setGlobalDescriptors(const std::vector<GlobalDescriptor> & descriptors) {_globalDescriptors = descriptors;}
255  void clearGlobalDescriptors() {_globalDescriptors.clear();}
256  const std::vector<GlobalDescriptor> & globalDescriptors() const {return _globalDescriptors;}
257 
258  void setGroundTruth(const Transform & pose) {groundTruth_ = pose;}
259  const Transform & groundTruth() const {return groundTruth_;}
260 
261  void setGlobalPose(const Transform & pose, const cv::Mat & covariance) {globalPose_ = pose; globalPoseCovariance_ = covariance;}
262  const Transform & globalPose() const {return globalPose_;}
263  const cv::Mat & globalPoseCovariance() const {return globalPoseCovariance_;}
264 
265  void setGPS(const GPS & gps) {gps_ = gps;}
266  const GPS & gps() const {return gps_;}
267 
268  void setIMU(const IMU & imu) {imu_ = imu; }
269  const IMU & imu() const {return imu_;}
270 
271  void setEnvSensors(const EnvSensors & sensors) {_envSensors = sensors;}
272  void addEnvSensor(const EnvSensor & sensor) {_envSensors.insert(std::make_pair(sensor.type(), sensor));}
273  const EnvSensors & envSensors() const {return _envSensors;}
274 
275  void setLandmarks(const Landmarks & landmarks) {_landmarks = landmarks;}
276  const Landmarks & landmarks() const {return _landmarks;}
277 
278  unsigned long getMemoryUsed() const; // Return memory usage in Bytes
283  void clearCompressedData(bool images = true, bool scan = true, bool userData = true);
288  void clearRawData(bool images = true, bool scan = true, bool userData = true);
289 
290  bool isPointVisibleFromCameras(const cv::Point3f & pt) const; // assuming point is in robot frame
291 
292 private:
293  int _id;
294  double _stamp;
295 
296  cv::Mat _imageCompressed; // compressed image
297  cv::Mat _depthOrRightCompressed; // compressed image
298  LaserScan _laserScanCompressed; // compressed data
299 
300  cv::Mat _imageRaw; // CV_8UC1 or CV_8UC3
301  cv::Mat _depthOrRightRaw; // depth CV_16UC1 or CV_32FC1, right image CV_8UC1
303 
304  std::vector<CameraModel> _cameraModels;
306 
307  // user data
308  cv::Mat _userDataCompressed; // compressed data
309  cv::Mat _userDataRaw;
310 
311  // occupancy grid
317  cv::Mat _emptyCellsRaw;
318  float _cellSize;
319  cv::Point3f _viewPoint;
320 
321  // environmental sensors
323 
324  // landmarks
326 
327  // features
328  std::vector<cv::KeyPoint> _keypoints;
329  std::vector<cv::Point3f> _keypoints3D;
330  cv::Mat _descriptors;
331 
332  // global descriptors
333  std::vector<GlobalDescriptor> _globalDescriptors;
334 
336 
338  cv::Mat globalPoseCovariance_; // 6x6 double
339 
341 
343 };
344 
345 }
346 
347 
348 #endif /* SENSORDATA_H_ */
cv::Mat RTABMAP_EXP uncompressData(const cv::Mat &bytes)
std::vector< GlobalDescriptor > _globalDescriptors
Definition: SensorData.h:333
Landmarks _landmarks
Definition: SensorData.h:325
cv::Mat _userDataCompressed
Definition: SensorData.h:308
std::vector< cv::Point3f > _keypoints3D
Definition: SensorData.h:329
const LaserScan & laserScanCompressed() const
Definition: SensorData.h:162
Transform groundTruth_
Definition: SensorData.h:335
LaserScan _laserScanCompressed
Definition: SensorData.h:298
cv::Mat _emptyCellsRaw
Definition: SensorData.h:317
cv::Mat _depthOrRightRaw
Definition: SensorData.h:301
cv::Mat _obstacleCellsRaw
Definition: SensorData.h:316
void setGlobalPose(const Transform &pose, const cv::Mat &covariance)
Definition: SensorData.h:261
void clearGlobalDescriptors()
Definition: SensorData.h:255
std::map< int, Landmark > Landmarks
Definition: Landmark.h:72
const cv::Mat & descriptors() const
Definition: SensorData.h:251
cv::Mat _groundCellsCompressed
Definition: SensorData.h:312
float gridCellSize() const
Definition: SensorData.h:245
const std::vector< cv::KeyPoint > & keypoints() const
Definition: SensorData.h:249
void setCameraModels(const std::vector< CameraModel > &models)
Definition: SensorData.h:185
void setGPS(const GPS &gps)
Definition: SensorData.h:265
void setId(int id)
Definition: SensorData.h:156
const cv::Mat & gridObstacleCellsCompressed() const
Definition: SensorData.h:242
const cv::Mat & gridGroundCellsRaw() const
Definition: SensorData.h:239
const cv::Mat & gridGroundCellsCompressed() const
Definition: SensorData.h:240
const LaserScan & laserScanRaw() const
Definition: SensorData.h:166
const Transform & groundTruth() const
Definition: SensorData.h:259
const cv::Mat & gridEmptyCellsCompressed() const
Definition: SensorData.h:244
cv::Mat _emptyCellsCompressed
Definition: SensorData.h:314
const EnvSensors & envSensors() const
Definition: SensorData.h:273
const cv::Mat & imageRaw() const
Definition: SensorData.h:164
const cv::Mat & globalPoseCovariance() const
Definition: SensorData.h:263
cv::Mat rightRaw() const
Definition: SensorData.h:190
std::vector< cv::KeyPoint > _keypoints
Definition: SensorData.h:328
void setCameraModel(const CameraModel &model)
Definition: SensorData.h:184
void addEnvSensor(const EnvSensor &sensor)
Definition: SensorData.h:272
bool isValid() const
Definition: SensorData.h:137
#define RTABMAP_EXP
Definition: RtabmapExp.h:38
void clearOccupancyGridRaw()
Definition: SensorData.h:238
void addGlobalDescriptor(const GlobalDescriptor &descriptor)
Definition: SensorData.h:253
const cv::Mat & depthOrRightCompressed() const
Definition: SensorData.h:161
cv::Mat globalPoseCovariance_
Definition: SensorData.h:338
const Transform & globalPose() const
Definition: SensorData.h:262
cv::Mat _obstacleCellsCompressed
Definition: SensorData.h:313
const Type & type() const
Definition: EnvSensor.h:71
LaserScan _laserScanRaw
Definition: SensorData.h:302
const GPS & gps() const
Definition: SensorData.h:266
const cv::Mat & depthOrRightRaw() const
Definition: SensorData.h:165
const cv::Mat & userDataRaw() const
Definition: SensorData.h:227
int id() const
Definition: SensorData.h:155
void setEnvSensors(const EnvSensors &sensors)
Definition: SensorData.h:271
double stamp() const
Definition: SensorData.h:157
const std::vector< GlobalDescriptor > & globalDescriptors() const
Definition: SensorData.h:256
const cv::Mat & userDataCompressed() const
Definition: SensorData.h:228
const cv::Mat & gridEmptyCellsRaw() const
Definition: SensorData.h:243
const IMU & imu() const
Definition: SensorData.h:269
cv::Mat _depthOrRightCompressed
Definition: SensorData.h:297
const Landmarks & landmarks() const
Definition: SensorData.h:276
const std::vector< CameraModel > & cameraModels() const
Definition: SensorData.h:215
cv::Mat _imageCompressed
Definition: SensorData.h:296
cv::Point3f _viewPoint
Definition: SensorData.h:319
EnvSensors _envSensors
Definition: SensorData.h:322
void setGlobalDescriptors(const std::vector< GlobalDescriptor > &descriptors)
Definition: SensorData.h:254
StereoCameraModel _stereoCameraModel
Definition: SensorData.h:305
const StereoCameraModel & stereoCameraModel() const
Definition: SensorData.h:216
std::vector< CameraModel > _cameraModels
Definition: SensorData.h:304
void setStamp(double stamp)
Definition: SensorData.h:158
const cv::Mat & imageCompressed() const
Definition: SensorData.h:160
Transform globalPose_
Definition: SensorData.h:337
void setLandmarks(const Landmarks &landmarks)
Definition: SensorData.h:275
void setIMU(const IMU &imu)
Definition: SensorData.h:268
void setGroundTruth(const Transform &pose)
Definition: SensorData.h:258
std::map< EnvSensor::Type, EnvSensor > EnvSensors
Definition: EnvSensor.h:81
RTABMAP_DEPRECATED(typedef SensorData Image,"rtabmap::Image class is renamed to rtabmap::SensorData, use the last one instead.")
void setStereoCameraModel(const StereoCameraModel &stereoCameraModel)
Definition: SensorData.h:186
const cv::Point3f & gridViewPoint() const
Definition: SensorData.h:246
const std::vector< cv::Point3f > & keypoints3D() const
Definition: SensorData.h:250
cv::Mat depthRaw() const
Definition: SensorData.h:189
cv::Mat _groundCellsRaw
Definition: SensorData.h:315
const cv::Mat & gridObstacleCellsRaw() const
Definition: SensorData.h:241


rtabmap
Author(s): Mathieu Labbe
autogenerated on Mon Dec 14 2020 03:35:00