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  // Multi-cameras stereo constructor
130  SensorData(
131  const cv::Mat & rgb,
132  const cv::Mat & depth,
133  const std::vector<StereoCameraModel> & cameraModels,
134  int id = 0,
135  double stamp = 0.0,
136  const cv::Mat & userData = cv::Mat());
137 
138  // Multi-cameras stereo constructor + laser scan
139  SensorData(
140  const LaserScan & laserScan,
141  const cv::Mat & rgb,
142  const cv::Mat & depth,
143  const std::vector<StereoCameraModel> & cameraModels,
144  int id = 0,
145  double stamp = 0.0,
146  const cv::Mat & userData = cv::Mat());
147 
148  // IMU constructor
149  SensorData(
150  const IMU & imu,
151  int id = 0,
152  double stamp = 0.0);
153 
154  virtual ~SensorData();
155 
156  bool isValid() const {
157  return !(_id == 0 &&
158  _stamp == 0.0 &&
159  _imageRaw.empty() &&
160  _imageCompressed.empty() &&
161  _depthOrRightRaw.empty() &&
162  _depthOrRightCompressed.empty() &&
163  _laserScanRaw.isEmpty() &&
164  _laserScanCompressed.isEmpty() &&
165  _cameraModels.empty() &&
166  _stereoCameraModels.empty() &&
167  _userDataRaw.empty() &&
168  _userDataCompressed.empty() &&
169  _keypoints.size() == 0 &&
170  _descriptors.empty() &&
171  imu_.empty());
172  }
173 
174  int id() const {return _id;}
175  void setId(int id) {_id = id;}
176  double stamp() const {return _stamp;}
177  void setStamp(double stamp) {_stamp = stamp;}
178 
179  const cv::Mat & imageCompressed() const {return _imageCompressed;}
180  const cv::Mat & depthOrRightCompressed() const {return _depthOrRightCompressed;}
181  const LaserScan & laserScanCompressed() const {return _laserScanCompressed;}
182 
183  const cv::Mat & imageRaw() const {return _imageRaw;}
184  const cv::Mat & depthOrRightRaw() const {return _depthOrRightRaw;}
185  const LaserScan & laserScanRaw() const {return _laserScanRaw;}
186 
192  void setRGBDImage(const cv::Mat & rgb, const cv::Mat & depth, const CameraModel & model, bool clearPreviousData = true);
193  void setRGBDImage(const cv::Mat & rgb, const cv::Mat & depth, const std::vector<CameraModel> & models, bool clearPreviousData = true);
194  void setStereoImage(const cv::Mat & left, const cv::Mat & right, const StereoCameraModel & stereoCameraModel, bool clearPreviousData = true);
195  void setStereoImage(const cv::Mat & left, const cv::Mat & right, const std::vector<StereoCameraModel> & stereoCameraModels, bool clearPreviousData = true);
196 
202  void setLaserScan(const LaserScan & laserScan, bool clearPreviousData = true);
203 
204  void setCameraModel(const CameraModel & model) {_cameraModels.clear(); _cameraModels.push_back(model);}
205  void setCameraModels(const std::vector<CameraModel> & models) {_cameraModels = models;}
206  void setStereoCameraModel(const StereoCameraModel & stereoCameraModel) {_stereoCameraModels.clear(); _stereoCameraModels.push_back(stereoCameraModel);}
207  void setStereoCameraModels(const std::vector<StereoCameraModel> & stereoCameraModels) {_stereoCameraModels = stereoCameraModels;}
208 
209  //for convenience
210  cv::Mat depthRaw() const {return _depthOrRightRaw.type()!=CV_8UC1?_depthOrRightRaw:cv::Mat();}
211  cv::Mat rightRaw() const {return _depthOrRightRaw.type()==CV_8UC1?_depthOrRightRaw:cv::Mat();}
212 
213  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.");
214  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.");
215  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.");
216  RTABMAP_DEPRECATED(void setUserDataRaw(const cv::Mat & data), "Use setUserData() or removeRawData() instead.");
217 
218  void uncompressData();
219  void uncompressData(
220  cv::Mat * imageRaw,
221  cv::Mat * depthOrRightRaw,
222  LaserScan * laserScanRaw = 0,
223  cv::Mat * userDataRaw = 0,
224  cv::Mat * groundCellsRaw = 0,
225  cv::Mat * obstacleCellsRaw = 0,
226  cv::Mat * emptyCellsRaw = 0);
227  void uncompressDataConst(
228  cv::Mat * imageRaw,
229  cv::Mat * depthOrRightRaw,
230  LaserScan * laserScanRaw = 0,
231  cv::Mat * userDataRaw = 0,
232  cv::Mat * groundCellsRaw = 0,
233  cv::Mat * obstacleCellsRaw = 0,
234  cv::Mat * emptyCellsRaw = 0) const;
235 
236  const std::vector<CameraModel> & cameraModels() const {return _cameraModels;}
237  const std::vector<StereoCameraModel> & stereoCameraModels() const {return _stereoCameraModels;}
238 
247  void setUserData(const cv::Mat & userData, bool clearPreviousData = true);
248  const cv::Mat & userDataRaw() const {return _userDataRaw;}
249  const cv::Mat & userDataCompressed() const {return _userDataCompressed;}
250 
251  // detect automatically if raw or compressed. If raw, the data will be compressed.
252  void setOccupancyGrid(
253  const cv::Mat & ground,
254  const cv::Mat & obstacles,
255  const cv::Mat & empty,
256  float cellSize,
257  const cv::Point3f & viewPoint);
258  // remove raw occupancy grids
259  void clearOccupancyGridRaw() {_groundCellsRaw = cv::Mat(); _obstacleCellsRaw = cv::Mat();}
260  const cv::Mat & gridGroundCellsRaw() const {return _groundCellsRaw;}
261  const cv::Mat & gridGroundCellsCompressed() const {return _groundCellsCompressed;}
262  const cv::Mat & gridObstacleCellsRaw() const {return _obstacleCellsRaw;}
263  const cv::Mat & gridObstacleCellsCompressed() const {return _obstacleCellsCompressed;}
264  const cv::Mat & gridEmptyCellsRaw() const {return _emptyCellsRaw;}
265  const cv::Mat & gridEmptyCellsCompressed() const {return _emptyCellsCompressed;}
266  float gridCellSize() const {return _cellSize;}
267  const cv::Point3f & gridViewPoint() const {return _viewPoint;}
268 
269  void setFeatures(const std::vector<cv::KeyPoint> & keypoints, const std::vector<cv::Point3f> & keypoints3D, const cv::Mat & descriptors);
270  const std::vector<cv::KeyPoint> & keypoints() const {return _keypoints;}
271  const std::vector<cv::Point3f> & keypoints3D() const {return _keypoints3D;}
272  const cv::Mat & descriptors() const {return _descriptors;}
273 
274  void addGlobalDescriptor(const GlobalDescriptor & descriptor) {_globalDescriptors.push_back(descriptor);}
275  void setGlobalDescriptors(const std::vector<GlobalDescriptor> & descriptors) {_globalDescriptors = descriptors;}
276  void clearGlobalDescriptors() {_globalDescriptors.clear();}
277  const std::vector<GlobalDescriptor> & globalDescriptors() const {return _globalDescriptors;}
278 
279  void setGroundTruth(const Transform & pose) {groundTruth_ = pose;}
280  const Transform & groundTruth() const {return groundTruth_;}
281 
282  void setGlobalPose(const Transform & pose, const cv::Mat & covariance) {globalPose_ = pose; globalPoseCovariance_ = covariance;}
283  const Transform & globalPose() const {return globalPose_;}
284  const cv::Mat & globalPoseCovariance() const {return globalPoseCovariance_;}
285 
286  void setGPS(const GPS & gps) {gps_ = gps;}
287  const GPS & gps() const {return gps_;}
288 
289  void setIMU(const IMU & imu) {imu_ = imu; }
290  const IMU & imu() const {return imu_;}
291 
292  void setEnvSensors(const EnvSensors & sensors) {_envSensors = sensors;}
293  void addEnvSensor(const EnvSensor & sensor) {_envSensors.insert(std::make_pair(sensor.type(), sensor));}
294  const EnvSensors & envSensors() const {return _envSensors;}
295 
296  void setLandmarks(const Landmarks & landmarks) {_landmarks = landmarks;}
297  const Landmarks & landmarks() const {return _landmarks;}
298 
299  unsigned long getMemoryUsed() const; // Return memory usage in Bytes
304  void clearCompressedData(bool images = true, bool scan = true, bool userData = true);
309  void clearRawData(bool images = true, bool scan = true, bool userData = true);
310 
311  bool isPointVisibleFromCameras(const cv::Point3f & pt) const; // assuming point is in robot frame
312 
313 private:
314  int _id;
315  double _stamp;
316 
317  cv::Mat _imageCompressed; // compressed image
318  cv::Mat _depthOrRightCompressed; // compressed image
319  LaserScan _laserScanCompressed; // compressed data
320 
321  cv::Mat _imageRaw; // CV_8UC1 or CV_8UC3
322  cv::Mat _depthOrRightRaw; // depth CV_16UC1 or CV_32FC1, right image CV_8UC1
324 
325  std::vector<CameraModel> _cameraModels;
326  std::vector<StereoCameraModel> _stereoCameraModels;
327 
328  // user data
329  cv::Mat _userDataCompressed; // compressed data
330  cv::Mat _userDataRaw;
331 
332  // occupancy grid
338  cv::Mat _emptyCellsRaw;
339  float _cellSize;
340  cv::Point3f _viewPoint;
341 
342  // environmental sensors
344 
345  // landmarks
347 
348  // features
349  std::vector<cv::KeyPoint> _keypoints;
350  std::vector<cv::Point3f> _keypoints3D;
351  cv::Mat _descriptors;
352 
353  // global descriptors
354  std::vector<GlobalDescriptor> _globalDescriptors;
355 
357 
359  cv::Mat globalPoseCovariance_; // 6x6 double
360 
362 
364 };
365 
366 }
367 
368 
369 #endif /* SENSORDATA_H_ */
const Type & type() const
Definition: EnvSensor.h:71
cv::Mat RTABMAP_EXP uncompressData(const cv::Mat &bytes)
const cv::Mat & gridObstacleCellsCompressed() const
Definition: SensorData.h:263
std::vector< GlobalDescriptor > _globalDescriptors
Definition: SensorData.h:354
Landmarks _landmarks
Definition: SensorData.h:346
cv::Mat _userDataCompressed
Definition: SensorData.h:329
const std::vector< cv::Point3f > & keypoints3D() const
Definition: SensorData.h:271
const Transform & globalPose() const
Definition: SensorData.h:283
std::vector< cv::Point3f > _keypoints3D
Definition: SensorData.h:350
Transform groundTruth_
Definition: SensorData.h:356
LaserScan _laserScanCompressed
Definition: SensorData.h:319
cv::Mat _emptyCellsRaw
Definition: SensorData.h:338
const LaserScan & laserScanCompressed() const
Definition: SensorData.h:181
std::vector< StereoCameraModel > _stereoCameraModels
Definition: SensorData.h:326
cv::Mat _depthOrRightRaw
Definition: SensorData.h:322
cv::Mat _obstacleCellsRaw
Definition: SensorData.h:337
const cv::Mat & gridGroundCellsCompressed() const
Definition: SensorData.h:261
void setStereoCameraModels(const std::vector< StereoCameraModel > &stereoCameraModels)
Definition: SensorData.h:207
void setGlobalPose(const Transform &pose, const cv::Mat &covariance)
Definition: SensorData.h:282
void clearGlobalDescriptors()
Definition: SensorData.h:276
const cv::Mat & depthOrRightRaw() const
Definition: SensorData.h:184
data
std::map< int, Landmark > Landmarks
Definition: Landmark.h:78
const std::vector< StereoCameraModel > & stereoCameraModels() const
Definition: SensorData.h:237
const std::vector< cv::KeyPoint > & keypoints() const
Definition: SensorData.h:270
cv::Mat _groundCellsCompressed
Definition: SensorData.h:333
void setCameraModels(const std::vector< CameraModel > &models)
Definition: SensorData.h:205
void setGPS(const GPS &gps)
Definition: SensorData.h:286
void setId(int id)
Definition: SensorData.h:175
cv::Mat _emptyCellsCompressed
Definition: SensorData.h:335
const std::vector< GlobalDescriptor > & globalDescriptors() const
Definition: SensorData.h:277
RTABMAP_DEPRECATED(typedef SensorData Image, "rtabmap::Image class is renamed to rtabmap::SensorData, use the last one instead.")
const cv::Mat & globalPoseCovariance() const
Definition: SensorData.h:284
float gridCellSize() const
Definition: SensorData.h:266
cv::Mat rightRaw() const
Definition: SensorData.h:211
std::vector< cv::KeyPoint > _keypoints
Definition: SensorData.h:349
void setCameraModel(const CameraModel &model)
Definition: SensorData.h:204
void addEnvSensor(const EnvSensor &sensor)
Definition: SensorData.h:293
#define RTABMAP_EXP
Definition: RtabmapExp.h:38
void clearOccupancyGridRaw()
Definition: SensorData.h:259
int id() const
Definition: SensorData.h:174
const std::vector< CameraModel > & cameraModels() const
Definition: SensorData.h:236
void addGlobalDescriptor(const GlobalDescriptor &descriptor)
Definition: SensorData.h:274
cv::Mat globalPoseCovariance_
Definition: SensorData.h:359
const GPS & gps() const
Definition: SensorData.h:287
cv::Mat _obstacleCellsCompressed
Definition: SensorData.h:334
cv::Mat depthRaw() const
Definition: SensorData.h:210
const cv::Mat & imageRaw() const
Definition: SensorData.h:183
const EnvSensors & envSensors() const
Definition: SensorData.h:294
const cv::Mat & descriptors() const
Definition: SensorData.h:272
LaserScan _laserScanRaw
Definition: SensorData.h:323
void setEnvSensors(const EnvSensors &sensors)
Definition: SensorData.h:292
const cv::Mat & depthOrRightCompressed() const
Definition: SensorData.h:180
const Transform & groundTruth() const
Definition: SensorData.h:280
cv::Mat _depthOrRightCompressed
Definition: SensorData.h:318
const cv::Point3f & gridViewPoint() const
Definition: SensorData.h:267
cv::Mat _imageCompressed
Definition: SensorData.h:317
cv::Point3f _viewPoint
Definition: SensorData.h:340
const LaserScan & laserScanRaw() const
Definition: SensorData.h:185
const cv::Mat & userDataRaw() const
Definition: SensorData.h:248
EnvSensors _envSensors
Definition: SensorData.h:343
void setGlobalDescriptors(const std::vector< GlobalDescriptor > &descriptors)
Definition: SensorData.h:275
const cv::Mat & gridEmptyCellsRaw() const
Definition: SensorData.h:264
const cv::Mat & userDataCompressed() const
Definition: SensorData.h:249
const cv::Mat & gridGroundCellsRaw() const
Definition: SensorData.h:260
double stamp() const
Definition: SensorData.h:176
std::vector< CameraModel > _cameraModels
Definition: SensorData.h:325
void setStamp(double stamp)
Definition: SensorData.h:177
Transform globalPose_
Definition: SensorData.h:358
model
Definition: trace.py:4
void setLandmarks(const Landmarks &landmarks)
Definition: SensorData.h:296
void setIMU(const IMU &imu)
Definition: SensorData.h:289
void setGroundTruth(const Transform &pose)
Definition: SensorData.h:279
const cv::Mat & gridObstacleCellsRaw() const
Definition: SensorData.h:262
const Landmarks & landmarks() const
Definition: SensorData.h:297
std::map< EnvSensor::Type, EnvSensor > EnvSensors
Definition: EnvSensor.h:81
const IMU & imu() const
Definition: SensorData.h:290
const cv::Mat & gridEmptyCellsCompressed() const
Definition: SensorData.h:265
bool isValid() const
Definition: SensorData.h:156
void setStereoCameraModel(const StereoCameraModel &stereoCameraModel)
Definition: SensorData.h:206
const cv::Mat & imageCompressed() const
Definition: SensorData.h:179
cv::Mat _groundCellsRaw
Definition: SensorData.h:336


rtabmap
Author(s): Mathieu Labbe
autogenerated on Mon Jan 23 2023 03:37:30