40 #include <pcl/filters/filter.h> 41 #include <pcl/io/ply_io.h> 42 #include <pcl/io/obj_io.h> 43 #include <pcl/common/common.h> 44 #include <pcl/surface/poisson.h> 53 "rtabmap-detectMoreLoopClosures [options] database.db\n" 55 " -r # Cluster radius (default 1 m).\n" 56 " -rx # Cluster radius min (default 0 m).\n" 57 " -a # Cluster angle (default 30 deg).\n" 58 " -i # Iterations (default 1).\n" 59 " --intra Add only intra-session loop closures.\n" 60 " --inter Add only inter-session loop closures.\n" 69 printf(
"\nSignal %d caught...\n", sig);
76 virtual bool callback(
const std::string & msg)
const 79 printf(
"%s \n", msg.c_str());
98 float clusterRadiusMin = 0.0f;
99 float clusterRadiusMax = 1.0f;
100 float clusterAngle = CV_PI/6.0f;
102 bool intraSession =
false;
103 bool interSession =
false;
104 for(
int i=1; i<argc-1; ++i)
106 if(std::strcmp(argv[i],
"--help") == 0)
110 else if(std::strcmp(argv[i],
"--intra") == 0)
118 else if(std::strcmp(argv[i],
"--inter") == 0)
126 else if(std::strcmp(argv[i],
"-r") == 0)
138 else if(std::strcmp(argv[i],
"-rx") == 0)
150 else if(std::strcmp(argv[i],
"-a") == 0)
155 clusterAngle =
uStr2Float(argv[i])*CV_PI/180.0f;
162 else if(std::strcmp(argv[i],
"-i") == 0)
177 std::string dbPath = argv[argc-1];
180 printf(
"Database %s doesn't exist!\n", dbPath.c_str());
183 printf(
"\nDatabase: %s\n", dbPath.c_str());
184 printf(
"Cluster radius min = %f m\n", clusterRadiusMin);
185 printf(
"Cluster radius max = %f m\n", clusterRadiusMax);
186 printf(
"Cluster angle = %f deg\n", clusterAngle*180.0
f/CV_PI);
189 printf(
"Intra-session only\n");
191 else if(interSession)
193 printf(
"Inter-session only\n");
196 if(!intraSession && !interSession)
212 UERROR(
"Cannot open database %s!", dbPath.c_str());
216 for(ParametersMap::iterator iter=inputParams.begin(); iter!=inputParams.end(); ++iter)
218 printf(
" Using parameter \"%s=%s\" from arguments\n", iter->first.c_str(), iter->second.c_str());
223 printf(
"Initialization...\n");
224 uInsert(parameters, inputParams);
225 rtabmap.init(parameters, dbPath);
227 float xMin, yMin, cellSize;
228 bool haveOptimizedMap = !rtabmap.getMemory()->load2DMap(xMin, yMin, cellSize).empty();
231 printf(
"Detecting...\n");
232 int detected = rtabmap.detectMoreLoopClosures(clusterRadiusMax, clusterAngle, iterations, intraSession, interSession, &progress, clusterRadiusMin);
237 printf(
"Detection interrupted. Loop closures found so far (if any) are not saved.\n");
241 printf(
"Loop closure detection failed!\n");
244 else if(detected > 0 && haveOptimizedMap)
246 printf(
"The database has a global occupancy grid, regenerating one with new optimized graph!\n");
248 std::map<int, Transform> optimizedPoses = rtabmap.getLocalOptimizedPoses();
249 for(std::map<int, Transform>::iterator iter=optimizedPoses.lower_bound(0); iter!=optimizedPoses.end(); ++iter)
251 cv::Mat occupancyGrid;
252 SensorData data = rtabmap.getMemory()->getNodeData(iter->first,
false,
false,
false,
true);
256 grid.
update(optimizedPoses);
257 cv::Mat map = grid.
getMap(xMin, yMin);
260 printf(
"Could not generate the global occupancy grid!\n");
264 rtabmap.getMemory()->save2DMap(map, xMin, yMin, cellSize);
265 printf(
"Save new global occupancy grid!\n");
int UTILITE_EXP uStr2Int(const std::string &str)
bool update(const std::map< int, Transform > &poses)
virtual bool callback(const std::string &msg) const
static const char * showUsage()
static ParametersMap parseArguments(int argc, char *argv[], bool onlyParameters=false)
float UTILITE_EXP uStr2Float(const std::string &str)
std::map< std::string, std::string > ParametersMap
Basic mathematics functions.
static void setLevel(ULogger::Level level)
bool openConnection(const std::string &url, bool overwritten=false)
Wrappers of STL for convenient functions.
void closeConnection(bool save=true, const std::string &outputUrl="")
void addToCache(int nodeId, const cv::Mat &ground, const cv::Mat &obstacles, const cv::Mat &empty)
static void setType(Type type, const std::string &fileName=kDefaultLogFileName, bool append=true)
int main(int argc, char *argv[])
cv::Mat getMap(float &xMin, float &yMin) const
static DBDriver * create(const ParametersMap ¶meters=ParametersMap())
const cv::Mat & gridEmptyCellsRaw() const
const cv::Mat & gridGroundCellsRaw() const
ParametersMap getLastParameters() const
const cv::Mat & gridObstacleCellsRaw() const
void uInsert(std::map< K, V > &map, const std::pair< K, V > &pair)