mirror of
https://github.com/introlab/rtabmap.git
synced 2026-09-02 17:40:23 +08:00
Improved DatabaseViewer memory usage (by not keeping uncompressed data in cache)
This commit is contained in:
@@ -61,7 +61,7 @@ public:
|
|||||||
static void getConnectedGraph(
|
static void getConnectedGraph(
|
||||||
int fromId,
|
int fromId,
|
||||||
const std::map<int, Transform> & posesIn,
|
const std::map<int, Transform> & posesIn,
|
||||||
const std::multimap<int, Link> & linksIn,
|
const std::multimap<int, Link> & linksIn, // only one link between two poses
|
||||||
std::map<int, Transform> & posesOut,
|
std::map<int, Transform> & posesOut,
|
||||||
std::multimap<int, Link> & linksOut,
|
std::multimap<int, Link> & linksOut,
|
||||||
int depth = 0);
|
int depth = 0);
|
||||||
|
|||||||
@@ -141,7 +141,7 @@ public:
|
|||||||
double & stamp,
|
double & stamp,
|
||||||
bool lookInDatabase = false) const;
|
bool lookInDatabase = false) const;
|
||||||
cv::Mat getImageCompressed(int signatureId) const;
|
cv::Mat getImageCompressed(int signatureId) const;
|
||||||
SensorData getNodeData(int nodeId, bool uncompressedData = false);
|
SensorData getNodeData(int nodeId, bool uncompressedData = false, bool keepLoadedDataInMemory = true);
|
||||||
void getNodeWords(int nodeId,
|
void getNodeWords(int nodeId,
|
||||||
std::multimap<int, cv::KeyPoint> & words,
|
std::multimap<int, cv::KeyPoint> & words,
|
||||||
std::multimap<int, pcl::PointXYZ> & words3);
|
std::multimap<int, pcl::PointXYZ> & words3);
|
||||||
|
|||||||
@@ -239,6 +239,7 @@ void Optimizer::getConnectedGraph(
|
|||||||
std::multimap<int, int> biLinks;
|
std::multimap<int, int> biLinks;
|
||||||
for(std::multimap<int, Link>::const_iterator iter=linksIn.begin(); iter!=linksIn.end(); ++iter)
|
for(std::multimap<int, Link>::const_iterator iter=linksIn.begin(); iter!=linksIn.end(); ++iter)
|
||||||
{
|
{
|
||||||
|
UASSERT_MSG(findLink(biLinks, iter->second.from(), iter->second.to()) == biLinks.end(), "Input links should be unique between two poses.");
|
||||||
biLinks.insert(std::make_pair(iter->second.from(), iter->second.to()));
|
biLinks.insert(std::make_pair(iter->second.from(), iter->second.to()));
|
||||||
biLinks.insert(std::make_pair(iter->second.to(), iter->second.from()));
|
biLinks.insert(std::make_pair(iter->second.to(), iter->second.from()));
|
||||||
}
|
}
|
||||||
@@ -262,7 +263,7 @@ void Optimizer::getConnectedGraph(
|
|||||||
{
|
{
|
||||||
nextDepth.insert(nextId);
|
nextDepth.insert(nextId);
|
||||||
|
|
||||||
std::map<int, Link>::const_iterator kter = graph::findLink(linksIn, *jter, nextId);
|
std::multimap<int, Link>::const_iterator kter = graph::findLink(linksIn, *jter, nextId);
|
||||||
if(depth == 0 || d < depth-1)
|
if(depth == 0 || d < depth-1)
|
||||||
{
|
{
|
||||||
linksOut.insert(*kter);
|
linksOut.insert(*kter);
|
||||||
|
|||||||
@@ -3392,23 +3392,27 @@ cv::Mat Memory::getImageCompressed(int signatureId) const
|
|||||||
return image;
|
return image;
|
||||||
}
|
}
|
||||||
|
|
||||||
SensorData Memory::getNodeData(int nodeId, bool uncompressedData)
|
SensorData Memory::getNodeData(int nodeId, bool uncompressedData, bool keepLoadedDataInMemory)
|
||||||
{
|
{
|
||||||
UDEBUG("nodeId=%d", nodeId);
|
UDEBUG("nodeId=%d", nodeId);
|
||||||
SensorData r;
|
SensorData r;
|
||||||
Signature * s = this->_getSignature(nodeId);
|
Signature * s = this->_getSignature(nodeId);
|
||||||
if(s && !s->sensorData().imageCompressed().empty())
|
if(s && !s->sensorData().imageCompressed().empty())
|
||||||
{
|
{
|
||||||
if(uncompressedData)
|
if(keepLoadedDataInMemory && uncompressedData)
|
||||||
{
|
{
|
||||||
s->sensorData().uncompressData();
|
s->sensorData().uncompressData();
|
||||||
}
|
}
|
||||||
r = s->sensorData();
|
r = s->sensorData();
|
||||||
|
if(!keepLoadedDataInMemory && uncompressedData)
|
||||||
|
{
|
||||||
|
r.uncompressData();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else if(_dbDriver)
|
else if(_dbDriver)
|
||||||
{
|
{
|
||||||
// load from database
|
// load from database
|
||||||
if(s)
|
if(s && keepLoadedDataInMemory)
|
||||||
{
|
{
|
||||||
std::list<Signature*> signatures;
|
std::list<Signature*> signatures;
|
||||||
signatures.push_back(s);
|
signatures.push_back(s);
|
||||||
|
|||||||
@@ -838,7 +838,7 @@ void DatabaseViewer::exportDatabase()
|
|||||||
{
|
{
|
||||||
int id = ids.at(i);
|
int id = ids.at(i);
|
||||||
|
|
||||||
SensorData data = memory_->getNodeData(id, true);
|
SensorData data = memory_->getNodeData(id, true, false);
|
||||||
cv::Mat covariance = cv::Mat::eye(6,6,CV_64FC1);
|
cv::Mat covariance = cv::Mat::eye(6,6,CV_64FC1);
|
||||||
if(dialog.isOdomExported())
|
if(dialog.isOdomExported())
|
||||||
{
|
{
|
||||||
@@ -919,7 +919,7 @@ void DatabaseViewer::extractImages()
|
|||||||
if(ids_.size())
|
if(ids_.size())
|
||||||
{
|
{
|
||||||
int id = ids_.at(0);
|
int id = ids_.at(0);
|
||||||
SensorData data = memory_->getNodeData(id, true);
|
SensorData data = memory_->getNodeData(id, true, false);
|
||||||
if(!data.imageRaw().empty() && !data.rightRaw().empty())
|
if(!data.imageRaw().empty() && !data.rightRaw().empty())
|
||||||
{
|
{
|
||||||
QDir dir;
|
QDir dir;
|
||||||
@@ -1001,7 +1001,7 @@ void DatabaseViewer::extractImages()
|
|||||||
for(int i=0; i<ids_.size(); ++i)
|
for(int i=0; i<ids_.size(); ++i)
|
||||||
{
|
{
|
||||||
int id = ids_.at(i);
|
int id = ids_.at(i);
|
||||||
SensorData data = memory_->getNodeData(id, true);
|
SensorData data = memory_->getNodeData(id, true, false);
|
||||||
if(!data.imageRaw().empty() && !data.rightRaw().empty())
|
if(!data.imageRaw().empty() && !data.rightRaw().empty())
|
||||||
{
|
{
|
||||||
cv::imwrite(QString("%1/left/%2.jpg").arg(path).arg(id).toStdString(), data.imageRaw());
|
cv::imwrite(QString("%1/left/%2.jpg").arg(path).arg(id).toStdString(), data.imageRaw());
|
||||||
@@ -1342,7 +1342,7 @@ void DatabaseViewer::view3DMap()
|
|||||||
rtabmap::Transform pose = iter->second;
|
rtabmap::Transform pose = iter->second;
|
||||||
if(!pose.isNull())
|
if(!pose.isNull())
|
||||||
{
|
{
|
||||||
SensorData data = memory_->getNodeData(iter->first, true);
|
SensorData data = memory_->getNodeData(iter->first, true, false);
|
||||||
pcl::PointCloud<pcl::PointXYZRGB>::Ptr cloud;
|
pcl::PointCloud<pcl::PointXYZRGB>::Ptr cloud;
|
||||||
UASSERT(data.imageRaw().empty() || data.imageRaw().type()==CV_8UC3 || data.imageRaw().type() == CV_8UC1);
|
UASSERT(data.imageRaw().empty() || data.imageRaw().type()==CV_8UC3 || data.imageRaw().type() == CV_8UC1);
|
||||||
UASSERT(data.depthOrRightRaw().empty() || data.depthOrRightRaw().type()==CV_8UC1 || data.depthOrRightRaw().type() == CV_16UC1 || data.depthOrRightRaw().type() == CV_32FC1);
|
UASSERT(data.depthOrRightRaw().empty() || data.depthOrRightRaw().type()==CV_8UC1 || data.depthOrRightRaw().type() == CV_16UC1 || data.depthOrRightRaw().type() == CV_32FC1);
|
||||||
@@ -1426,7 +1426,7 @@ void DatabaseViewer::generate3DMap()
|
|||||||
const rtabmap::Transform & pose = iter->second;
|
const rtabmap::Transform & pose = iter->second;
|
||||||
if(!pose.isNull())
|
if(!pose.isNull())
|
||||||
{
|
{
|
||||||
SensorData data = memory_->getNodeData(iter->first, true);
|
SensorData data = memory_->getNodeData(iter->first, true, false);
|
||||||
pcl::PointCloud<pcl::PointXYZRGB>::Ptr cloud;
|
pcl::PointCloud<pcl::PointXYZRGB>::Ptr cloud;
|
||||||
UASSERT(data.imageRaw().empty() || data.imageRaw().type()==CV_8UC3 || data.imageRaw().type() == CV_8UC1);
|
UASSERT(data.imageRaw().empty() || data.imageRaw().type()==CV_8UC3 || data.imageRaw().type() == CV_8UC1);
|
||||||
UASSERT(data.depthOrRightRaw().empty() || data.depthOrRightRaw().type()==CV_8UC1 || data.depthOrRightRaw().type() == CV_16UC1 || data.depthOrRightRaw().type() == CV_32FC1);
|
UASSERT(data.depthOrRightRaw().empty() || data.depthOrRightRaw().type()==CV_8UC1 || data.depthOrRightRaw().type() == CV_16UC1 || data.depthOrRightRaw().type() == CV_32FC1);
|
||||||
@@ -1690,7 +1690,7 @@ void DatabaseViewer::update(int value,
|
|||||||
QImage imgDepth;
|
QImage imgDepth;
|
||||||
if(memory_)
|
if(memory_)
|
||||||
{
|
{
|
||||||
SensorData data = memory_->getNodeData(id, true);
|
SensorData data = memory_->getNodeData(id, true, false);
|
||||||
if(!data.imageRaw().empty())
|
if(!data.imageRaw().empty())
|
||||||
{
|
{
|
||||||
img = uCvMat2QImage(data.imageRaw());
|
img = uCvMat2QImage(data.imageRaw());
|
||||||
@@ -1898,7 +1898,7 @@ void DatabaseViewer::updateStereo()
|
|||||||
if(ui_->horizontalSlider_A->maximum())
|
if(ui_->horizontalSlider_A->maximum())
|
||||||
{
|
{
|
||||||
int id = ids_.at(ui_->horizontalSlider_A->value());
|
int id = ids_.at(ui_->horizontalSlider_A->value());
|
||||||
SensorData data = memory_->getNodeData(id, true);
|
SensorData data = memory_->getNodeData(id, true, false);
|
||||||
updateStereo(&data);
|
updateStereo(&data);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -2308,11 +2308,11 @@ void DatabaseViewer::updateConstraintView(
|
|||||||
{
|
{
|
||||||
SensorData dataFrom, dataTo;
|
SensorData dataFrom, dataTo;
|
||||||
|
|
||||||
dataFrom = memory_->getNodeData(link.from(), true);
|
dataFrom = memory_->getNodeData(link.from(), true, false);
|
||||||
UASSERT(dataFrom.imageRaw().empty() || dataFrom.imageRaw().type()==CV_8UC3 || dataFrom.imageRaw().type() == CV_8UC1);
|
UASSERT(dataFrom.imageRaw().empty() || dataFrom.imageRaw().type()==CV_8UC3 || dataFrom.imageRaw().type() == CV_8UC1);
|
||||||
UASSERT(dataFrom.depthOrRightRaw().empty() || dataFrom.depthOrRightRaw().type()==CV_8UC1 || dataFrom.depthOrRightRaw().type() == CV_16UC1 || dataFrom.depthOrRightRaw().type() == CV_32FC1);
|
UASSERT(dataFrom.depthOrRightRaw().empty() || dataFrom.depthOrRightRaw().type()==CV_8UC1 || dataFrom.depthOrRightRaw().type() == CV_16UC1 || dataFrom.depthOrRightRaw().type() == CV_32FC1);
|
||||||
|
|
||||||
dataTo = memory_->getNodeData(link.to(), true);
|
dataTo = memory_->getNodeData(link.to(), true, false);
|
||||||
UASSERT(dataTo.imageRaw().empty() || dataTo.imageRaw().type()==CV_8UC3 || dataTo.imageRaw().type() == CV_8UC1);
|
UASSERT(dataTo.imageRaw().empty() || dataTo.imageRaw().type()==CV_8UC3 || dataTo.imageRaw().type() == CV_8UC1);
|
||||||
UASSERT(dataTo.depthOrRightRaw().empty() || dataTo.depthOrRightRaw().type()==CV_8UC1 || dataTo.depthOrRightRaw().type() == CV_16UC1 || dataTo.depthOrRightRaw().type() == CV_32FC1);
|
UASSERT(dataTo.depthOrRightRaw().empty() || dataTo.depthOrRightRaw().type()==CV_8UC1 || dataTo.depthOrRightRaw().type() == CV_16UC1 || dataTo.depthOrRightRaw().type() == CV_32FC1);
|
||||||
|
|
||||||
@@ -2699,7 +2699,7 @@ void DatabaseViewer::sliderIterationsValueChanged(int value)
|
|||||||
bool added = false;
|
bool added = false;
|
||||||
if(ui_->groupBox_gridFromProjection->isChecked())
|
if(ui_->groupBox_gridFromProjection->isChecked())
|
||||||
{
|
{
|
||||||
SensorData data = memory_->getNodeData(ids.at(i), true);
|
SensorData data = memory_->getNodeData(ids.at(i), true, false);
|
||||||
if(!data.depthOrRightRaw().empty())
|
if(!data.depthOrRightRaw().empty())
|
||||||
{
|
{
|
||||||
pcl::PointCloud<pcl::PointXYZ>::Ptr cloud;
|
pcl::PointCloud<pcl::PointXYZ>::Ptr cloud;
|
||||||
@@ -2757,6 +2757,18 @@ void DatabaseViewer::sliderIterationsValueChanged(int value)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
//cleanup
|
||||||
|
for(std::map<int, std::pair<cv::Mat, cv::Mat> >::iterator iter=localMaps_.begin(); iter!=localMaps_.end();)
|
||||||
|
{
|
||||||
|
if(graphFiltered.find(iter->first) == graphFiltered.end())
|
||||||
|
{
|
||||||
|
localMaps_.erase(iter++);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
++iter;
|
||||||
|
}
|
||||||
|
}
|
||||||
UINFO("Update local maps list... done");
|
UINFO("Update local maps list... done");
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -3338,8 +3350,8 @@ void DatabaseViewer::refineConstraintVisually(int from, int to, bool silent, boo
|
|||||||
Memory tmpMemory(parameters);
|
Memory tmpMemory(parameters);
|
||||||
|
|
||||||
// Add signatures
|
// Add signatures
|
||||||
SensorData dataFrom = memory_->getNodeData(from, true);
|
SensorData dataFrom = memory_->getNodeData(from, true, false);
|
||||||
SensorData dataTo = memory_->getNodeData(to, true);
|
SensorData dataTo = memory_->getNodeData(to, true, false);
|
||||||
|
|
||||||
if(from > to)
|
if(from > to)
|
||||||
{
|
{
|
||||||
@@ -3459,8 +3471,8 @@ bool DatabaseViewer::addConstraint(int from, int to, bool silent, bool updateGra
|
|||||||
Memory tmpMemory(parameters);
|
Memory tmpMemory(parameters);
|
||||||
|
|
||||||
// Add signatures
|
// Add signatures
|
||||||
SensorData dataFrom = memory_->getNodeData(from, true);
|
SensorData dataFrom = memory_->getNodeData(from, true, false);
|
||||||
SensorData dataTo = memory_->getNodeData(to, true);
|
SensorData dataTo = memory_->getNodeData(to, true, false);
|
||||||
|
|
||||||
if(from > to)
|
if(from > to)
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user