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 " --quiet Don't show log messages and iteration updates.\n" 63 " $ rtabmap-rgbd_dataset \\\n" 64 " --Rtabmap/PublishRAMUsage true\\\n" 65 " --Rtabmap/DetectionRate 2\\\n" 66 " --RGBD/LinearUpdate 0\\\n" 67 " --Mem/STMSize 30\\\n" 76 printf(
"\nSignal %d caught...\n", sig);
80 int main(
int argc,
char * argv[])
92 std::string outputName =
"rtabmap";
100 for(
int i=1; i<argc; ++i)
102 if(std::strcmp(argv[i],
"--output") == 0)
106 else if(std::strcmp(argv[i],
"--output_name") == 0)
108 outputName = argv[++i];
110 else if(std::strcmp(argv[i],
"--quiet") == 0)
128 parameters.insert(
ParametersPair(Parameters::kRtabmapWorkingDirectory(), output));
129 parameters.insert(
ParametersPair(Parameters::kRtabmapPublishRAMUsage(),
"true"));
132 std::string seq =
uSplit(path,
'/').back();
133 std::string pathRgbImages = path+
"/rgb_sync";
134 std::string pathDepthImages = path+
"/depth_sync";
135 std::string pathGt = path+
"/groundtruth.txt";
138 UWARN(
"Ground truth file path doesn't exist: \"%s\", benchmark values won't be computed.", pathGt.c_str());
148 " Dataset name: %s\n" 149 " Dataset path: %s\n" 153 " Output name: %s\n",
156 pathRgbImages.c_str(),
157 pathDepthImages.c_str(),
162 printf(
" groundtruth.txt: %s\n", pathGt.c_str());
164 if(!parameters.empty())
166 printf(
"Parameters:\n");
167 for(ParametersMap::iterator iter=parameters.begin(); iter!=parameters.end(); ++iter)
169 printf(
" %s=%s\n", iter->first.c_str(), iter->second.c_str());
172 printf(
"RTAB-Map version: %s\n", RTABMAP_VERSION);
177 Transform opticalRotation(0,0,1,0, -1,0,0,0, 0,-1,0,0);
178 float depthFactor = 5.0f;
179 if(sequenceName.find(
"freiburg1") != std::string::npos)
181 model =
CameraModel(outputName+
"_calib", 517.3, 516.5, 318.6, 255.3, opticalRotation, 0, cv::Size(640,480));
183 else if(sequenceName.find(
"freiburg2") != std::string::npos)
185 model =
CameraModel(outputName+
"_calib", 520.9, 521.0, 325.1, 249.7, opticalRotation, 0, cv::Size(640,480));
189 model =
CameraModel(outputName+
"_calib", 535.4, 539.2, 320.1, 247.6, opticalRotation, 0, cv::Size(640,480));
200 opticalRotation), parameters);
207 bool intermediateNodes = Parameters::defaultRtabmapCreateIntermediateNodes();
208 float detectionRate = Parameters::defaultRtabmapDetectionRate();
209 int odomStrategy = Parameters::defaultOdomStrategy();
210 Parameters::parse(parameters, Parameters::kRtabmapCreateIntermediateNodes(), intermediateNodes);
212 Parameters::parse(parameters, Parameters::kRtabmapDetectionRate(), detectionRate);
213 std::string databasePath = output+
"/"+outputName+
".db";
215 if(cameraThread.
camera()->
init(path, outputName+
"_calib"))
219 printf(
"Processing %d images...\n", totalImages);
222 odomParameters.erase(Parameters::kRtabmapPublishRAMUsage());
225 rtabmap.
init(parameters, databasePath);
237 int odomKeyFrames = 0;
238 double previousStamp = 0.0;
247 if(odomStrategy == 2)
261 bool processData =
true;
262 if(detectionRate>0.0
f &&
264 data.
stamp()>previousStamp && data.
stamp() - previousStamp < 1.0/detectionRate)
271 previousStamp = data.
stamp();
278 data.
setFeatures(std::vector<cv::KeyPoint>(), std::vector<cv::Point3f>(), cv::Mat());
279 processData = intermediateNodes;
281 if(covariance.empty() || odomInfo.
reg.
covariance.at<
double>(0,0) > covariance.at<
double>(0,0))
289 std::map<std::string, float> externalStats;
291 externalStats.insert(std::make_pair(
"Camera/BilateralFiltering/ms", cameraInfo.
timeBilateralFiltering*1000.0f));
292 externalStats.insert(std::make_pair(
"Camera/Capture/ms", cameraInfo.
timeCapture*1000.0f));
293 externalStats.insert(std::make_pair(
"Camera/Disparity/ms", cameraInfo.
timeDisparity*1000.0f));
294 externalStats.insert(std::make_pair(
"Camera/ImageDecimation/ms", cameraInfo.
timeImageDecimation*1000.0f));
295 externalStats.insert(std::make_pair(
"Camera/Mirroring/ms", cameraInfo.
timeMirroring*1000.0f));
297 externalStats.insert(std::make_pair(
"Camera/ScanFromDepth/ms", cameraInfo.
timeScanFromDepth*1000.0f));
298 externalStats.insert(std::make_pair(
"Camera/TotalTime/ms", cameraInfo.
timeTotal*1000.0f));
299 externalStats.insert(std::make_pair(
"Camera/UndistortDepth/ms", cameraInfo.
timeUndistortDepth*1000.0f));
301 externalStats.insert(std::make_pair(
"Odometry/LocalBundle/ms", odomInfo.
localBundleTime*1000.0f));
302 externalStats.insert(std::make_pair(
"Odometry/LocalBundleConstraints/", odomInfo.
localBundleConstraints));
303 externalStats.insert(std::make_pair(
"Odometry/LocalBundleOutliers/", odomInfo.
localBundleOutliers));
304 externalStats.insert(std::make_pair(
"Odometry/TotalTime/ms", odomInfo.
timeEstimation*1000.0f));
305 externalStats.insert(std::make_pair(
"Odometry/Registration/ms", odomInfo.
reg.
totalTime*1000.0f));
306 externalStats.insert(std::make_pair(
"Odometry/Inliers/", odomInfo.
reg.
inliers));
307 externalStats.insert(std::make_pair(
"Odometry/Features/", odomInfo.
features));
308 externalStats.insert(std::make_pair(
"Odometry/DistanceTravelled/m", odomInfo.
distanceTravelled));
309 externalStats.insert(std::make_pair(
"Odometry/KeyFrameAdded/", odomInfo.
keyFrameAdded));
310 externalStats.insert(std::make_pair(
"Odometry/LocalKeyFrames/", odomInfo.
localKeyFrames));
311 externalStats.insert(std::make_pair(
"Odometry/LocalMapSize/", odomInfo.
localMapSize));
312 externalStats.insert(std::make_pair(
"Odometry/LocalScanMapSize/", odomInfo.
localScanMapSize));
316 covariance = cv::Mat();
320 if(!quiet || iteration == totalImages)
322 double slamTime = timer.
ticks();
334 printf(
"Iteration %d/%d: camera=%dms, odom(quality=%d/%d, kfs=%d)=%dms, slam=%dms, rmse=%fm",
339 printf(
"Iteration %d/%d: camera=%dms, odom(quality=%d/%d, kfs=%d)=%dms, slam=%dms",
348 else if(iteration % (totalImages/10) == 0)
359 printf(
"Total time=%fs\n", totalTime.
ticks());
365 printf(
"Saving trajectory...\n");
366 std::map<int, Transform> poses;
367 std::multimap<int, Link> links;
368 std::map<int, Signature> signatures;
369 std::map<int, double> stamps;
370 rtabmap.
getGraph(poses, links,
true,
true, &signatures);
371 for(std::map<int, Signature>::iterator iter=signatures.begin(); iter!=signatures.end(); ++iter)
373 stamps.insert(std::make_pair(iter->first, iter->second.getStamp()));
375 std::string pathTrajectory = output+
"/"+outputName+
"_poses.txt";
378 printf(
"Saving %s... done!\n", pathTrajectory.c_str());
382 printf(
"Saving %s... failed!\n", pathTrajectory.c_str());
388 std::map<int, Transform> groundTruth;
390 for(std::map<int, Transform>::const_iterator iter=poses.begin(); iter!=poses.end(); ++iter)
396 std::vector<float> v;
401 groundTruth.insert(std::make_pair(iter->first, gtPose));
407 float translational_rmse = 0.0f;
408 float translational_mean = 0.0f;
409 float translational_median = 0.0f;
410 float translational_std = 0.0f;
411 float translational_min = 0.0f;
412 float translational_max = 0.0f;
413 float rotational_rmse = 0.0f;
414 float rotational_mean = 0.0f;
415 float rotational_median = 0.0f;
416 float rotational_std = 0.0f;
417 float rotational_min = 0.0f;
418 float rotational_max = 0.0f;
424 translational_median,
435 printf(
" translational_rmse= %f m\n", translational_rmse);
436 printf(
" rotational_rmse= %f deg\n", rotational_rmse);
439 std::string pathErrors = output+
"/"+outputName+
"_rmse.txt";
440 pFile = fopen(pathErrors.c_str(),
"w");
443 UERROR(
"could not save RMSE results to \"%s\"", pathErrors.c_str());
445 fprintf(pFile,
"Ground truth comparison:\n");
446 fprintf(pFile,
" translational_rmse= %f\n", translational_rmse);
447 fprintf(pFile,
" translational_mean= %f\n", translational_mean);
448 fprintf(pFile,
" translational_median= %f\n", translational_median);
449 fprintf(pFile,
" translational_std= %f\n", translational_std);
450 fprintf(pFile,
" translational_min= %f\n", translational_min);
451 fprintf(pFile,
" translational_max= %f\n", translational_max);
452 fprintf(pFile,
" rotational_rmse= %f\n", rotational_rmse);
453 fprintf(pFile,
" rotational_mean= %f\n", rotational_mean);
454 fprintf(pFile,
" rotational_median= %f\n", rotational_median);
455 fprintf(pFile,
" rotational_std= %f\n", rotational_std);
456 fprintf(pFile,
" rotational_min= %f\n", rotational_min);
457 fprintf(pFile,
" rotational_max= %f\n", rotational_max);
463 UERROR(
"Camera init failed!");
466 printf(
"Saving rtabmap database (with all statistics) to \"%s\"\n", (output+
"/"+outputName+
".db").c_str());
468 " $ rtabmap-databaseViewer %s\n\n", (output+
"/"+outputName+
".db").c_str());
static std::string homeDir()
static bool parse(const ParametersMap ¶meters, const std::string &key, bool &value)
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 >(), bool g2oRobust=false)
static bool makeDir(const std::string &dirPath)
static const char * showUsage()
std::pair< std::string, std::string > ParametersPair
static std::string getName(const std::string &filePath)
bool save(const std::string &directory) const
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
Basic mathematics functions.
Some conversion functions.
int localBundleConstraints
static void setLevel(ULogger::Level level)
void getGraph(std::map< int, Transform > &poses, std::multimap< int, Link > &constraints, bool optimized, bool global, std::map< int, Signature > *signatures=0)
static rtabmap::Transform opticalRotation(1.0f, 0.0f, 0.0f, 0.0f, 0.0f,-1.0f, 0.0f, 0.0f, 0.0f, 0.0f,-1.0f, 0.0f)
Transform process(SensorData &data, OdometryInfo *info=0)
std::list< std::string > uSplit(const std::string &str, char separator= ' ')
virtual bool init(const std::string &calibrationFolder=".", const std::string &cameraName="")=0
SensorData takeImage(CameraInfo *info=0)
Wrappers of STL for convenient functions.
const std::map< std::string, float > & data() const
float timeStereoExposureCompensation
int getLoopClosureId() 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)
const Statistics & getStatistics() const
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.
static Odometry * create(const ParametersMap ¶meters)
std::string UTILITE_EXP uReplaceChar(const std::string &str, char before, char after)
void init(const ParametersMap ¶meters, const std::string &databasePath="")
void postUpdate(SensorData *data, CameraInfo *info=0) const
bool getNodeInfo(int signatureId, Transform &odomPose, int &mapId, int &weight, std::string &label, double &stamp, Transform &groundTruth, std::vector< float > &velocity, GPS &gps, bool lookInDatabase=false) const
int main(int argc, char *argv[])
const Memory * getMemory() const
float timeImageDecimation
std::vector< float > velocity() const
float timeBilateralFiltering
void setFeatures(const std::vector< cv::KeyPoint > &keypoints, const std::vector< cv::Point3f > &keypoints3D, const cv::Mat &descriptors)