Added image sequence to rtabmap::Image class

git-svn-id: http://rtabmap.googlecode.com/svn/trunk/rtabmap@740 f169173b-cf89-36c8-b27e-44dbe73f0c83
This commit is contained in:
matlabbe
2013-01-21 18:55:25 +00:00
parent 1836f39304
commit 0c1b8d7349
7 changed files with 39 additions and 9 deletions

View File

@@ -59,7 +59,7 @@ public:
CameraEvent(const cv::Mat & descriptors, const std::vector<cv::KeyPoint> & keypoints, const cv::Mat & image = cv::Mat(), int cameraId = 0) : CameraEvent(const cv::Mat & descriptors, const std::vector<cv::KeyPoint> & keypoints, const cv::Mat & image = cv::Mat(), int cameraId = 0) :
UEvent(kCodeFeatures), UEvent(kCodeFeatures),
_cameraId(cameraId), _cameraId(cameraId),
_image(image, descriptors, keypoints) _image(image, 0, descriptors, keypoints)
{ {
} }
CameraEvent(int cameraId = 0) : CameraEvent(int cameraId = 0) :

View File

@@ -16,13 +16,18 @@
namespace rtabmap namespace rtabmap
{ {
/**
* An id is automatically generated if id=0.
*/
class Image class Image
{ {
public: public:
Image(const cv::Mat & image = cv::Mat(), Image(const cv::Mat & image = cv::Mat(),
int id = 0,
const cv::Mat & descriptors = cv::Mat(), const cv::Mat & descriptors = cv::Mat(),
const std::vector<cv::KeyPoint> & keypoints = std::vector<cv::KeyPoint>()) : const std::vector<cv::KeyPoint> & keypoints = std::vector<cv::KeyPoint>()) :
_image(image), _image(image),
_id(id),
_descriptors(descriptors), _descriptors(descriptors),
_keypoints(keypoints) _keypoints(keypoints)
{ {
@@ -30,11 +35,13 @@ public:
bool empty() const {return _image.empty() && _descriptors.empty() && _keypoints.size() == 0;} bool empty() const {return _image.empty() && _descriptors.empty() && _keypoints.size() == 0;}
const cv::Mat & image() const {return _image;} const cv::Mat & image() const {return _image;}
int id() const {return _id;};
const cv::Mat & descriptors() const {return _descriptors;} const cv::Mat & descriptors() const {return _descriptors;}
const std::vector<cv::KeyPoint> & keypoints() const {return _keypoints;} const std::vector<cv::KeyPoint> & keypoints() const {return _keypoints;}
private: private:
cv::Mat _image; cv::Mat _image;
int _id;
cv::Mat _descriptors; cv::Mat _descriptors;
std::vector<cv::KeyPoint> _keypoints; std::vector<cv::KeyPoint> _keypoints;
}; };

View File

@@ -142,7 +142,7 @@ protected:
private: private:
void copyData(const Signature * from, Signature * to); void copyData(const Signature * from, Signature * to);
Signature * createSignature(int id, Signature * createSignature(
const Image & image, const Image & image,
bool keepRawData=false); bool keepRawData=false);

View File

@@ -73,7 +73,7 @@ public:
Rtabmap(); Rtabmap();
virtual ~Rtabmap(); virtual ~Rtabmap();
void process(const cv::Mat & image); // for convenience void process(const cv::Mat & image, int id=0); // for convenience, an id is automatically generated if id=0
void process(const Image & image); // for convenience void process(const Image & image); // for convenience
void init(const ParametersMap & param, bool deleteMemory = true); void init(const ParametersMap & param, bool deleteMemory = true);
@@ -94,6 +94,7 @@ public:
std::map<int, int> getWeights(); std::map<int, int> getWeights();
int getTotalMemSize(); int getTotalMemSize();
double getLastProcessTime() const {return _lastProcessTime;}; double getLastProcessTime() const {return _lastProcessTime;};
std::multimap<int, cv::KeyPoint> getWords(int nodeId);
void setTimeThreshold(float maxTimeAllowed); // in ms void setTimeThreshold(float maxTimeAllowed); // in ms

View File

@@ -386,7 +386,7 @@ bool Memory::update(const Image & image, std::map<std::string, float> & stats)
//============================================================ //============================================================
// Create a signature with the image received. // Create a signature with the image received.
//============================================================ //============================================================
Signature * signature = this->createSignature(this->getNextId(), image, this->isRawDataKept()); Signature * signature = this->createSignature(image, this->isRawDataKept());
if (signature == 0) if (signature == 0)
{ {
UERROR("Failed to create a signature"); UERROR("Failed to create a signature");
@@ -2094,7 +2094,7 @@ private:
VWDictionary * _vwp; VWDictionary * _vwp;
}; };
Signature * Memory::createSignature(int id, const Image & image, bool keepRawData) Signature * Memory::createSignature(const Image & image, bool keepRawData)
{ {
PreUpdateThread preUpdateThread(_vwd); PreUpdateThread preUpdateThread(_vwd);
@@ -2102,6 +2102,11 @@ Signature * Memory::createSignature(int id, const Image & image, bool keepRawDat
timer.start(); timer.start();
std::vector<cv::KeyPoint> keypoints; std::vector<cv::KeyPoint> keypoints;
cv::Mat descriptors; cv::Mat descriptors;
int id = image.id();
if(!id)
{
id = this->getNextId();
}
int treeSize= _workingMem.size() + _stMem.size(); int treeSize= _workingMem.size() + _stMem.size();
int nbCommonWords = 0; int nbCommonWords = 0;

View File

@@ -502,6 +502,23 @@ int Rtabmap::getTotalMemSize()
return memSize; return memSize;
} }
std::multimap<int, cv::KeyPoint> Rtabmap::getWords(int nodeId)
{
UScopeMutex s(&_threadMutex);
std::multimap<int, cv::KeyPoint> words;
if(_memory)
{
const Signature * s = _memory->getSignature(nodeId);
if(s)
{
words = s->getWords();
}
}
return words;
}
void Rtabmap::clearBufferedSensors() void Rtabmap::clearBufferedSensors()
{ {
_imageMutex.lock(); _imageMutex.lock();
@@ -1466,10 +1483,10 @@ void Rtabmap::setWorkingDirectory(std::string path)
} }
} }
void Rtabmap::process(const cv::Mat & image) void Rtabmap::process(const cv::Mat & image, int id)
{ {
UScopeMutex s(&_threadMutex); UScopeMutex s(&_threadMutex);
this->process(Image(image)); this->process(Image(image, id));
} }
void Rtabmap::process(const Image & image) void Rtabmap::process(const Image & image)

View File

@@ -435,7 +435,7 @@ int main(int argc, char * argv[])
cv::Mat descriptors; cv::Mat descriptors;
std::vector<cv::KeyPoint> keypoints; std::vector<cv::KeyPoint> keypoints;
cv::Mat cvImg = camera->takeImage(descriptors, keypoints); cv::Mat cvImg = camera->takeImage(descriptors, keypoints);
Image img(cvImg, descriptors, keypoints); Image img(cvImg, 0, descriptors, keypoints);
int i=0; int i=0;
double maxIterationTime = 0.0; double maxIterationTime = 0.0;
int maxIterationTimeId = 0; int maxIterationTimeId = 0;
@@ -452,7 +452,7 @@ int main(int argc, char * argv[])
++countLoopDetected; ++countLoopDetected;
} }
cvImg = camera->takeImage(descriptors, keypoints); cvImg = camera->takeImage(descriptors, keypoints);
img = Image(cvImg, descriptors, keypoints); img = Image(cvImg, 0, descriptors, keypoints);
if(++count % 100 == 0) if(++count % 100 == 0)
{ {
printf(" count = %d, loop closures = %d, max time (at %d) = %fs\n", printf(" count = %d, loop closures = %d, max time (at %d) = %fs\n",