43 #include <pcl/common/common.h> 52 "rtabmap-rgbd_dataset [options] path\n" 53 " path Folder of the sequence (e.g., \"~/rgbd_dataset_freiburg3_long_office_household\")\n" 54 " containing least rgb_sync and depth_sync folders. These folders contain\n" 55 " synchronized images using associate.py tool (use tool version from\n" 56 " https://gist.github.com/matlabbe/484134a2d9da8ad425362c6669824798). If \n" 57 " \"groundtruth.txt\" is found in the sequence folder, they will be saved in the database.\n" 58 " --output Output directory. By default, results are saved in \"path\".\n" 59 " --output_name Output database name (default \"rtabmap\").\n" 60 " --skip # Skip X frames.\n" 61 " --quiet Don't show log messages and iteration updates.\n" 64 " $ rtabmap-rgbd_dataset \\\n" 65 " --Rtabmap/PublishRAMUsage true\\\n" 66 " --Rtabmap/DetectionRate 2\\\n" 67 " --RGBD/LinearUpdate 0\\\n" 68 " --Mem/STMSize 30\\\n" 77 printf(
"\nSignal %d caught...\n", sig);
93 std::string outputName =
"rtabmap";
102 for(
int i=1; i<argc; ++i)
104 if(std::strcmp(argv[i],
"--output") == 0)
108 else if(std::strcmp(argv[i],
"--output_name") == 0)
110 outputName = argv[++i];
112 else if(std::strcmp(argv[i],
"--skip") == 0)
114 skipFrames = atoi(argv[++i]);
117 else if(std::strcmp(argv[i],
"--quiet") == 0)
135 parameters.insert(
ParametersPair(Parameters::kRtabmapWorkingDirectory(), output));
136 parameters.insert(
ParametersPair(Parameters::kRtabmapPublishRAMUsage(),
"true"));
139 std::string seq =
uSplit(path,
'/').back();
140 std::string pathRgbImages = path+
"/rgb_sync";
141 std::string pathDepthImages = path+
"/depth_sync";
142 std::string pathGt = path+
"/groundtruth.txt";
145 UWARN(
"Ground truth file path doesn't exist: \"%s\", benchmark values won't be computed.", pathGt.c_str());
155 " Dataset name: %s\n" 156 " Dataset path: %s\n" 161 " Skip frames: %d\n",
164 pathRgbImages.c_str(),
165 pathDepthImages.c_str(),
171 printf(
" groundtruth.txt: %s\n", pathGt.c_str());
173 if(!parameters.empty())
175 printf(
"Parameters:\n");
176 for(ParametersMap::iterator iter=parameters.begin(); iter!=parameters.end(); ++iter)
178 printf(
" %s=%s\n", iter->first.c_str(), iter->second.c_str());
181 printf(
"RTAB-Map version: %s\n", RTABMAP_VERSION);
186 Transform opticalRotation(0,0,1,0, -1,0,0,0, 0,-1,0,0);
187 float depthFactor = 5.0f;
188 if(sequenceName.find(
"freiburg1") != std::string::npos)
190 model =
CameraModel(outputName+
"_calib", 517.3, 516.5, 318.6, 255.3, opticalRotation, 0, cv::Size(640,480));
192 else if(sequenceName.find(
"freiburg2") != std::string::npos)
194 model =
CameraModel(outputName+
"_calib", 520.9, 521.0, 325.1, 249.7, opticalRotation, 0, cv::Size(640,480));
198 model =
CameraModel(outputName+
"_calib", 535.4, 539.2, 320.1, 247.6, opticalRotation, 0, cv::Size(640,480));
215 bool intermediateNodes = Parameters::defaultRtabmapCreateIntermediateNodes();
216 float detectionRate = Parameters::defaultRtabmapDetectionRate();
217 int odomStrategy = Parameters::defaultOdomStrategy();
218 Parameters::parse(parameters, Parameters::kRtabmapCreateIntermediateNodes(), intermediateNodes);
220 Parameters::parse(parameters, Parameters::kRtabmapDetectionRate(), detectionRate);
221 std::string databasePath = output+
"/"+outputName+
".db";
223 if(cameraThread.
camera()->
init(path, outputName+
"_calib"))
229 totalImages /= skipFrames+1;
232 printf(
"Processing %d images...\n", totalImages);
235 odomParameters.erase(Parameters::kRtabmapPublishRAMUsage());
238 rtabmap.
init(parameters, databasePath);
250 int odomKeyFrames = 0;
251 double previousStamp = 0.0;
255 if(skipCount < skipFrames)
272 if(odomStrategy == 2)
286 bool processData =
true;
287 if(detectionRate>0.0
f &&
289 data.
stamp()>previousStamp && data.
stamp() - previousStamp < 1.0/detectionRate)
296 previousStamp = data.
stamp();
303 data.
setFeatures(std::vector<cv::KeyPoint>(), std::vector<cv::Point3f>(), cv::Mat());
304 processData = intermediateNodes;
306 if(covariance.empty() || odomInfo.
reg.
covariance.at<
double>(0,0) > covariance.at<
double>(0,0))
314 std::map<std::string, float> externalStats;
316 externalStats.insert(std::make_pair(
"Camera/BilateralFiltering/ms", cameraInfo.
timeBilateralFiltering*1000.0f));
317 externalStats.insert(std::make_pair(
"Camera/Capture/ms", cameraInfo.
timeCapture*1000.0f));
318 externalStats.insert(std::make_pair(
"Camera/Disparity/ms", cameraInfo.
timeDisparity*1000.0f));
319 externalStats.insert(std::make_pair(
"Camera/ImageDecimation/ms", cameraInfo.
timeImageDecimation*1000.0f));
320 externalStats.insert(std::make_pair(
"Camera/Mirroring/ms", cameraInfo.
timeMirroring*1000.0f));
322 externalStats.insert(std::make_pair(
"Camera/ScanFromDepth/ms", cameraInfo.
timeScanFromDepth*1000.0f));
323 externalStats.insert(std::make_pair(
"Camera/TotalTime/ms", cameraInfo.
timeTotal*1000.0f));
324 externalStats.insert(std::make_pair(
"Camera/UndistortDepth/ms", cameraInfo.
timeUndistortDepth*1000.0f));
326 externalStats.insert(std::make_pair(
"Odometry/LocalBundle/ms", odomInfo.
localBundleTime*1000.0f));
327 externalStats.insert(std::make_pair(
"Odometry/LocalBundleConstraints/", odomInfo.
localBundleConstraints));
328 externalStats.insert(std::make_pair(
"Odometry/LocalBundleOutliers/", odomInfo.
localBundleOutliers));
329 externalStats.insert(std::make_pair(
"Odometry/TotalTime/ms", odomInfo.
timeEstimation*1000.0f));
330 externalStats.insert(std::make_pair(
"Odometry/Registration/ms", odomInfo.
reg.
totalTime*1000.0f));
331 externalStats.insert(std::make_pair(
"Odometry/Inliers/", odomInfo.
reg.
inliers));
332 externalStats.insert(std::make_pair(
"Odometry/Features/", odomInfo.
features));
333 externalStats.insert(std::make_pair(
"Odometry/DistanceTravelled/m", odomInfo.
distanceTravelled));
334 externalStats.insert(std::make_pair(
"Odometry/KeyFrameAdded/", odomInfo.
keyFrameAdded));
335 externalStats.insert(std::make_pair(
"Odometry/LocalKeyFrames/", odomInfo.
localKeyFrames));
336 externalStats.insert(std::make_pair(
"Odometry/LocalMapSize/", odomInfo.
localMapSize));
337 externalStats.insert(std::make_pair(
"Odometry/LocalScanMapSize/", odomInfo.
localScanMapSize));
341 covariance = cv::Mat();
345 if(!quiet || iteration == totalImages)
347 double slamTime = timer.
ticks();
359 printf(
"Iteration %d/%d: camera=%dms, odom(quality=%d/%d, kfs=%d)=%dms, slam=%dms, rmse=%fm",
364 printf(
"Iteration %d/%d: camera=%dms, odom(quality=%d/%d, kfs=%d)=%dms, slam=%dms",
373 else if(iteration % (totalImages/10) == 0)
384 printf(
"Total time=%fs\n", totalTime.
ticks());
390 printf(
"Saving trajectory...\n");
391 std::map<int, Transform> poses;
392 std::multimap<int, Link> links;
393 std::map<int, Signature> signatures;
394 std::map<int, double> stamps;
395 rtabmap.
getGraph(poses, links,
true,
true, &signatures);
396 for(std::map<int, Signature>::iterator iter=signatures.begin(); iter!=signatures.end(); ++iter)
398 stamps.insert(std::make_pair(iter->first, iter->second.getStamp()));
400 std::string pathTrajectory = output+
"/"+outputName+
"_poses.txt";
403 printf(
"Saving %s... done!\n", pathTrajectory.c_str());
407 printf(
"Saving %s... failed!\n", pathTrajectory.c_str());
413 std::map<int, Transform> groundTruth;
415 for(std::map<int, Transform>::const_iterator iter=poses.begin(); iter!=poses.end(); ++iter)
421 std::vector<float> v;
424 rtabmap.
getMemory()->
getNodeInfo(iter->first, o, m, w, l, s, gtPose, v, gps, sensors,
true);
427 groundTruth.insert(std::make_pair(iter->first, gtPose));
433 float translational_rmse = 0.0f;
434 float translational_mean = 0.0f;
435 float translational_median = 0.0f;
436 float translational_std = 0.0f;
437 float translational_min = 0.0f;
438 float translational_max = 0.0f;
439 float rotational_rmse = 0.0f;
440 float rotational_mean = 0.0f;
441 float rotational_median = 0.0f;
442 float rotational_std = 0.0f;
443 float rotational_min = 0.0f;
444 float rotational_max = 0.0f;
450 translational_median,
461 printf(
" translational_rmse= %f m\n", translational_rmse);
462 printf(
" rotational_rmse= %f deg\n", rotational_rmse);
465 std::string pathErrors = output+
"/"+outputName+
"_rmse.txt";
466 pFile = fopen(pathErrors.c_str(),
"w");
469 UERROR(
"could not save RMSE results to \"%s\"", pathErrors.c_str());
471 fprintf(pFile,
"Ground truth comparison:\n");
472 fprintf(pFile,
" translational_rmse= %f\n", translational_rmse);
473 fprintf(pFile,
" translational_mean= %f\n", translational_mean);
474 fprintf(pFile,
" translational_median= %f\n", translational_median);
475 fprintf(pFile,
" translational_std= %f\n", translational_std);
476 fprintf(pFile,
" translational_min= %f\n", translational_min);
477 fprintf(pFile,
" translational_max= %f\n", translational_max);
478 fprintf(pFile,
" rotational_rmse= %f\n", rotational_rmse);
479 fprintf(pFile,
" rotational_mean= %f\n", rotational_mean);
480 fprintf(pFile,
" rotational_median= %f\n", rotational_median);
481 fprintf(pFile,
" rotational_std= %f\n", rotational_std);
482 fprintf(pFile,
" rotational_min= %f\n", rotational_min);
483 fprintf(pFile,
" rotational_max= %f\n", rotational_max);
489 UERROR(
"Camera init failed!");
492 printf(
"Saving rtabmap database (with all statistics) to \"%s\"\n", (output+
"/"+outputName+
".db").c_str());
494 " $ rtabmap-databaseViewer %s\n\n", (output+
"/"+outputName+
".db").c_str());
bool getNodeInfo(int signatureId, Transform &odomPose, int &mapId, int &weight, std::string &label, double &stamp, Transform &groundTruth, std::vector< float > &velocity, GPS &gps, EnvSensors &sensors, bool lookInDatabase=false) const
static std::string homeDir()
static bool parse(const ParametersMap ¶meters, const std::string &key, bool &value)
static bool makeDir(const std::string &dirPath)
bool save(const std::string &directory) const
static const char * showUsage()
const Statistics & getStatistics() const
std::pair< std::string, std::string > ParametersPair
static std::string getName(const std::string &filePath)
static ParametersMap parseArguments(int argc, char *argv[], bool onlyParameters=false)
static int erase(const std::string &filePath)
GLM_FUNC_DECL genType e()
std::map< std::string, std::string > ParametersMap
void init(const ParametersMap ¶meters, const std::string &databasePath="", bool loadDatabaseParameters=false)
Basic mathematics functions.
Some conversion functions.
int localBundleConstraints
static void setLevel(ULogger::Level level)
Transform process(SensorData &data, OdometryInfo *info=0)
const std::map< std::string, float > & data() const
virtual bool init(const std::string &calibrationFolder=".", const std::string &cameraName="")=0
#define UASSERT(condition)
SensorData takeImage(CameraInfo *info=0)
Wrappers of STL for convenient functions.
std::list< std::string > uSplit(const std::string &str, char separator=' ')
float timeStereoExposureCompensation
static Odometry * create(const ParametersMap ¶meters=ParametersMap())
const Memory * getMemory() const
Transform RTABMAP_EXP calcRMSE(const std::map< int, Transform > &groundTruth, const std::map< int, Transform > &poses, float &translational_rmse, float &translational_mean, float &translational_median, float &translational_std, float &translational_min, float &translational_max, float &rotational_rmse, float &rotational_mean, float &rotational_median, float &rotational_std, float &rotational_min, float &rotational_max)
static void setType(Type type, const std::string &fileName=kDefaultLogFileName, bool append=true)
bool process(const SensorData &data, Transform odomPose, const cv::Mat &odomCovariance=cv::Mat::eye(6, 6, CV_64FC1), const std::vector< float > &odomVelocity=std::vector< float >(), const std::map< std::string, float > &externalStats=std::map< std::string, float >())
Main loop of rtabmap.
std::string UTILITE_EXP uReplaceChar(const std::string &str, char before, char after)
bool RTABMAP_EXP exportPoses(const std::string &filePath, int format, const std::map< int, Transform > &poses, const std::multimap< int, Link > &constraints=std::multimap< int, Link >(), const std::map< int, double > &stamps=std::map< int, double >(), const ParametersMap ¶meters=ParametersMap())
std::vector< float > velocity() const
void postUpdate(SensorData *data, CameraInfo *info=0) const
int main(int argc, char *argv[])
void getGraph(std::map< int, Transform > &poses, std::multimap< int, Link > &constraints, bool optimized, bool global, std::map< int, Signature > *signatures=0, bool withImages=false, bool withScan=false, bool withUserData=false, bool withGrid=false, bool withWords=true, bool withGlobalDescriptors=true) const
float timeImageDecimation
std::map< EnvSensor::Type, EnvSensor > EnvSensors
float timeBilateralFiltering
void setFeatures(const std::vector< cv::KeyPoint > &keypoints, const std::vector< cv::Point3f > &keypoints3D, const cv::Mat &descriptors)
int getLoopClosureId() const