mirror of
https://github.com/introlab/rtabmap.git
synced 2026-09-01 17:10:26 +08:00
fixed delete database action when memory is not yet initialized, enabled gpu SURF option when available
git-svn-id: http://rtabmap.googlecode.com/svn/trunk/rtabmap@1055 f169173b-cf89-36c8-b27e-44dbe73f0c83
This commit is contained in:
@@ -26,6 +26,7 @@
|
||||
#include "rtabmap/utilite/UTimer.h"
|
||||
#include <opencv2/imgproc/imgproc_c.h>
|
||||
#include <opencv2/gpu/gpu.hpp>
|
||||
#include <opencv2/nonfree/gpu.hpp>
|
||||
#include <opencv2/core/version.hpp>
|
||||
#if CV_MAJOR_VERSION >=2 and CV_MINOR_VERSION >=4
|
||||
#include <opencv2/nonfree/features2d.hpp>
|
||||
@@ -155,18 +156,17 @@ cv::Mat SURFDescriptor::generateDescriptors(const cv::Mat & image, std::vector<c
|
||||
{
|
||||
img = image;
|
||||
}
|
||||
/*#if OPENCV_SURF_GPU
|
||||
if(_gpuVersion)
|
||||
if(_gpuVersion && cv::gpu::getCudaEnabledDeviceCount())
|
||||
{
|
||||
std::vector<float> d;
|
||||
cv::gpu::GpuMat imgGpu(img);
|
||||
cv::gpu::GpuMat descriptorsGpu;
|
||||
cv::gpu::GpuMat keypointsGpu;
|
||||
cv::gpu::SURF_GPU surfGpu(_params.hessianThreshold, _params.nOctaves, _params.nOctaveLayers, _params.extended, 0.01f, _params.upright);
|
||||
cv::gpu::SURF_GPU surfGpu(_hessianThreshold, _nOctaves, _nOctaveLayers, _extended, 0.01f, _upright);
|
||||
surfGpu.uploadKeypoints(keypoints, keypointsGpu);
|
||||
surfGpu(imgGpu, cv::gpu::GpuMat(), keypointsGpu, descriptorsGpu, true);
|
||||
surfGpu.downloadDescriptors(descriptorsGpu, d);
|
||||
unsigned int dim = _params.extended?128:64;
|
||||
unsigned int dim = _extended?128:64;
|
||||
descriptors = cv::Mat(d.size()/dim, dim, CV_32F);
|
||||
for(int i=0; i<descriptors.rows; ++i)
|
||||
{
|
||||
@@ -176,18 +176,15 @@ cv::Mat SURFDescriptor::generateDescriptors(const cv::Mat & image, std::vector<c
|
||||
}
|
||||
else
|
||||
{
|
||||
cv::SurfDescriptorExtractor extractor(_params.nOctaves, _params.nOctaveLayers, _params.extended, _params.upright);
|
||||
if(_gpuVersion)
|
||||
{
|
||||
UWARN("GPU version of SURF not available! Using CPU version instead...");
|
||||
}
|
||||
|
||||
cv::SURF extractor(_hessianThreshold, _nOctaves, _nOctaveLayers, _extended, _upright);
|
||||
extractor.compute(img, keypoints, descriptors);
|
||||
}
|
||||
#else*/
|
||||
#if CV_MAJOR_VERSION >=2 and CV_MINOR_VERSION >=4
|
||||
cv::SURF extractor(_hessianThreshold, _nOctaves, _nOctaveLayers, _extended, _upright);
|
||||
extractor.compute(img, keypoints, descriptors);
|
||||
#else
|
||||
cv::SurfDescriptorExtractor extractor(_nOctaves, _nOctaveLayers, _extended, _upright);
|
||||
extractor.compute(img, keypoints, descriptors);
|
||||
#endif
|
||||
//#endif
|
||||
|
||||
return descriptors;
|
||||
}
|
||||
|
||||
@@ -244,17 +241,10 @@ cv::Mat SIFTDescriptor::generateDescriptors(const cv::Mat & image, std::vector<c
|
||||
{
|
||||
img = image;
|
||||
}
|
||||
#if CV_MAJOR_VERSION >=2 and CV_MINOR_VERSION >=4
|
||||
|
||||
cv::SIFT extractor(_nfeatures, _nOctaveLayers, _contrastThreshold, _edgeThreshold, _sigma);
|
||||
extractor.compute(img, keypoints, descriptors);
|
||||
#else
|
||||
cv::SIFT extractor(cv::SIFT::DescriptorParams::GET_DEFAULT_MAGNIFICATION(),
|
||||
cv::SIFT::DescriptorParams::DEFAULT_IS_NORMALIZE,
|
||||
true,
|
||||
cv::SIFT::CommonParams::DEFAULT_NOCTAVES,
|
||||
_nOctaveLayers);
|
||||
extractor(img, cv::Mat(), keypoints, descriptors, true);
|
||||
#endif
|
||||
|
||||
return descriptors;
|
||||
}
|
||||
|
||||
@@ -411,30 +401,25 @@ std::vector<cv::KeyPoint> SURFDetector::_generateKeypoints(const cv::Mat & image
|
||||
}
|
||||
|
||||
cv::Mat imgRoi(img, roi);
|
||||
/*#if OPENCV_SURF_GPU
|
||||
if(_gpuVersion )
|
||||
if(_gpuVersion && cv::gpu::getCudaEnabledDeviceCount())
|
||||
{
|
||||
cv::gpu::GpuMat imgGpu(imgRoi);
|
||||
cv::gpu::GpuMat keypointsGpu;
|
||||
cv::gpu::SURF_GPU surfGpu(params.hessianThreshold, params.nOctaves, params.nOctaveLayers, params.extended, 0.01f, params.upright);
|
||||
cv::gpu::SURF_GPU surfGpu(_hessianThreshold, _nOctaves, _nOctaveLayers, _extended, 0.01f, _upright);
|
||||
surfGpu(imgGpu, cv::gpu::GpuMat(), keypointsGpu);
|
||||
surfGpu.downloadKeypoints(keypointsGpu, keypoints);
|
||||
}
|
||||
else
|
||||
{
|
||||
cv::SurfFeatureDetector detector(params.hessianThreshold, params.nOctaves, params.nOctaveLayers, params.upright);
|
||||
if(_gpuVersion)
|
||||
{
|
||||
UWARN("GPU version of SURF not available! Using CPU version instead...");
|
||||
}
|
||||
ULOGGER_DEBUG("%f %d %d %d %d", _hessianThreshold, _nOctaves, _nOctaveLayers, _extended?1:0, _upright?1:0);
|
||||
cv::SURF detector(_hessianThreshold, _nOctaves, _nOctaveLayers, _extended, _upright);
|
||||
detector.detect(imgRoi, keypoints);
|
||||
}
|
||||
#else*/
|
||||
ULOGGER_DEBUG("%f %d %d %d %d", _hessianThreshold, _nOctaves, _nOctaveLayers, _extended?1:0, _upright?1:0);
|
||||
cv::SURF detector(_hessianThreshold, _nOctaves, _nOctaveLayers, _extended, _upright);
|
||||
ULOGGER_DEBUG("");
|
||||
#if CV_MAJOR_VERSION >=2 and CV_MINOR_VERSION >=4
|
||||
detector.detect(imgRoi, keypoints);
|
||||
#else
|
||||
detector(imgRoi, cv::Mat(), keypoints);
|
||||
#endif
|
||||
//#endif
|
||||
|
||||
ULOGGER_DEBUG("");
|
||||
return keypoints;
|
||||
}
|
||||
@@ -493,13 +478,8 @@ std::vector<cv::KeyPoint> SIFTDetector::_generateKeypoints(const cv::Mat & image
|
||||
}
|
||||
|
||||
cv::Mat imgRoi(img, roi);
|
||||
#if CV_MAJOR_VERSION >=2 and CV_MINOR_VERSION >=4
|
||||
cv::SIFT detector(_nfeatures, _nOctaveLayers, _contrastThreshold, _edgeThreshold, _sigma);
|
||||
detector.detect(imgRoi, keypoints); // Opencv surf keypoints
|
||||
#else
|
||||
cv::SIFT detector(_contrastThreshold, _edgeThreshold, cv::SIFT::CommonParams::DEFAULT_NOCTAVES, _nOctaveLayers);
|
||||
detector(imgRoi, cv::Mat(), keypoints); // Opencv surf keypoints
|
||||
#endif
|
||||
return keypoints;
|
||||
}
|
||||
|
||||
|
||||
@@ -610,6 +610,7 @@ void Rtabmap::resetMemory(bool dbOverwritten)
|
||||
{
|
||||
// FIXME May be not work with other database type.
|
||||
// May be memory should be already created here, and use init above...
|
||||
UINFO("Erasing file : \"%s\"", getDatabasePath().c_str());
|
||||
UFile::erase(getDatabasePath());
|
||||
}
|
||||
this->setupLogFiles(dbOverwritten);
|
||||
@@ -1614,9 +1615,11 @@ void Rtabmap::setDatabasePath(const std::string & path)
|
||||
ULOGGER_DEBUG("Comparing new database path \"%s\" with \"%s\"", path.c_str(), _databasePath.c_str());
|
||||
if(path.compare(_databasePath) != 0)
|
||||
{
|
||||
UDEBUG("Set new database path to \"%s\"", _databasePath.c_str());
|
||||
_databasePath = path;
|
||||
if(_memory)
|
||||
{
|
||||
UDEBUG("Reset memory!");
|
||||
this->resetMemory();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -157,6 +157,10 @@ void RtabmapThread::mainLoop()
|
||||
_rtabmap->generateGraph(parameters.at("path"), atoi(parameters.at("id").c_str()), atoi(parameters.at("margin").c_str()));
|
||||
break;
|
||||
case kStateDeletingMemory:
|
||||
if(!parameters.at("path").empty())
|
||||
{
|
||||
_rtabmap->setDatabasePath(parameters.at("path"));
|
||||
}
|
||||
_rtabmap->resetMemory(true);
|
||||
this->clearBufferedData();
|
||||
break;
|
||||
@@ -243,7 +247,9 @@ void RtabmapThread::handleEvent(UEvent* event)
|
||||
else if(cmd == RtabmapEventCmd::kCmdDeleteMemory)
|
||||
{
|
||||
ULOGGER_DEBUG("CMD_DELETE_MEMORY");
|
||||
pushNewState(kStateDeletingMemory);
|
||||
ParametersMap param;
|
||||
param.insert(ParametersPair("path", rtabmapEvent->getStr()));
|
||||
pushNewState(kStateDeletingMemory, param);
|
||||
}
|
||||
else if(cmd == RtabmapEventCmd::kCmdCleanDataBuffer)
|
||||
{
|
||||
|
||||
@@ -126,6 +126,7 @@ public:
|
||||
int getScanPointSize(int index) const; // 0=map, 1=odom, 2=save
|
||||
|
||||
QString getWorkingDirectory() const;
|
||||
QString getDatabasePath() const;
|
||||
|
||||
// source panel
|
||||
double getGeneralInputRate() const;
|
||||
|
||||
@@ -831,15 +831,6 @@ void MainWindow::processStats(const rtabmap::Statistics & stat)
|
||||
|
||||
UDEBUG("time= %d ms", time.restart());
|
||||
|
||||
if(_ui->imageView_loopClosure->items().size() || stat.loopClosureId()>0)
|
||||
{
|
||||
this->drawKeypoints(stat.refWords(), stat.loopWords());
|
||||
}
|
||||
else
|
||||
{
|
||||
this->drawKeypoints(stat.refWords(), std::multimap<int, cv::KeyPoint>()); //empty loop keypoints...
|
||||
}
|
||||
|
||||
// We use the reference image to resize the 2 views
|
||||
_ui->imageView_source->resetZoom();
|
||||
_ui->imageView_loopClosure->resetZoom();
|
||||
@@ -851,6 +842,16 @@ void MainWindow::processStats(const rtabmap::Statistics & stat)
|
||||
_ui->imageView_source->fitInView(_ui->imageView_source->sceneRect(), Qt::KeepAspectRatio);
|
||||
_ui->imageView_loopClosure->fitInView(_ui->imageView_source->sceneRect(), Qt::KeepAspectRatio);
|
||||
|
||||
// do it after scaling
|
||||
if(_ui->imageView_loopClosure->items().size() || stat.loopClosureId()>0)
|
||||
{
|
||||
this->drawKeypoints(stat.refWords(), stat.loopWords());
|
||||
}
|
||||
else
|
||||
{
|
||||
this->drawKeypoints(stat.refWords(), std::multimap<int, cv::KeyPoint>()); //empty loop keypoints...
|
||||
}
|
||||
|
||||
if(_preferencesDialog->isImageFlipped())
|
||||
{
|
||||
_ui->imageView_source->scale(-1.0, 1.0);
|
||||
@@ -1543,13 +1544,16 @@ void MainWindow::drawKeypoints(const std::multimap<int, cv::KeyPoint> & refWords
|
||||
}
|
||||
|
||||
// Draw lines between corresponding features...
|
||||
int deltaX = _ui->imageView_source->sceneRect().width();
|
||||
float scaleX = _ui->imageView_source->transform().m11();
|
||||
float scaleY = _ui->imageView_source->transform().m22();
|
||||
UDEBUG("scaleX=%f scaleY=%f", scaleX, scaleY);
|
||||
int deltaX = _ui->imageView_source->width()/scaleX;
|
||||
int deltaY = 0;
|
||||
if(_preferencesDialog->isVerticalLayoutUsed())
|
||||
{
|
||||
deltaX = 0;
|
||||
deltaY = _ui->imageView_source->sceneRect().height();
|
||||
deltaY += _ui->label_matchId->height()/_ui->imageView_source->transform().m22();
|
||||
deltaY = _ui->imageView_source->height()/scaleY;
|
||||
deltaY += _ui->label_matchId->height()/scaleY;
|
||||
}
|
||||
for(QList<QPair<KeypointItem*, KeypointItem*> >::iterator iter = uniqueCorrespondences.begin();
|
||||
iter!=uniqueCorrespondences.end();
|
||||
@@ -2147,7 +2151,7 @@ void MainWindow::generateLocalMap()
|
||||
void MainWindow::deleteMemory()
|
||||
{
|
||||
QMessageBox::StandardButton button;
|
||||
QString dbPath = _preferencesDialog->getWorkingDirectory() + QDir::separator() + "rtabmap.db";
|
||||
QString dbPath = _preferencesDialog->getDatabasePath();
|
||||
if(_state == kMonitoring || _state == kMonitoringPaused)
|
||||
{
|
||||
button = QMessageBox::question(this,
|
||||
@@ -2170,7 +2174,7 @@ void MainWindow::deleteMemory()
|
||||
return;
|
||||
}
|
||||
|
||||
this->post(new RtabmapEventCmd(RtabmapEventCmd::kCmdDeleteMemory));
|
||||
this->post(new RtabmapEventCmd(RtabmapEventCmd::kCmdDeleteMemory, dbPath.toStdString()));
|
||||
this->clearTheCache();
|
||||
}
|
||||
|
||||
|
||||
@@ -49,6 +49,8 @@
|
||||
#include <rtabmap/utilite/UEventsManager.h>
|
||||
#include "utilite/UPlot.h"
|
||||
|
||||
#include <opencv2/gpu/gpu.hpp>
|
||||
|
||||
using namespace rtabmap;
|
||||
|
||||
namespace rtabmap {
|
||||
@@ -115,6 +117,14 @@ PreferencesDialog::PreferencesDialog(QWidget * parent) :
|
||||
_ui->label_space2->setEnabled(false);
|
||||
_ui->label_space3->setEnabled(false);
|
||||
_ui->loopClosure_icpType->setEnabled(false);
|
||||
_ui->surf_checkBox_gpuVersion->setEnabled(false);
|
||||
_ui->label_surf_checkBox_gpuVersion->setEnabled(false);
|
||||
#else
|
||||
if(cv::gpu::getCudaEnabledDeviceCount() == 0)
|
||||
{
|
||||
_ui->surf_checkBox_gpuVersion->setEnabled(false);
|
||||
_ui->label_surf_checkBox_gpuVersion->setEnabled(false);
|
||||
}
|
||||
#endif
|
||||
_ui->predictionPlot->showLegend(false);
|
||||
|
||||
@@ -824,6 +834,11 @@ QString PreferencesDialog::getWorkingDirectory() const
|
||||
return _ui->lineEdit_workingDirectory->text();
|
||||
}
|
||||
|
||||
QString PreferencesDialog::getDatabasePath() const
|
||||
{
|
||||
return _ui->lineEdit_databasePath->text();
|
||||
}
|
||||
|
||||
QString PreferencesDialog::getIniFilePath() const
|
||||
{
|
||||
#ifdef DEMO_BUILD
|
||||
|
||||
@@ -64,8 +64,8 @@
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>939</width>
|
||||
<height>724</height>
|
||||
<width>955</width>
|
||||
<height>685</height>
|
||||
</rect>
|
||||
</property>
|
||||
<layout class="QVBoxLayout" name="verticalLayout_16">
|
||||
@@ -86,7 +86,7 @@
|
||||
<enum>QFrame::Raised</enum>
|
||||
</property>
|
||||
<property name="currentIndex">
|
||||
<number>1</number>
|
||||
<number>9</number>
|
||||
</property>
|
||||
<widget class="QWidget" name="page_22">
|
||||
<layout class="QVBoxLayout" name="verticalLayout_29">
|
||||
@@ -3048,7 +3048,7 @@ generate the number of words requested.</string>
|
||||
<item row="5" column="0">
|
||||
<widget class="QCheckBox" name="surf_checkBox_gpuVersion">
|
||||
<property name="enabled">
|
||||
<bool>false</bool>
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string/>
|
||||
@@ -3056,12 +3056,12 @@ generate the number of words requested.</string>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="5" column="1">
|
||||
<widget class="QLabel" name="label_48">
|
||||
<widget class="QLabel" name="label_surf_checkBox_gpuVersion">
|
||||
<property name="enabled">
|
||||
<bool>false</bool>
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>GPU version (as well for descriptor). Experimental.</string>
|
||||
<string>GPU version (as well for descriptor).</string>
|
||||
</property>
|
||||
<property name="wordWrap">
|
||||
<bool>true</bool>
|
||||
|
||||
Reference in New Issue
Block a user