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:
matlabbe
2013-12-14 02:43:26 +00:00
parent a3c0158650
commit 4a150e3215
7 changed files with 73 additions and 64 deletions

View File

@@ -26,6 +26,7 @@
#include "rtabmap/utilite/UTimer.h" #include "rtabmap/utilite/UTimer.h"
#include <opencv2/imgproc/imgproc_c.h> #include <opencv2/imgproc/imgproc_c.h>
#include <opencv2/gpu/gpu.hpp> #include <opencv2/gpu/gpu.hpp>
#include <opencv2/nonfree/gpu.hpp>
#include <opencv2/core/version.hpp> #include <opencv2/core/version.hpp>
#if CV_MAJOR_VERSION >=2 and CV_MINOR_VERSION >=4 #if CV_MAJOR_VERSION >=2 and CV_MINOR_VERSION >=4
#include <opencv2/nonfree/features2d.hpp> #include <opencv2/nonfree/features2d.hpp>
@@ -155,18 +156,17 @@ cv::Mat SURFDescriptor::generateDescriptors(const cv::Mat & image, std::vector<c
{ {
img = image; img = image;
} }
/*#if OPENCV_SURF_GPU if(_gpuVersion && cv::gpu::getCudaEnabledDeviceCount())
if(_gpuVersion)
{ {
std::vector<float> d; std::vector<float> d;
cv::gpu::GpuMat imgGpu(img); cv::gpu::GpuMat imgGpu(img);
cv::gpu::GpuMat descriptorsGpu; cv::gpu::GpuMat descriptorsGpu;
cv::gpu::GpuMat keypointsGpu; 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.uploadKeypoints(keypoints, keypointsGpu);
surfGpu(imgGpu, cv::gpu::GpuMat(), keypointsGpu, descriptorsGpu, true); surfGpu(imgGpu, cv::gpu::GpuMat(), keypointsGpu, descriptorsGpu, true);
surfGpu.downloadDescriptors(descriptorsGpu, d); 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); descriptors = cv::Mat(d.size()/dim, dim, CV_32F);
for(int i=0; i<descriptors.rows; ++i) for(int i=0; i<descriptors.rows; ++i)
{ {
@@ -176,18 +176,15 @@ cv::Mat SURFDescriptor::generateDescriptors(const cv::Mat & image, std::vector<c
} }
else 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); 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; return descriptors;
} }
@@ -244,17 +241,10 @@ cv::Mat SIFTDescriptor::generateDescriptors(const cv::Mat & image, std::vector<c
{ {
img = image; img = image;
} }
#if CV_MAJOR_VERSION >=2 and CV_MINOR_VERSION >=4
cv::SIFT extractor(_nfeatures, _nOctaveLayers, _contrastThreshold, _edgeThreshold, _sigma); cv::SIFT extractor(_nfeatures, _nOctaveLayers, _contrastThreshold, _edgeThreshold, _sigma);
extractor.compute(img, keypoints, descriptors); 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; return descriptors;
} }
@@ -411,30 +401,25 @@ std::vector<cv::KeyPoint> SURFDetector::_generateKeypoints(const cv::Mat & image
} }
cv::Mat imgRoi(img, roi); cv::Mat imgRoi(img, roi);
/*#if OPENCV_SURF_GPU if(_gpuVersion && cv::gpu::getCudaEnabledDeviceCount())
if(_gpuVersion )
{ {
cv::gpu::GpuMat imgGpu(imgRoi); cv::gpu::GpuMat imgGpu(imgRoi);
cv::gpu::GpuMat keypointsGpu; 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(imgGpu, cv::gpu::GpuMat(), keypointsGpu);
surfGpu.downloadKeypoints(keypointsGpu, keypoints); surfGpu.downloadKeypoints(keypointsGpu, keypoints);
} }
else 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); 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(""); ULOGGER_DEBUG("");
return keypoints; return keypoints;
} }
@@ -493,13 +478,8 @@ std::vector<cv::KeyPoint> SIFTDetector::_generateKeypoints(const cv::Mat & image
} }
cv::Mat imgRoi(img, roi); cv::Mat imgRoi(img, roi);
#if CV_MAJOR_VERSION >=2 and CV_MINOR_VERSION >=4
cv::SIFT detector(_nfeatures, _nOctaveLayers, _contrastThreshold, _edgeThreshold, _sigma); cv::SIFT detector(_nfeatures, _nOctaveLayers, _contrastThreshold, _edgeThreshold, _sigma);
detector.detect(imgRoi, keypoints); // Opencv surf keypoints 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; return keypoints;
} }

View File

@@ -610,6 +610,7 @@ void Rtabmap::resetMemory(bool dbOverwritten)
{ {
// FIXME May be not work with other database type. // FIXME May be not work with other database type.
// May be memory should be already created here, and use init above... // May be memory should be already created here, and use init above...
UINFO("Erasing file : \"%s\"", getDatabasePath().c_str());
UFile::erase(getDatabasePath()); UFile::erase(getDatabasePath());
} }
this->setupLogFiles(dbOverwritten); 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()); ULOGGER_DEBUG("Comparing new database path \"%s\" with \"%s\"", path.c_str(), _databasePath.c_str());
if(path.compare(_databasePath) != 0) if(path.compare(_databasePath) != 0)
{ {
UDEBUG("Set new database path to \"%s\"", _databasePath.c_str());
_databasePath = path; _databasePath = path;
if(_memory) if(_memory)
{ {
UDEBUG("Reset memory!");
this->resetMemory(); this->resetMemory();
} }
} }

View File

@@ -157,6 +157,10 @@ void RtabmapThread::mainLoop()
_rtabmap->generateGraph(parameters.at("path"), atoi(parameters.at("id").c_str()), atoi(parameters.at("margin").c_str())); _rtabmap->generateGraph(parameters.at("path"), atoi(parameters.at("id").c_str()), atoi(parameters.at("margin").c_str()));
break; break;
case kStateDeletingMemory: case kStateDeletingMemory:
if(!parameters.at("path").empty())
{
_rtabmap->setDatabasePath(parameters.at("path"));
}
_rtabmap->resetMemory(true); _rtabmap->resetMemory(true);
this->clearBufferedData(); this->clearBufferedData();
break; break;
@@ -243,7 +247,9 @@ void RtabmapThread::handleEvent(UEvent* event)
else if(cmd == RtabmapEventCmd::kCmdDeleteMemory) else if(cmd == RtabmapEventCmd::kCmdDeleteMemory)
{ {
ULOGGER_DEBUG("CMD_DELETE_MEMORY"); ULOGGER_DEBUG("CMD_DELETE_MEMORY");
pushNewState(kStateDeletingMemory); ParametersMap param;
param.insert(ParametersPair("path", rtabmapEvent->getStr()));
pushNewState(kStateDeletingMemory, param);
} }
else if(cmd == RtabmapEventCmd::kCmdCleanDataBuffer) else if(cmd == RtabmapEventCmd::kCmdCleanDataBuffer)
{ {

View File

@@ -126,6 +126,7 @@ public:
int getScanPointSize(int index) const; // 0=map, 1=odom, 2=save int getScanPointSize(int index) const; // 0=map, 1=odom, 2=save
QString getWorkingDirectory() const; QString getWorkingDirectory() const;
QString getDatabasePath() const;
// source panel // source panel
double getGeneralInputRate() const; double getGeneralInputRate() const;

View File

@@ -831,15 +831,6 @@ void MainWindow::processStats(const rtabmap::Statistics & stat)
UDEBUG("time= %d ms", time.restart()); 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 // We use the reference image to resize the 2 views
_ui->imageView_source->resetZoom(); _ui->imageView_source->resetZoom();
_ui->imageView_loopClosure->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_source->fitInView(_ui->imageView_source->sceneRect(), Qt::KeepAspectRatio);
_ui->imageView_loopClosure->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()) if(_preferencesDialog->isImageFlipped())
{ {
_ui->imageView_source->scale(-1.0, 1.0); _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... // 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; int deltaY = 0;
if(_preferencesDialog->isVerticalLayoutUsed()) if(_preferencesDialog->isVerticalLayoutUsed())
{ {
deltaX = 0; deltaX = 0;
deltaY = _ui->imageView_source->sceneRect().height(); deltaY = _ui->imageView_source->height()/scaleY;
deltaY += _ui->label_matchId->height()/_ui->imageView_source->transform().m22(); deltaY += _ui->label_matchId->height()/scaleY;
} }
for(QList<QPair<KeypointItem*, KeypointItem*> >::iterator iter = uniqueCorrespondences.begin(); for(QList<QPair<KeypointItem*, KeypointItem*> >::iterator iter = uniqueCorrespondences.begin();
iter!=uniqueCorrespondences.end(); iter!=uniqueCorrespondences.end();
@@ -2147,7 +2151,7 @@ void MainWindow::generateLocalMap()
void MainWindow::deleteMemory() void MainWindow::deleteMemory()
{ {
QMessageBox::StandardButton button; QMessageBox::StandardButton button;
QString dbPath = _preferencesDialog->getWorkingDirectory() + QDir::separator() + "rtabmap.db"; QString dbPath = _preferencesDialog->getDatabasePath();
if(_state == kMonitoring || _state == kMonitoringPaused) if(_state == kMonitoring || _state == kMonitoringPaused)
{ {
button = QMessageBox::question(this, button = QMessageBox::question(this,
@@ -2170,7 +2174,7 @@ void MainWindow::deleteMemory()
return; return;
} }
this->post(new RtabmapEventCmd(RtabmapEventCmd::kCmdDeleteMemory)); this->post(new RtabmapEventCmd(RtabmapEventCmd::kCmdDeleteMemory, dbPath.toStdString()));
this->clearTheCache(); this->clearTheCache();
} }

View File

@@ -49,6 +49,8 @@
#include <rtabmap/utilite/UEventsManager.h> #include <rtabmap/utilite/UEventsManager.h>
#include "utilite/UPlot.h" #include "utilite/UPlot.h"
#include <opencv2/gpu/gpu.hpp>
using namespace rtabmap; using namespace rtabmap;
namespace rtabmap { namespace rtabmap {
@@ -115,6 +117,14 @@ PreferencesDialog::PreferencesDialog(QWidget * parent) :
_ui->label_space2->setEnabled(false); _ui->label_space2->setEnabled(false);
_ui->label_space3->setEnabled(false); _ui->label_space3->setEnabled(false);
_ui->loopClosure_icpType->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 #endif
_ui->predictionPlot->showLegend(false); _ui->predictionPlot->showLegend(false);
@@ -824,6 +834,11 @@ QString PreferencesDialog::getWorkingDirectory() const
return _ui->lineEdit_workingDirectory->text(); return _ui->lineEdit_workingDirectory->text();
} }
QString PreferencesDialog::getDatabasePath() const
{
return _ui->lineEdit_databasePath->text();
}
QString PreferencesDialog::getIniFilePath() const QString PreferencesDialog::getIniFilePath() const
{ {
#ifdef DEMO_BUILD #ifdef DEMO_BUILD

View File

@@ -64,8 +64,8 @@
<rect> <rect>
<x>0</x> <x>0</x>
<y>0</y> <y>0</y>
<width>939</width> <width>955</width>
<height>724</height> <height>685</height>
</rect> </rect>
</property> </property>
<layout class="QVBoxLayout" name="verticalLayout_16"> <layout class="QVBoxLayout" name="verticalLayout_16">
@@ -86,7 +86,7 @@
<enum>QFrame::Raised</enum> <enum>QFrame::Raised</enum>
</property> </property>
<property name="currentIndex"> <property name="currentIndex">
<number>1</number> <number>9</number>
</property> </property>
<widget class="QWidget" name="page_22"> <widget class="QWidget" name="page_22">
<layout class="QVBoxLayout" name="verticalLayout_29"> <layout class="QVBoxLayout" name="verticalLayout_29">
@@ -3048,7 +3048,7 @@ generate the number of words requested.</string>
<item row="5" column="0"> <item row="5" column="0">
<widget class="QCheckBox" name="surf_checkBox_gpuVersion"> <widget class="QCheckBox" name="surf_checkBox_gpuVersion">
<property name="enabled"> <property name="enabled">
<bool>false</bool> <bool>true</bool>
</property> </property>
<property name="text"> <property name="text">
<string/> <string/>
@@ -3056,12 +3056,12 @@ generate the number of words requested.</string>
</widget> </widget>
</item> </item>
<item row="5" column="1"> <item row="5" column="1">
<widget class="QLabel" name="label_48"> <widget class="QLabel" name="label_surf_checkBox_gpuVersion">
<property name="enabled"> <property name="enabled">
<bool>false</bool> <bool>true</bool>
</property> </property>
<property name="text"> <property name="text">
<string>GPU version (as well for descriptor). Experimental.</string> <string>GPU version (as well for descriptor).</string>
</property> </property>
<property name="wordWrap"> <property name="wordWrap">
<bool>true</bool> <bool>true</bool>