38 #include <opencv2/core/core.hpp> 43 #define GENERATED_GT_NAME "GroundTruth_generated.bmp" 48 "rtabmap-console [options] \"path\"\n" 49 " path For images, use the directory path. For videos or databases, use full\n " 52 " -rate #.## Acquisition time (seconds)\n" 53 " -rateHz #.## Acquisition rate (Hz), for convenience\n" 54 " -repeat # Repeat the process on the data set # times (minimum of 1)\n" 55 " -createGT Generate a ground truth file\n" 56 " -start_at # When \"path\" is a directory of images, set this parameter\n" 57 " to start processing at image # (default 0).\n" 58 " -skip # Skip X images while reading directory (default 0).\n" 59 " -v Get version of RTAB-Map\n" 60 " -input \"path\" Load previous database if it exists.\n" 70 printf(
"\nSignal %d caught...\n", sig);
84 pm.insert(
ParametersPair(Parameters::kRtabmapWorkingDirectory(),
"."));
90 else if(argc == 2 && strcmp(argv[1],
"-v") == 0)
101 bool createGT =
false;
102 std::string inputDbPath;
106 for(
int i=1; i<argc; ++i)
114 printf(
"Path not valid : %s\n", path.c_str());
120 if(strcmp(argv[i],
"-rate") == 0)
137 if(strcmp(argv[i],
"-rateHz") == 0)
158 if(strcmp(argv[i],
"-repeat") == 0)
163 repeat = std::atoi(argv[i]);
175 if(strcmp(argv[i],
"-start_at") == 0)
180 startAt = std::atoi(argv[i]);
192 if (strcmp(argv[i],
"-skip") == 0)
197 skip = std::atoi(argv[i]);
209 if(strcmp(argv[i],
"-createGT") == 0)
214 if(strcmp(argv[i],
"-input") == 0)
219 inputDbPath = argv[i];
227 if(strcmp(argv[i],
"-help") == 0 || strcmp(argv[i],
"--help") == 0)
233 if(repeat && createGT)
235 printf(
"Cannot create a Ground truth if repeat is on.\n");
241 std::queue<double> iterationMeanTime;
254 if(!camera || !camera->
init())
256 printf(
"Camera init failed, using path \"%s\"\n", path.c_str());
260 std::map<int, int> groundTruth;
264 if(inputDbPath.empty())
266 inputDbPath =
"rtabmapconsole.db";
269 printf(
"Deleted database \"%s\".\n", inputDbPath.c_str());
274 printf(
"Loading database \"%s\".\n", inputDbPath.c_str());
284 cv::Mat tmp = cv::Mat::zeros(640,480,CV_8UC1);
287 rtabmap.
close(
false);
290 rtabmap.
init(pm, inputDbPath);
292 printf(
"rtabmap init time = %fs\n", timer.
ticks());
297 int countLoopDetected=0;
299 printf(
"\nParameters : \n");
300 printf(
" Data set : %s\n", path.c_str());
302 printf(
" Image rate = %1.2f s (%1.2f Hz)\n", rate, 1/rate);
303 printf(
" Repeating data set = %s\n", repeat?
"true":
"false");
304 printf(
" Camera starts at image %d (default 0)\n", startAt);
305 printf(
" Skip image = %d\n", skip);
308 printf(
" Creating the ground truth matrix.\n");
310 printf(
" INFO: All other parameters are set to defaults\n");
313 printf(
" Overwritten parameters :\n");
314 for(ParametersMap::iterator iter = pm.begin(); iter!=pm.end(); ++iter)
316 printf(
" %s=%s\n",iter->first.c_str(), iter->second.c_str());
319 if(rtabmap.
getWM().size() || rtabmap.
getSTM().size())
321 printf(
"[Warning] RTAB-Map database is not empty (%s)\n", inputDbPath.c_str());
323 printf(
"\nProcessing images...\n");
327 int imagesProcessed = 0;
328 std::list<std::vector<float> > teleopActions;
329 while(loopDataset <= repeat &&
g_forever)
333 double maxIterationTime = 0.0;
334 int maxIterationTimeId = 0;
338 iterationTimer.
start();
339 rtabmapTimer.
start();
341 double rtabmapTime = rtabmapTimer.
elapsed();
347 for(
int j=0; j<=skip; ++j)
351 if(++count % 100 == 0)
353 printf(
" count = %d, loop closures = %d, max time (at %d) = %fs\n",
354 count, countLoopDetected, maxIterationTimeId, maxIterationTime);
355 maxIterationTime = 0.0;
356 maxIterationTimeId = 0;
358 printf(
" WM(%d)=[", (
int)wm.size());
359 for(std::map<int, int>::iterator iter=wm.begin(); iter!=wm.end();++iter)
361 if(iter != wm.begin())
365 printf(
"%d,%d", iter->first, iter->second);
373 if(loopClosureId > 0)
375 groundTruth.insert(std::make_pair(i, loopClosureId-1));
381 double iterationTime = iterationTimer.
ticks();
383 if(rtabmapTime > maxIterationTime)
385 maxIterationTime = rtabmapTime;
386 maxIterationTimeId = count;
393 printf(
" iteration(%d) loop(%d) hyp(%.2f) time=%fs/%fs *\n",
398 printf(
" iteration(%d) high(%d) hyp(%.2f) time=%fs/%fs\n",
403 printf(
" iteration(%d) time=%fs/%fs\n", count, rtabmapTime, iterationTime);
408 printf(
" ERROR, there is problem, too much time taken... %fs", rtabmapTime);
413 if(loopDataset <= repeat)
416 printf(
" Beginning loop %d...\n", loopDataset);
419 printf(
"Processing images completed. Loop closures found = %d\n", countLoopDetected);
420 printf(
" Total time = %fs\n", timer.
ticks());
422 if(imagesProcessed && createGT)
424 cv::Mat groundTruthMat = cv::Mat::zeros(imagesProcessed, imagesProcessed, CV_8U);
426 for(std::map<int, int>::iterator iter = groundTruth.begin(); iter!=groundTruth.end(); ++iter)
428 groundTruthMat.at<
unsigned char>(iter->first, iter->second) = 255;
432 printf(
"Generate ground truth to file %s, size of %d\n",
GENERATED_GT_NAME, groundTruthMat.rows);
434 printf(
" Creating ground truth file = %fs\n", timer.
ticks());
445 printf(
" Cleanup time = %fs\n", timer.
ticks());
447 printf(
"Database (\"%s\") and log files saved to current directory.\n", inputDbPath.c_str());
#define GENERATED_GT_NAME
float getTimeThreshold() const
static const char * showUsage()
std::pair< std::string, std::string > ParametersPair
static std::string getVersion()
static ParametersMap parseArguments(int argc, char *argv[], bool onlyParameters=false)
static int erase(const std::string &filePath)
float UTILITE_EXP uStr2Float(const std::string &str)
std::map< std::string, std::string > ParametersMap
void init(const ParametersMap ¶meters, const std::string &databasePath="", bool loadDatabaseParameters=false)
Some conversion functions.
static void setLevel(ULogger::Level level)
std::set< int > getSTM() const
virtual bool init(const std::string &calibrationFolder=".", const std::string &cameraName="")=0
SensorData takeImage(CameraInfo *info=0)
Wrappers of STL for convenient functions.
void close(bool databaseSaved=true, const std::string &ouputDatabasePath="")
std::list< int > getWM() const
float getHighestHypothesisValue() const
const cv::Mat & imageRaw() 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.
GLM_FUNC_DECL genType repeat(genType const &Texcoord)
static ULogger::Level level()
std::map< int, int > getWeights() const
float getLoopClosureValue() const
ULogger class and convenient macros.
int main(int argc, char *argv[])
static bool exists(const std::string &dirPath)
int getHighestHypothesisId() const
int getLoopClosureId() const
void uInsert(std::map< K, V > &map, const std::pair< K, V > &pair)