mirror of
https://github.com/introlab/rtabmap.git
synced 2026-09-11 14:00:20 +08:00
Added c++ example usage
git-svn-id: http://rtabmap.googlecode.com/svn/trunk/rtabmap@694 f169173b-cf89-36c8-b27e-44dbe73f0c83
This commit is contained in:
@@ -179,6 +179,7 @@ ENDIF()
|
||||
|
||||
IF(NOT BUILD_LIBS_ONLY AND NOT BUILD_AS_BUNDLE)
|
||||
ADD_SUBDIRECTORY( tools )
|
||||
ADD_SUBDIRECTORY( examples )
|
||||
ENDIF(NOT BUILD_LIBS_ONLY AND NOT BUILD_AS_BUNDLE)
|
||||
|
||||
#######################
|
||||
|
||||
@@ -94,11 +94,14 @@ public:
|
||||
std::set<int> getStMem() const;
|
||||
std::map<int, int> getWeights() const;
|
||||
int getTotalMemSize() const;
|
||||
double getLastProcessTime() const {return _lastProcessTime;};
|
||||
|
||||
void setMaxTimeAllowed(float maxTimeAllowed); // in ms
|
||||
void setDataBufferSize(int size);
|
||||
void setWorkingDirectory(std::string path);
|
||||
|
||||
void deleteMemory();
|
||||
|
||||
void adjustLikelihood(std::map<int, float> & likelihood) const;
|
||||
std::pair<int, float> selectHypothesis(const std::map<int, float> & posterior,
|
||||
const std::map<int, float> & likelihood) const;
|
||||
@@ -141,6 +144,7 @@ private:
|
||||
int _retrievedId;
|
||||
float _lastLcHypothesisValue;
|
||||
int _lastLoopClosureId;
|
||||
double _lastProcessTime;
|
||||
|
||||
UMutex _stateMutex;
|
||||
std::stack<State> _state;
|
||||
|
||||
@@ -75,6 +75,7 @@ Rtabmap::Rtabmap() :
|
||||
_retrievedId(0),
|
||||
_lastLcHypothesisValue(0),
|
||||
_lastLoopClosureId(0),
|
||||
_lastProcessTime(0.0),
|
||||
_epipolarGeometry(0),
|
||||
_bayesFilter(0),
|
||||
_memory(0),
|
||||
@@ -517,6 +518,15 @@ void Rtabmap::mainLoop()
|
||||
}
|
||||
}
|
||||
|
||||
void Rtabmap::deleteMemory()
|
||||
{
|
||||
// Only if rtabmap's thread is not started...
|
||||
if(!this->isRunning())
|
||||
{
|
||||
this->resetMemory(true);
|
||||
}
|
||||
}
|
||||
|
||||
void Rtabmap::resetMemory(bool dbOverwritten)
|
||||
{
|
||||
if(_memory)
|
||||
@@ -1146,6 +1156,7 @@ void Rtabmap::process()
|
||||
ULOGGER_INFO("Removing old signatures because time limit is reached %f>%f or memory is reached %d>%d...", totalTime*1000, _maxTimeAllowed, _memory->getWorkingMemSize(), _maxMemoryAllowed);
|
||||
signaturesRemoved = _memory->forget(immunizedLocations);
|
||||
}
|
||||
_lastProcessTime = totalTime;
|
||||
|
||||
timeRealTimeLimitReachedProcess = timer.ticks();
|
||||
ULOGGER_INFO("Time limit reached processing = %f...", timeRealTimeLimitReachedProcess);
|
||||
|
||||
@@ -0,0 +1,24 @@
|
||||
|
||||
SET(SRC_FILES
|
||||
main.cpp
|
||||
)
|
||||
|
||||
SET(INCLUDE_DIRS
|
||||
${PROJECT_SOURCE_DIR}/corelib/include
|
||||
${UTILITE_INCLUDE_DIRS}
|
||||
${OpenCV_INCLUDE_DIRS}
|
||||
)
|
||||
|
||||
SET(LIBRARIES
|
||||
${UTILITE_LIBRARIES}
|
||||
${OpenCV_LIBRARIES}
|
||||
)
|
||||
|
||||
INCLUDE_DIRECTORIES(${INCLUDE_DIRS})
|
||||
|
||||
ADD_EXECUTABLE(example ${SRC_FILES})
|
||||
TARGET_LINK_LIBRARIES(example rtabmap_corelib ${LIBRARIES})
|
||||
|
||||
SET_TARGET_PROPERTIES( example
|
||||
PROPERTIES OUTPUT_NAME ${PROJECT_PREFIX}-example)
|
||||
|
||||
@@ -0,0 +1,101 @@
|
||||
/*
|
||||
* Copyright (C) 2010-2011, Mathieu Labbe and IntRoLab - Universite de Sherbrooke
|
||||
*
|
||||
* This file is part of RTAB-Map.
|
||||
*
|
||||
* RTAB-Map is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* RTAB-Map is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with RTAB-Map. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "rtabmap/core/Rtabmap.h"
|
||||
#include "rtabmap/core/Camera.h"
|
||||
#include <opencv2/core/core.hpp>
|
||||
|
||||
void showUsage()
|
||||
{
|
||||
printf("\nUsage:\n"
|
||||
"rtabmap-example \"path\"\n"
|
||||
" path Path to a directory of images\n ");
|
||||
exit(1);
|
||||
}
|
||||
|
||||
int main(int argc, char * argv[])
|
||||
{
|
||||
if(argc < 2)
|
||||
{
|
||||
showUsage();
|
||||
}
|
||||
std::string path = argv[1];
|
||||
|
||||
// rtabmap::Camera is simply a convenience wrapper of OpenCV cv::VideoCapture and cv::imread
|
||||
float imageRate = 1.0f; // 1 Hz
|
||||
rtabmap::CameraImages camera(path, 1, false, imageRate);
|
||||
|
||||
if(!camera.init())
|
||||
{
|
||||
printf("Camera init failed, using path \"%s\"\n", path.c_str());
|
||||
exit(1);
|
||||
}
|
||||
|
||||
// Create tasks
|
||||
rtabmap::Rtabmap rtabmap;
|
||||
|
||||
// Where database is saved
|
||||
rtabmap.setWorkingDirectory(".");
|
||||
|
||||
// Initialize rtabmap: load database...
|
||||
// It will automatically create config.ini
|
||||
// with default parameters if it not exists
|
||||
rtabmap.init("./config.ini");
|
||||
|
||||
// For this example, we want to delete the memory at each start.
|
||||
rtabmap.deleteMemory();
|
||||
|
||||
rtabmap.setMaxTimeAllowed(700); // Time threshold : 700 ms
|
||||
|
||||
// Start thread's task
|
||||
int countLoopDetected=0;
|
||||
|
||||
printf("\nProcessing images at %f Hz... from directory \"%s\"\n", imageRate, path.c_str());
|
||||
|
||||
int imagesProcessed = 0;
|
||||
|
||||
cv::Mat img = camera.takeImage();
|
||||
int i=0;
|
||||
while(!img.empty())
|
||||
{
|
||||
++imagesProcessed;
|
||||
rtabmap.process(rtabmap::Image(img));
|
||||
if(rtabmap.getLoopClosureId())
|
||||
{
|
||||
++countLoopDetected;
|
||||
}
|
||||
img = camera.takeImage();
|
||||
|
||||
++i;
|
||||
|
||||
if(rtabmap.getLoopClosureId())
|
||||
{
|
||||
printf(" iteration(%d) ptime(%fs) loop(%d) hyp(%.2f)\n",
|
||||
i, rtabmap.getLastProcessTime(), rtabmap.getLoopClosureId(), rtabmap.getLcHypValue());
|
||||
}
|
||||
else
|
||||
{
|
||||
printf(" iteration(%d) ptime(%fs)\n", i, rtabmap.getLastProcessTime());
|
||||
}
|
||||
}
|
||||
|
||||
printf("Processing images completed. Loop closures found = %d\n", countLoopDetected);
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -27,8 +27,3 @@ TARGET_LINK_LIBRARIES(consoleApp rtabmap_corelib ${LIBRARIES})
|
||||
SET_TARGET_PROPERTIES( consoleApp
|
||||
PROPERTIES OUTPUT_NAME ${PROJECT_PREFIX}-console)
|
||||
|
||||
INSTALL(TARGETS consoleApp
|
||||
RUNTIME DESTINATION bin COMPONENT runtime
|
||||
LIBRARY DESTINATION lib COMPONENT devel
|
||||
ARCHIVE DESTINATION lib COMPONENT devel)
|
||||
|
||||
|
||||
@@ -26,8 +26,4 @@ TARGET_LINK_LIBRARIES(epipolar_geometry rtabmap_corelib rtabmap_guilib ${LIBRARI
|
||||
SET_TARGET_PROPERTIES( epipolar_geometry
|
||||
PROPERTIES OUTPUT_NAME ${PROJECT_PREFIX}-epipolar_geometry)
|
||||
|
||||
INSTALL(TARGETS epipolar_geometry
|
||||
RUNTIME DESTINATION bin COMPONENT runtime
|
||||
LIBRARY DESTINATION lib COMPONENT devel
|
||||
ARCHIVE DESTINATION lib COMPONENT devel)
|
||||
|
||||
|
||||
@@ -23,8 +23,3 @@ TARGET_LINK_LIBRARIES(imagesDbExtractor rtabmap_corelib ${LIBRARIES})
|
||||
SET_TARGET_PROPERTIES( imagesDbExtractor
|
||||
PROPERTIES OUTPUT_NAME ${PROJECT_PREFIX}-imagesDbExtractor)
|
||||
|
||||
INSTALL(TARGETS imagesDbExtractor
|
||||
RUNTIME DESTINATION bin COMPONENT runtime
|
||||
LIBRARY DESTINATION lib COMPONENT devel
|
||||
ARCHIVE DESTINATION lib COMPONENT devel)
|
||||
|
||||
|
||||
@@ -25,8 +25,3 @@ TARGET_LINK_LIBRARIES(imagesJoiner ${LIBRARIES})
|
||||
SET_TARGET_PROPERTIES( imagesJoiner
|
||||
PROPERTIES OUTPUT_NAME ${PROJECT_PREFIX}-imagesJoiner)
|
||||
|
||||
INSTALL(TARGETS imagesJoiner
|
||||
RUNTIME DESTINATION bin COMPONENT runtime
|
||||
LIBRARY DESTINATION lib COMPONENT devel
|
||||
ARCHIVE DESTINATION lib COMPONENT devel)
|
||||
|
||||
|
||||
@@ -18,8 +18,3 @@ TARGET_LINK_LIBRARIES(vocabularyComparison rtabmap_corelib ${LIBRARIES})
|
||||
SET_TARGET_PROPERTIES( vocabularyComparison
|
||||
PROPERTIES OUTPUT_NAME ${PROJECT_PREFIX}-vocabularyComparison)
|
||||
|
||||
INSTALL(TARGETS vocabularyComparison
|
||||
RUNTIME DESTINATION bin COMPONENT runtime
|
||||
LIBRARY DESTINATION lib COMPONENT devel
|
||||
ARCHIVE DESTINATION lib COMPONENT devel)
|
||||
|
||||
|
||||
@@ -26,8 +26,3 @@ TARGET_LINK_LIBRARIES(databaseViewer rtabmap_corelib rtabmap_guilib ${LIBRARIES}
|
||||
SET_TARGET_PROPERTIES( databaseViewer
|
||||
PROPERTIES OUTPUT_NAME ${PROJECT_PREFIX}-databaseViewer)
|
||||
|
||||
INSTALL(TARGETS databaseViewer
|
||||
RUNTIME DESTINATION bin COMPONENT runtime
|
||||
LIBRARY DESTINATION lib COMPONENT devel
|
||||
ARCHIVE DESTINATION lib COMPONENT devel)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user