2011-10-25 15:48:19 +00:00
|
|
|
/*
|
2014-08-06 13:43:29 +00:00
|
|
|
Copyright (c) 2011-2014, Mathieu Labbe - IntRoLab - Universite de Sherbrooke
|
|
|
|
|
All rights reserved.
|
|
|
|
|
|
|
|
|
|
Redistribution and use in source and binary forms, with or without
|
|
|
|
|
modification, are permitted provided that the following conditions are met:
|
|
|
|
|
* Redistributions of source code must retain the above copyright
|
|
|
|
|
notice, this list of conditions and the following disclaimer.
|
|
|
|
|
* Redistributions in binary form must reproduce the above copyright
|
|
|
|
|
notice, this list of conditions and the following disclaimer in the
|
|
|
|
|
documentation and/or other materials provided with the distribution.
|
|
|
|
|
* Neither the name of the Universite de Sherbrooke nor the
|
|
|
|
|
names of its contributors may be used to endorse or promote products
|
|
|
|
|
derived from this software without specific prior written permission.
|
|
|
|
|
|
|
|
|
|
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
|
|
|
|
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
|
|
|
|
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
2014-08-11 15:49:53 +00:00
|
|
|
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY
|
2014-08-06 13:43:29 +00:00
|
|
|
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
|
|
|
|
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
|
|
|
|
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
|
|
|
|
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
|
|
|
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
|
|
|
|
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
|
*/
|
2011-10-25 15:48:19 +00:00
|
|
|
|
2014-07-31 20:11:46 +00:00
|
|
|
#include "find_object/Camera.h"
|
|
|
|
|
#include "find_object/Settings.h"
|
|
|
|
|
#include "find_object/utilite/ULogger.h"
|
|
|
|
|
|
2011-10-25 15:48:19 +00:00
|
|
|
#include <QtCore/QSettings>
|
|
|
|
|
#include <QtCore/QStringList>
|
2011-11-10 14:00:20 +00:00
|
|
|
#include <QtCore/QDir>
|
2011-10-25 15:48:19 +00:00
|
|
|
#include <stdio.h>
|
2014-04-11 19:24:59 +00:00
|
|
|
#include <opencv2/calib3d/calib3d.hpp>
|
2015-06-23 16:38:47 -04:00
|
|
|
#include <opencv2/opencv_modules.hpp>
|
|
|
|
|
|
|
|
|
|
#if CV_MAJOR_VERSION < 3
|
2014-06-19 21:52:04 +00:00
|
|
|
#include <opencv2/gpu/gpu.hpp>
|
2015-06-23 16:38:47 -04:00
|
|
|
#define CVCUDA cv::gpu
|
|
|
|
|
#else
|
|
|
|
|
#include <opencv2/core/cuda.hpp>
|
|
|
|
|
#define CVCUDA cv::cuda
|
|
|
|
|
#ifdef HAVE_OPENCV_CUDAFEATURES2D
|
|
|
|
|
#include <opencv2/cudafeatures2d.hpp>
|
|
|
|
|
#endif
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
#ifdef HAVE_OPENCV_NONFREE
|
|
|
|
|
#if CV_MAJOR_VERSION == 2 && CV_MINOR_VERSION >=4
|
|
|
|
|
#include <opencv2/nonfree/gpu.hpp>
|
|
|
|
|
#include <opencv2/nonfree/features2d.hpp>
|
|
|
|
|
#endif
|
|
|
|
|
#endif
|
|
|
|
|
#ifdef HAVE_OPENCV_XFEATURES2D
|
|
|
|
|
#include <opencv2/xfeatures2d.hpp>
|
|
|
|
|
#include <opencv2/xfeatures2d/cuda.hpp>
|
|
|
|
|
#endif
|
2011-10-25 15:48:19 +00:00
|
|
|
|
2014-08-06 13:43:29 +00:00
|
|
|
namespace find_object {
|
|
|
|
|
|
2011-10-25 15:48:19 +00:00
|
|
|
ParametersMap Settings::defaultParameters_;
|
|
|
|
|
ParametersMap Settings::parameters_;
|
|
|
|
|
ParametersType Settings::parametersType_;
|
2014-03-24 20:04:56 +00:00
|
|
|
DescriptionsMap Settings::descriptions_;
|
2011-10-25 15:48:19 +00:00
|
|
|
Settings Settings::dummyInit_;
|
2014-07-31 19:02:31 +00:00
|
|
|
QString Settings::iniPath_;
|
2011-11-10 14:00:20 +00:00
|
|
|
|
|
|
|
|
QString Settings::workingDirectory()
|
|
|
|
|
{
|
|
|
|
|
#ifdef WIN32
|
|
|
|
|
return QString("%1/Documents/%2").arg(QDir::homePath()).arg(PROJECT_NAME);
|
|
|
|
|
#else
|
|
|
|
|
return QString("%1").arg(QDir::homePath());
|
|
|
|
|
#endif
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QString Settings::iniDefaultPath()
|
|
|
|
|
{
|
|
|
|
|
#ifdef WIN32
|
|
|
|
|
return QString("%1/Documents/%2/%3").arg(QDir::homePath()).arg(PROJECT_NAME).arg(Settings::iniDefaultFileName());
|
|
|
|
|
#else
|
|
|
|
|
return QString("%1/.%2/%3").arg(QDir::homePath()).arg(PROJECT_PREFIX).arg(Settings::iniDefaultFileName());
|
|
|
|
|
#endif
|
|
|
|
|
}
|
2011-10-25 15:48:19 +00:00
|
|
|
|
2014-07-31 19:02:31 +00:00
|
|
|
QString Settings::iniPath()
|
|
|
|
|
{
|
|
|
|
|
if(!iniPath_.isNull())
|
|
|
|
|
{
|
|
|
|
|
return iniPath_;
|
|
|
|
|
}
|
|
|
|
|
return iniDefaultPath();
|
|
|
|
|
}
|
|
|
|
|
|
2018-08-31 11:53:34 -04:00
|
|
|
ParametersMap Settings::init(const QString & fileName)
|
2014-07-31 19:02:31 +00:00
|
|
|
{
|
|
|
|
|
iniPath_ = fileName;
|
2018-08-31 11:53:34 -04:00
|
|
|
return loadSettings(iniPath_);
|
2014-07-31 19:02:31 +00:00
|
|
|
}
|
|
|
|
|
|
2018-08-31 11:53:34 -04:00
|
|
|
ParametersMap Settings::loadSettings(const QString & fileName)
|
2011-10-25 15:48:19 +00:00
|
|
|
{
|
2018-08-31 11:53:34 -04:00
|
|
|
ParametersMap loadedParameters;
|
2011-11-10 14:00:20 +00:00
|
|
|
QString path = fileName;
|
|
|
|
|
if(fileName.isEmpty())
|
|
|
|
|
{
|
2014-07-31 19:02:31 +00:00
|
|
|
path = iniPath();
|
2011-11-10 14:00:20 +00:00
|
|
|
}
|
2014-08-28 17:54:29 +00:00
|
|
|
if(!path.isEmpty())
|
2011-10-25 15:48:19 +00:00
|
|
|
{
|
2014-08-28 17:54:29 +00:00
|
|
|
QSettings ini(path, QSettings::IniFormat);
|
|
|
|
|
for(ParametersMap::const_iterator iter = defaultParameters_.begin(); iter!=defaultParameters_.end(); ++iter)
|
2011-10-25 15:48:19 +00:00
|
|
|
{
|
2014-08-28 17:54:29 +00:00
|
|
|
const QString & key = iter.key();
|
|
|
|
|
QVariant value = ini.value(key, QVariant());
|
|
|
|
|
if(value.isValid())
|
2012-10-29 20:00:44 +00:00
|
|
|
{
|
2014-08-28 17:54:29 +00:00
|
|
|
QString str = value.toString();
|
2015-01-19 18:40:29 +00:00
|
|
|
if(str.contains(";"))
|
2014-08-28 17:54:29 +00:00
|
|
|
{
|
2015-01-19 18:40:29 +00:00
|
|
|
if(str.size() != getParameter(key).toString().size())
|
|
|
|
|
{
|
|
|
|
|
// If a string list is modified, update the value
|
|
|
|
|
// (assuming that index < 10... one character for index)
|
|
|
|
|
QChar index = str.at(0);
|
|
|
|
|
str = getParameter(key).toString();
|
2015-11-29 18:39:20 -05:00
|
|
|
str[0] = index.toLatin1();
|
2015-01-19 18:40:29 +00:00
|
|
|
value = QVariant(str);
|
|
|
|
|
UINFO("Updated list of parameter \"%s\"", key.toStdString().c_str());
|
|
|
|
|
}
|
2014-11-28 21:47:02 +00:00
|
|
|
#if FINDOBJECT_NONFREE == 0
|
2015-01-19 18:40:29 +00:00
|
|
|
QChar index = str.at(0);
|
|
|
|
|
if(key.compare(Settings::kFeature2D_1Detector()) == 0)
|
2014-11-28 21:47:02 +00:00
|
|
|
{
|
2015-01-19 18:40:29 +00:00
|
|
|
if(index == '5' || index == '7')
|
|
|
|
|
{
|
|
|
|
|
index = Settings::defaultFeature2D_1Detector().at(0);
|
|
|
|
|
int indexInt = Settings::defaultFeature2D_1Detector().split(':').first().toInt();
|
|
|
|
|
UWARN("Trying to set \"%s\" to SIFT/SURF but Find-Object isn't built "
|
|
|
|
|
"with the nonfree module from OpenCV. Keeping default combo value: %s.",
|
|
|
|
|
Settings::kFeature2D_1Detector().toStdString().c_str(),
|
|
|
|
|
Settings::defaultFeature2D_1Detector().split(':').last().split(";").at(indexInt).toStdString().c_str());
|
|
|
|
|
}
|
2014-11-28 21:47:02 +00:00
|
|
|
}
|
2015-01-19 18:40:29 +00:00
|
|
|
else if(key.compare(Settings::kFeature2D_2Descriptor()) == 0)
|
2014-11-28 21:47:02 +00:00
|
|
|
{
|
2015-01-19 18:40:29 +00:00
|
|
|
if(index == '2' || index == '3')
|
|
|
|
|
{
|
|
|
|
|
index = Settings::defaultFeature2D_2Descriptor().at(0);
|
|
|
|
|
int indexInt = Settings::defaultFeature2D_2Descriptor().split(':').first().toInt();
|
|
|
|
|
UWARN("Trying to set \"%s\" to SIFT/SURF but Find-Object isn't built "
|
|
|
|
|
"with the nonfree module from OpenCV. Keeping default combo value: %s.",
|
|
|
|
|
Settings::kFeature2D_2Descriptor().toStdString().c_str(),
|
|
|
|
|
Settings::defaultFeature2D_2Descriptor().split(':').last().split(";").at(indexInt).toStdString().c_str());
|
|
|
|
|
}
|
2014-11-28 21:47:02 +00:00
|
|
|
}
|
2015-01-19 18:40:29 +00:00
|
|
|
else if(key.compare(Settings::kNearestNeighbor_1Strategy()) == 0)
|
2014-11-28 21:47:02 +00:00
|
|
|
{
|
2015-01-19 18:40:29 +00:00
|
|
|
if(index <= '4')
|
|
|
|
|
{
|
|
|
|
|
index = Settings::defaultNearestNeighbor_1Strategy().at(0);
|
|
|
|
|
int indexInt = Settings::defaultNearestNeighbor_1Strategy().split(':').first().toInt();
|
|
|
|
|
UWARN("Trying to set \"%s\" to one FLANN approach but Find-Object isn't built "
|
|
|
|
|
"with the nonfree module from OpenCV and FLANN cannot be used "
|
|
|
|
|
"with binary descriptors. Keeping default combo value: %s.",
|
|
|
|
|
Settings::kNearestNeighbor_1Strategy().toStdString().c_str(),
|
|
|
|
|
Settings::defaultNearestNeighbor_1Strategy().split(':').last().split(";").at(indexInt).toStdString().c_str());
|
|
|
|
|
}
|
2014-11-28 21:47:02 +00:00
|
|
|
}
|
2015-01-19 18:40:29 +00:00
|
|
|
str = getParameter(key).toString();
|
2015-11-29 18:39:20 -05:00
|
|
|
str[0] = index.toLatin1();
|
2015-01-19 18:40:29 +00:00
|
|
|
value = QVariant(str);
|
2014-11-28 21:47:02 +00:00
|
|
|
#endif
|
2015-01-19 18:40:29 +00:00
|
|
|
}
|
2018-08-31 11:53:34 -04:00
|
|
|
loadedParameters.insert(key, value);
|
2014-08-28 17:54:29 +00:00
|
|
|
setParameter(key, value);
|
2012-10-29 20:00:44 +00:00
|
|
|
}
|
2011-10-25 15:48:19 +00:00
|
|
|
}
|
2014-08-28 17:54:29 +00:00
|
|
|
UINFO("Settings loaded from %s.", path.toStdString().c_str());
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
parameters_ = defaultParameters_;
|
|
|
|
|
UINFO("Settings set to defaults.");
|
2011-10-25 15:48:19 +00:00
|
|
|
}
|
|
|
|
|
|
2015-06-23 16:38:47 -04:00
|
|
|
if(CVCUDA::getCudaEnabledDeviceCount() == 0)
|
2011-10-25 15:48:19 +00:00
|
|
|
{
|
2014-11-28 21:47:02 +00:00
|
|
|
#if FINDOBJECT_NONFREE == 1
|
2014-07-31 19:02:31 +00:00
|
|
|
Settings::setFeature2D_SURF_gpu(false);
|
2014-10-24 02:46:03 +00:00
|
|
|
#endif
|
2014-07-31 19:02:31 +00:00
|
|
|
Settings::setFeature2D_Fast_gpu(false);
|
|
|
|
|
Settings::setFeature2D_ORB_gpu(false);
|
2014-10-24 02:46:03 +00:00
|
|
|
Settings::setNearestNeighbor_BruteForce_gpu(false);
|
2011-10-25 15:48:19 +00:00
|
|
|
}
|
2018-08-31 11:53:34 -04:00
|
|
|
return loadedParameters;
|
2014-07-31 19:02:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void Settings::loadWindowSettings(QByteArray & windowGeometry, QByteArray & windowState, const QString & fileName)
|
|
|
|
|
{
|
|
|
|
|
QString path = fileName;
|
|
|
|
|
if(fileName.isEmpty())
|
2012-08-28 13:44:57 +00:00
|
|
|
{
|
2014-07-31 19:02:31 +00:00
|
|
|
path = iniPath();
|
|
|
|
|
}
|
|
|
|
|
|
2014-08-28 17:54:29 +00:00
|
|
|
if(!path.isEmpty())
|
2014-07-31 19:02:31 +00:00
|
|
|
{
|
2014-08-28 17:54:29 +00:00
|
|
|
QSettings ini(path, QSettings::IniFormat);
|
2011-10-25 15:48:19 +00:00
|
|
|
|
2014-08-28 17:54:29 +00:00
|
|
|
QVariant value = ini.value("windowGeometry", QVariant());
|
|
|
|
|
if(value.isValid())
|
|
|
|
|
{
|
|
|
|
|
windowGeometry = value.toByteArray();
|
|
|
|
|
}
|
2014-07-31 19:02:31 +00:00
|
|
|
|
2014-08-28 17:54:29 +00:00
|
|
|
value = ini.value("windowState", QVariant());
|
|
|
|
|
if(value.isValid())
|
|
|
|
|
{
|
|
|
|
|
windowState = value.toByteArray();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
UINFO("Window settings loaded from %s", path.toStdString().c_str());
|
|
|
|
|
}
|
2011-10-25 15:48:19 +00:00
|
|
|
}
|
|
|
|
|
|
2014-07-31 19:02:31 +00:00
|
|
|
void Settings::saveSettings(const QString & fileName)
|
2011-10-25 15:48:19 +00:00
|
|
|
{
|
2011-11-10 14:00:20 +00:00
|
|
|
QString path = fileName;
|
|
|
|
|
if(fileName.isEmpty())
|
|
|
|
|
{
|
2014-07-31 19:02:31 +00:00
|
|
|
path = iniPath();
|
2011-11-10 14:00:20 +00:00
|
|
|
}
|
2014-08-28 17:54:29 +00:00
|
|
|
if(!path.isEmpty())
|
2011-10-25 15:48:19 +00:00
|
|
|
{
|
2014-08-28 17:54:29 +00:00
|
|
|
QSettings ini(path, QSettings::IniFormat);
|
|
|
|
|
for(ParametersMap::const_iterator iter = parameters_.begin(); iter!=parameters_.end(); ++iter)
|
2011-10-25 15:48:19 +00:00
|
|
|
{
|
2014-08-28 17:54:29 +00:00
|
|
|
QString type = Settings::getParametersType().value(iter.key());
|
|
|
|
|
if(type.compare("float") == 0)
|
|
|
|
|
{
|
|
|
|
|
ini.setValue(iter.key(), QString::number(iter.value().toFloat(),'g',6));
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
ini.setValue(iter.key(), iter.value());
|
|
|
|
|
}
|
2011-10-25 15:48:19 +00:00
|
|
|
}
|
2014-08-28 17:54:29 +00:00
|
|
|
UINFO("Settings saved to %s", path.toStdString().c_str());
|
2011-10-25 15:48:19 +00:00
|
|
|
}
|
2014-07-31 19:02:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void Settings::saveWindowSettings(const QByteArray & windowGeometry, const QByteArray & windowState, const QString & fileName)
|
|
|
|
|
{
|
|
|
|
|
QString path = fileName;
|
|
|
|
|
if(fileName.isEmpty())
|
|
|
|
|
{
|
|
|
|
|
path = iniPath();
|
|
|
|
|
}
|
2014-08-28 17:54:29 +00:00
|
|
|
if(!path.isEmpty())
|
2012-08-28 13:44:57 +00:00
|
|
|
{
|
2014-08-28 17:54:29 +00:00
|
|
|
QSettings ini(path, QSettings::IniFormat);
|
|
|
|
|
if(!windowGeometry.isEmpty())
|
|
|
|
|
{
|
|
|
|
|
ini.setValue("windowGeometry", windowGeometry);
|
|
|
|
|
}
|
|
|
|
|
if(!windowState.isEmpty())
|
|
|
|
|
{
|
|
|
|
|
ini.setValue("windowState", windowState);
|
|
|
|
|
}
|
|
|
|
|
UINFO("Window settings saved to %s", path.toStdString().c_str());
|
2012-08-28 13:44:57 +00:00
|
|
|
}
|
2011-10-25 15:48:19 +00:00
|
|
|
}
|
|
|
|
|
|
2014-11-28 21:47:02 +00:00
|
|
|
#if FINDOBJECT_NONFREE == 1
|
2015-07-10 14:27:11 -04:00
|
|
|
class GPUSURF : public Feature2D
|
2014-06-17 21:04:26 +00:00
|
|
|
{
|
|
|
|
|
public:
|
|
|
|
|
GPUSURF(double hessianThreshold,
|
2014-06-19 21:52:04 +00:00
|
|
|
int nOctaves,
|
|
|
|
|
int nOctaveLayers,
|
|
|
|
|
bool extended,
|
|
|
|
|
float keypointsRatio,
|
|
|
|
|
bool upright) :
|
|
|
|
|
surf_(hessianThreshold,
|
|
|
|
|
nOctaves,
|
|
|
|
|
nOctaveLayers,
|
|
|
|
|
extended,
|
|
|
|
|
keypointsRatio,
|
|
|
|
|
upright)
|
2014-06-17 21:04:26 +00:00
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
virtual ~GPUSURF() {}
|
|
|
|
|
|
2015-07-10 14:27:11 -04:00
|
|
|
virtual void detect(const cv::Mat & image,
|
2014-08-22 22:36:09 +00:00
|
|
|
std::vector<cv::KeyPoint> & keypoints,
|
|
|
|
|
const cv::Mat & mask = cv::Mat())
|
2014-06-17 21:04:26 +00:00
|
|
|
{
|
2015-06-23 16:38:47 -04:00
|
|
|
CVCUDA::GpuMat imgGpu(image);
|
|
|
|
|
CVCUDA::GpuMat maskGpu(mask);
|
2014-06-19 21:52:04 +00:00
|
|
|
try
|
|
|
|
|
{
|
2014-08-22 22:36:09 +00:00
|
|
|
surf_(imgGpu, maskGpu, keypoints);
|
2014-06-19 21:52:04 +00:00
|
|
|
}
|
|
|
|
|
catch(cv::Exception &e)
|
|
|
|
|
{
|
2014-07-31 19:02:31 +00:00
|
|
|
UERROR("GPUSURF error: %s \n(If something about layer_rows, parameter nOctaves=%d of SURF "
|
|
|
|
|
"is too high for the size of the image (%d,%d).)",
|
2014-06-19 21:52:04 +00:00
|
|
|
e.msg.c_str(),
|
|
|
|
|
surf_.nOctaves,
|
|
|
|
|
image.cols,
|
|
|
|
|
image.rows);
|
|
|
|
|
}
|
2014-06-17 21:04:26 +00:00
|
|
|
}
|
|
|
|
|
|
2015-07-10 14:27:11 -04:00
|
|
|
virtual void compute( const cv::Mat& image,
|
2014-06-19 21:52:04 +00:00
|
|
|
std::vector<cv::KeyPoint>& keypoints,
|
|
|
|
|
cv::Mat& descriptors)
|
2014-06-17 21:04:26 +00:00
|
|
|
{
|
|
|
|
|
std::vector<float> d;
|
2015-06-23 16:38:47 -04:00
|
|
|
CVCUDA::GpuMat imgGpu(image);
|
|
|
|
|
CVCUDA::GpuMat descriptorsGPU;
|
2014-06-19 21:52:04 +00:00
|
|
|
try
|
|
|
|
|
{
|
2015-06-23 16:38:47 -04:00
|
|
|
surf_(imgGpu, CVCUDA::GpuMat(), keypoints, descriptorsGPU, true);
|
2014-06-19 21:52:04 +00:00
|
|
|
}
|
|
|
|
|
catch(cv::Exception &e)
|
|
|
|
|
{
|
2014-07-31 19:02:31 +00:00
|
|
|
UERROR("GPUSURF error: %s \n(If something about layer_rows, parameter nOctaves=%d of SURF "
|
|
|
|
|
"is too high for the size of the image (%d,%d).)",
|
2014-06-19 21:52:04 +00:00
|
|
|
e.msg.c_str(),
|
|
|
|
|
surf_.nOctaves,
|
|
|
|
|
image.cols,
|
|
|
|
|
image.rows);
|
|
|
|
|
}
|
2014-06-19 18:55:46 +00:00
|
|
|
|
|
|
|
|
// Download descriptors
|
|
|
|
|
if (descriptorsGPU.empty())
|
|
|
|
|
descriptors = cv::Mat();
|
|
|
|
|
else
|
2014-06-17 21:04:26 +00:00
|
|
|
{
|
2015-01-05 23:11:15 +00:00
|
|
|
UASSERT(descriptorsGPU.type() == CV_32F);
|
2014-06-19 18:55:46 +00:00
|
|
|
descriptors = cv::Mat(descriptorsGPU.size(), CV_32F);
|
|
|
|
|
descriptorsGPU.download(descriptors);
|
2014-06-17 21:04:26 +00:00
|
|
|
}
|
|
|
|
|
}
|
2015-07-10 14:27:11 -04:00
|
|
|
|
|
|
|
|
virtual void detectAndCompute( const cv::Mat& image,
|
|
|
|
|
std::vector<cv::KeyPoint>& keypoints,
|
|
|
|
|
cv::Mat& descriptors,
|
|
|
|
|
const cv::Mat & mask = cv::Mat())
|
|
|
|
|
{
|
|
|
|
|
std::vector<float> d;
|
|
|
|
|
CVCUDA::GpuMat imgGpu(image);
|
|
|
|
|
CVCUDA::GpuMat descriptorsGPU;
|
|
|
|
|
CVCUDA::GpuMat maskGpu(mask);
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
surf_(imgGpu, maskGpu, keypoints, descriptorsGPU, false);
|
|
|
|
|
}
|
|
|
|
|
catch(cv::Exception &e)
|
|
|
|
|
{
|
|
|
|
|
UERROR("GPUSURF error: %s \n(If something about layer_rows, parameter nOctaves=%d of SURF "
|
|
|
|
|
"is too high for the size of the image (%d,%d).)",
|
|
|
|
|
e.msg.c_str(),
|
|
|
|
|
surf_.nOctaves,
|
|
|
|
|
image.cols,
|
|
|
|
|
image.rows);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Download descriptors
|
|
|
|
|
if (descriptorsGPU.empty())
|
|
|
|
|
descriptors = cv::Mat();
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
UASSERT(descriptorsGPU.type() == CV_32F);
|
|
|
|
|
descriptors = cv::Mat(descriptorsGPU.size(), CV_32F);
|
|
|
|
|
descriptorsGPU.download(descriptors);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2014-06-17 21:04:26 +00:00
|
|
|
private:
|
2015-06-23 16:38:47 -04:00
|
|
|
#if CV_MAJOR_VERSION < 3
|
|
|
|
|
CVCUDA::SURF_GPU surf_;
|
|
|
|
|
#else
|
|
|
|
|
CVCUDA::SURF_CUDA surf_;
|
|
|
|
|
#endif
|
2014-06-17 21:04:26 +00:00
|
|
|
};
|
2014-10-24 02:46:03 +00:00
|
|
|
#endif
|
2014-06-17 21:04:26 +00:00
|
|
|
|
2015-07-10 14:27:11 -04:00
|
|
|
class GPUFAST : public Feature2D
|
2014-06-19 18:55:46 +00:00
|
|
|
{
|
|
|
|
|
public:
|
|
|
|
|
GPUFAST(int threshold=Settings::defaultFeature2D_Fast_threshold(),
|
|
|
|
|
bool nonmaxSuppression=Settings::defaultFeature2D_Fast_nonmaxSuppression(),
|
2015-06-23 16:38:47 -04:00
|
|
|
#if CV_MAJOR_VERSION < 3
|
2015-07-10 14:27:11 -04:00
|
|
|
double keypointsRatio=Settings::defaultFeature2D_Fast_keypointsRatio())
|
2015-06-23 16:38:47 -04:00
|
|
|
: fast_(threshold,
|
2014-06-19 21:52:04 +00:00
|
|
|
nonmaxSuppression,
|
|
|
|
|
keypointsRatio)
|
2015-06-23 16:38:47 -04:00
|
|
|
#else
|
2015-07-10 14:27:11 -04:00
|
|
|
int max_npoints=Settings::defaultFeature2D_Fast_maxNpoints())
|
2015-06-23 16:38:47 -04:00
|
|
|
#ifdef HAVE_OPENCV_CUDAFEATURES2D
|
2015-07-10 14:27:11 -04:00
|
|
|
: fast_(CVCUDA::FastFeatureDetector::create(
|
|
|
|
|
threshold,
|
|
|
|
|
nonmaxSuppression,
|
|
|
|
|
CVCUDA::FastFeatureDetector::TYPE_9_16,
|
|
|
|
|
max_npoints))
|
2015-06-23 16:38:47 -04:00
|
|
|
#endif
|
|
|
|
|
#endif
|
2014-06-19 18:55:46 +00:00
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
virtual ~GPUFAST() {}
|
|
|
|
|
|
2015-07-10 14:27:11 -04:00
|
|
|
virtual void detect(const cv::Mat & image,
|
2014-08-22 22:36:09 +00:00
|
|
|
std::vector<cv::KeyPoint> & keypoints,
|
|
|
|
|
const cv::Mat & mask = cv::Mat())
|
2014-06-19 18:55:46 +00:00
|
|
|
{
|
2015-06-23 16:38:47 -04:00
|
|
|
CVCUDA::GpuMat imgGpu(image);
|
|
|
|
|
CVCUDA::GpuMat maskGpu(mask);
|
|
|
|
|
#if CV_MAJOR_VERSION < 3
|
2014-08-22 22:36:09 +00:00
|
|
|
fast_(imgGpu, maskGpu, keypoints);
|
2015-06-23 16:38:47 -04:00
|
|
|
#else
|
|
|
|
|
#ifdef HAVE_OPENCV_CUDAFEATURES2D
|
2015-07-10 14:27:11 -04:00
|
|
|
CVCUDA::GpuMat keypointsGpu(keypoints);
|
|
|
|
|
fast_->detectAsync(imgGpu, keypointsGpu, maskGpu);
|
|
|
|
|
fast_->convert(keypointsGpu, keypoints);
|
2015-06-23 16:38:47 -04:00
|
|
|
#endif
|
|
|
|
|
#endif
|
2014-06-19 18:55:46 +00:00
|
|
|
}
|
2015-07-10 14:27:11 -04:00
|
|
|
virtual void compute( const cv::Mat& image,
|
2014-06-19 21:52:04 +00:00
|
|
|
std::vector<cv::KeyPoint>& keypoints,
|
|
|
|
|
cv::Mat& descriptors)
|
|
|
|
|
{
|
2014-07-31 19:02:31 +00:00
|
|
|
UERROR("GPUFAST:computeDescriptors() Should not be used!");
|
2014-06-19 21:52:04 +00:00
|
|
|
}
|
2015-07-10 14:27:11 -04:00
|
|
|
virtual void detectAndCompute( const cv::Mat& image,
|
|
|
|
|
std::vector<cv::KeyPoint>& keypoints,
|
|
|
|
|
cv::Mat& descriptors,
|
|
|
|
|
const cv::Mat & mask = cv::Mat())
|
|
|
|
|
{
|
|
|
|
|
UERROR("GPUFAST:detectAndCompute() Should not be used!");
|
|
|
|
|
}
|
2014-06-19 18:55:46 +00:00
|
|
|
|
|
|
|
|
private:
|
2015-06-23 16:38:47 -04:00
|
|
|
#if CV_MAJOR_VERSION < 3
|
|
|
|
|
CVCUDA::FAST_GPU fast_;
|
|
|
|
|
#else
|
|
|
|
|
#ifdef HAVE_OPENCV_CUDAFEATURES2D
|
2015-07-10 14:27:11 -04:00
|
|
|
cv::Ptr<CVCUDA::FastFeatureDetector> fast_;
|
2015-06-23 16:38:47 -04:00
|
|
|
#endif
|
|
|
|
|
#endif
|
2014-06-19 18:55:46 +00:00
|
|
|
};
|
|
|
|
|
|
2015-07-10 14:27:11 -04:00
|
|
|
class GPUORB : public Feature2D
|
2014-06-19 18:55:46 +00:00
|
|
|
{
|
|
|
|
|
public:
|
|
|
|
|
GPUORB(int nFeatures = Settings::defaultFeature2D_ORB_nFeatures(),
|
|
|
|
|
float scaleFactor = Settings::defaultFeature2D_ORB_scaleFactor(),
|
|
|
|
|
int nLevels = Settings::defaultFeature2D_ORB_nLevels(),
|
|
|
|
|
int edgeThreshold = Settings::defaultFeature2D_ORB_edgeThreshold(),
|
|
|
|
|
int firstLevel = Settings::defaultFeature2D_ORB_firstLevel(),
|
|
|
|
|
int WTA_K = Settings::defaultFeature2D_ORB_WTA_K(),
|
|
|
|
|
int scoreType = Settings::defaultFeature2D_ORB_scoreType(),
|
|
|
|
|
int patchSize = Settings::defaultFeature2D_ORB_patchSize(),
|
|
|
|
|
int fastThreshold = Settings::defaultFeature2D_Fast_threshold(),
|
2015-06-23 16:38:47 -04:00
|
|
|
#if CV_MAJOR_VERSION < 3
|
2015-07-10 14:27:11 -04:00
|
|
|
bool fastNonmaxSupression = Settings::defaultFeature2D_Fast_nonmaxSuppression())
|
2015-06-23 16:38:47 -04:00
|
|
|
: orb_(nFeatures,
|
|
|
|
|
scaleFactor,
|
|
|
|
|
nLevels,
|
|
|
|
|
edgeThreshold ,
|
|
|
|
|
firstLevel,
|
|
|
|
|
WTA_K,
|
|
|
|
|
scoreType,
|
|
|
|
|
patchSize)
|
|
|
|
|
#else
|
2015-07-10 14:27:11 -04:00
|
|
|
bool blurForDescriptor = Settings::defaultFeature2D_ORB_blurForDescriptor())
|
2015-06-23 16:38:47 -04:00
|
|
|
#ifdef HAVE_OPENCV_CUDAFEATURES2D
|
2015-07-10 14:27:11 -04:00
|
|
|
: orb_(CVCUDA::ORB::create(nFeatures,
|
2014-06-19 21:52:04 +00:00
|
|
|
scaleFactor,
|
|
|
|
|
nLevels,
|
|
|
|
|
edgeThreshold ,
|
|
|
|
|
firstLevel,
|
|
|
|
|
WTA_K,
|
|
|
|
|
scoreType,
|
2015-07-10 14:27:11 -04:00
|
|
|
patchSize,
|
|
|
|
|
fastThreshold,
|
|
|
|
|
blurForDescriptor))
|
2015-06-23 16:38:47 -04:00
|
|
|
#endif
|
|
|
|
|
#endif
|
2014-06-19 18:55:46 +00:00
|
|
|
{
|
2015-06-23 16:38:47 -04:00
|
|
|
#if CV_MAJOR_VERSION < 3
|
2014-06-19 21:52:04 +00:00
|
|
|
orb_.setFastParams(fastThreshold, fastNonmaxSupression);
|
2015-06-23 16:38:47 -04:00
|
|
|
#endif
|
2014-06-19 18:55:46 +00:00
|
|
|
}
|
|
|
|
|
virtual ~GPUORB() {}
|
|
|
|
|
|
2015-07-10 14:27:11 -04:00
|
|
|
virtual void detect(const cv::Mat & image,
|
2014-08-22 22:36:09 +00:00
|
|
|
std::vector<cv::KeyPoint> & keypoints,
|
|
|
|
|
const cv::Mat & mask = cv::Mat())
|
2014-06-19 18:55:46 +00:00
|
|
|
{
|
2015-06-23 16:38:47 -04:00
|
|
|
|
|
|
|
|
CVCUDA::GpuMat imgGpu(image);
|
|
|
|
|
CVCUDA::GpuMat maskGpu(mask);
|
|
|
|
|
|
2014-06-19 21:52:04 +00:00
|
|
|
try
|
|
|
|
|
{
|
2015-06-23 16:38:47 -04:00
|
|
|
#if CV_MAJOR_VERSION < 3
|
2014-08-22 22:36:09 +00:00
|
|
|
orb_(imgGpu, maskGpu, keypoints);
|
2015-06-23 16:38:47 -04:00
|
|
|
#else
|
|
|
|
|
#ifdef HAVE_OPENCV_CUDAFEATURES2D
|
2015-07-10 14:27:11 -04:00
|
|
|
CVCUDA::GpuMat keypointsGpu;
|
|
|
|
|
orb_->detectAsync(imgGpu, keypointsGpu, maskGpu);
|
|
|
|
|
orb_->convert(keypointsGpu, keypoints);
|
2015-06-23 16:38:47 -04:00
|
|
|
#endif
|
|
|
|
|
#endif
|
2014-06-19 21:52:04 +00:00
|
|
|
}
|
|
|
|
|
catch(cv::Exception &e)
|
|
|
|
|
{
|
2014-07-31 19:02:31 +00:00
|
|
|
UERROR("GPUORB error: %s \n(If something about matrix size, the image/object may be too small (%d,%d).)",
|
2014-06-19 21:52:04 +00:00
|
|
|
e.msg.c_str(),
|
|
|
|
|
image.cols,
|
|
|
|
|
image.rows);
|
|
|
|
|
}
|
2014-06-19 18:55:46 +00:00
|
|
|
}
|
|
|
|
|
|
2015-07-10 14:27:11 -04:00
|
|
|
virtual void compute( const cv::Mat& image,
|
2014-06-19 21:52:04 +00:00
|
|
|
std::vector<cv::KeyPoint>& keypoints,
|
|
|
|
|
cv::Mat& descriptors)
|
2014-06-19 18:55:46 +00:00
|
|
|
{
|
|
|
|
|
std::vector<float> d;
|
2015-06-23 16:38:47 -04:00
|
|
|
|
|
|
|
|
CVCUDA::GpuMat imgGpu(image);
|
|
|
|
|
CVCUDA::GpuMat descriptorsGPU;
|
|
|
|
|
|
2014-06-19 21:52:04 +00:00
|
|
|
try
|
|
|
|
|
{
|
2015-06-23 16:38:47 -04:00
|
|
|
#if CV_MAJOR_VERSION < 3
|
|
|
|
|
orb_(imgGpu, CVCUDA::GpuMat(), keypoints, descriptorsGPU); // No option to use provided keypoints!?
|
|
|
|
|
#else
|
|
|
|
|
#ifdef HAVE_OPENCV_CUDAFEATURES2D
|
2015-07-10 14:27:11 -04:00
|
|
|
UERROR("OpenCV 3 ORB-GPU doesn't support extracting ORB descriptors from already extracted keypoints. "
|
|
|
|
|
"Use ORB as feature detector too or desactivate ORB-GPU.");
|
|
|
|
|
//orb_->computeAsync(imgGpu, keypoints, descriptorsGPU, true);
|
|
|
|
|
#endif
|
|
|
|
|
#endif
|
|
|
|
|
}
|
|
|
|
|
catch(cv::Exception &e)
|
|
|
|
|
{
|
|
|
|
|
UERROR("GPUORB error: %s \n(If something about matrix size, the image/object may be too small (%d,%d).)",
|
|
|
|
|
e.msg.c_str(),
|
|
|
|
|
image.cols,
|
|
|
|
|
image.rows);
|
|
|
|
|
}
|
|
|
|
|
// Download descriptors
|
|
|
|
|
if (descriptorsGPU.empty())
|
|
|
|
|
descriptors = cv::Mat();
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
UASSERT(descriptorsGPU.type() == CV_8U);
|
|
|
|
|
descriptors = cv::Mat(descriptorsGPU.size(), CV_8U);
|
|
|
|
|
descriptorsGPU.download(descriptors);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
virtual void detectAndCompute( const cv::Mat& image,
|
|
|
|
|
std::vector<cv::KeyPoint>& keypoints,
|
|
|
|
|
cv::Mat& descriptors,
|
|
|
|
|
const cv::Mat & mask = cv::Mat())
|
|
|
|
|
{
|
|
|
|
|
std::vector<float> d;
|
|
|
|
|
|
|
|
|
|
CVCUDA::GpuMat imgGpu(image);
|
|
|
|
|
CVCUDA::GpuMat descriptorsGPU;
|
|
|
|
|
CVCUDA::GpuMat maskGpu(mask);
|
|
|
|
|
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
#if CV_MAJOR_VERSION < 3
|
2015-06-23 16:38:47 -04:00
|
|
|
orb_(imgGpu, CVCUDA::GpuMat(), keypoints, descriptorsGPU); // No option to use provided keypoints!?
|
2015-07-10 14:27:11 -04:00
|
|
|
#else
|
|
|
|
|
#ifdef HAVE_OPENCV_CUDAFEATURES2D
|
|
|
|
|
CVCUDA::GpuMat keypointsGpu;
|
|
|
|
|
orb_->detectAndComputeAsync(imgGpu, maskGpu, keypointsGpu, descriptorsGPU, false);
|
|
|
|
|
orb_->convert(keypointsGpu, keypoints);
|
2015-06-23 16:38:47 -04:00
|
|
|
#endif
|
|
|
|
|
#endif
|
2014-06-19 21:52:04 +00:00
|
|
|
}
|
|
|
|
|
catch(cv::Exception &e)
|
|
|
|
|
{
|
2014-07-31 19:02:31 +00:00
|
|
|
UERROR("GPUORB error: %s \n(If something about matrix size, the image/object may be too small (%d,%d).)",
|
2014-06-19 21:52:04 +00:00
|
|
|
e.msg.c_str(),
|
|
|
|
|
image.cols,
|
|
|
|
|
image.rows);
|
|
|
|
|
}
|
2014-06-19 18:55:46 +00:00
|
|
|
// Download descriptors
|
|
|
|
|
if (descriptorsGPU.empty())
|
|
|
|
|
descriptors = cv::Mat();
|
|
|
|
|
else
|
|
|
|
|
{
|
2015-01-05 23:11:15 +00:00
|
|
|
UASSERT(descriptorsGPU.type() == CV_8U);
|
2014-06-19 18:55:46 +00:00
|
|
|
descriptors = cv::Mat(descriptorsGPU.size(), CV_8U);
|
|
|
|
|
descriptorsGPU.download(descriptors);
|
|
|
|
|
}
|
|
|
|
|
}
|
2015-07-10 14:27:11 -04:00
|
|
|
|
2014-06-19 18:55:46 +00:00
|
|
|
private:
|
2015-06-23 16:38:47 -04:00
|
|
|
#if CV_MAJOR_VERSION < 3
|
|
|
|
|
CVCUDA::ORB_GPU orb_;
|
|
|
|
|
#else
|
|
|
|
|
#ifdef HAVE_OPENCV_CUDAFEATURES2D
|
2015-07-10 14:27:11 -04:00
|
|
|
cv::Ptr<CVCUDA::ORB> orb_;
|
2015-06-23 16:38:47 -04:00
|
|
|
#endif
|
|
|
|
|
#endif
|
2014-06-19 18:55:46 +00:00
|
|
|
};
|
|
|
|
|
|
2015-07-10 14:27:11 -04:00
|
|
|
Feature2D * Settings::createKeypointDetector()
|
2011-10-25 15:48:19 +00:00
|
|
|
{
|
2015-07-10 14:27:11 -04:00
|
|
|
Feature2D * feature2D = 0;
|
2012-10-29 20:00:44 +00:00
|
|
|
QString str = getFeature2D_1Detector();
|
2011-10-25 15:48:19 +00:00
|
|
|
QStringList split = str.split(':');
|
|
|
|
|
if(split.size()==2)
|
|
|
|
|
{
|
|
|
|
|
bool ok = false;
|
|
|
|
|
int index = split.first().toInt(&ok);
|
|
|
|
|
if(ok)
|
|
|
|
|
{
|
|
|
|
|
QStringList strategies = split.last().split(';');
|
2014-11-28 21:47:02 +00:00
|
|
|
|
2015-06-23 16:38:47 -04:00
|
|
|
if(index>=0 && index<strategies.size())
|
2011-10-25 15:48:19 +00:00
|
|
|
{
|
2014-11-28 21:47:02 +00:00
|
|
|
|
|
|
|
|
#if FINDOBJECT_NONFREE == 0
|
|
|
|
|
//check for nonfree stuff
|
|
|
|
|
if(strategies.at(index).compare("SIFT") == 0 ||
|
|
|
|
|
strategies.at(index).compare("SURF") == 0)
|
|
|
|
|
{
|
|
|
|
|
index = Settings::defaultFeature2D_1Detector().split(':').first().toInt();
|
|
|
|
|
UERROR("Find-Object is not built with OpenCV nonfree module so "
|
|
|
|
|
"SIFT/SURF cannot be used! Using default \"%s\" instead.",
|
|
|
|
|
strategies.at(index).toStdString().c_str());
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
#endif
|
|
|
|
|
|
2015-08-07 23:29:52 -04:00
|
|
|
#if CV_MAJOR_VERSION < 3
|
|
|
|
|
if(strategies.at(index).compare("AGAST") == 0 ||
|
|
|
|
|
strategies.at(index).compare("KAZE") == 0 ||
|
|
|
|
|
strategies.at(index).compare("AKAZE") == 0)
|
|
|
|
|
{
|
|
|
|
|
index = Settings::defaultFeature2D_1Detector().split(':').first().toInt();
|
|
|
|
|
UERROR("Find-Object is built with OpenCV 2 so "
|
|
|
|
|
"AGAST/KAZE/AKAZE cannot be used! Using default \"%s\" instead.",
|
|
|
|
|
strategies.at(index).toStdString().c_str());
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
#else
|
|
|
|
|
if(strategies.at(index).compare("Dense") == 0)
|
|
|
|
|
{
|
|
|
|
|
index = Settings::defaultFeature2D_1Detector().split(':').first().toInt();
|
|
|
|
|
UERROR("Find-Object is built with OpenCV 3 so "
|
|
|
|
|
"Dense cannot be used! Using default \"%s\" instead.",
|
|
|
|
|
strategies.at(index).toStdString().c_str());
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
#ifndef HAVE_OPENCV_XFEATURES2D
|
|
|
|
|
if(strategies.at(index).compare("Star") == 0)
|
|
|
|
|
{
|
|
|
|
|
index = Settings::defaultFeature2D_1Detector().split(':').first().toInt();
|
|
|
|
|
UERROR("Find-Object is not built with OpenCV xfeatures2d module so "
|
|
|
|
|
"Star cannot be used! Using default \"%s\" instead.",
|
|
|
|
|
strategies.at(index).toStdString().c_str());
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
#endif
|
|
|
|
|
#endif
|
|
|
|
|
|
2014-10-24 02:46:03 +00:00
|
|
|
if(strategies.at(index).compare("Dense") == 0)
|
2011-10-25 15:48:19 +00:00
|
|
|
{
|
2015-06-23 16:38:47 -04:00
|
|
|
#if CV_MAJOR_VERSION < 3
|
2015-07-10 14:27:11 -04:00
|
|
|
feature2D = new Feature2D(cv::Ptr<cv::FeatureDetector>(new cv::DenseFeatureDetector(
|
2015-06-23 16:38:47 -04:00
|
|
|
getFeature2D_Dense_initFeatureScale(),
|
|
|
|
|
getFeature2D_Dense_featureScaleLevels(),
|
|
|
|
|
getFeature2D_Dense_featureScaleMul(),
|
|
|
|
|
getFeature2D_Dense_initXyStep(),
|
|
|
|
|
getFeature2D_Dense_initImgBound(),
|
|
|
|
|
getFeature2D_Dense_varyXyStepWithScale(),
|
2015-07-10 14:27:11 -04:00
|
|
|
getFeature2D_Dense_varyImgBoundWithScale())));
|
2015-06-23 16:38:47 -04:00
|
|
|
#else
|
|
|
|
|
UWARN("Find-Object is not built with OpenCV 2 so Dense cannot be used!");
|
|
|
|
|
#endif
|
2014-10-24 02:46:03 +00:00
|
|
|
UDEBUG("type=%s", strategies.at(index).toStdString().c_str());
|
|
|
|
|
}
|
|
|
|
|
else if(strategies.at(index).compare("Fast") == 0)
|
|
|
|
|
{
|
2015-06-23 16:38:47 -04:00
|
|
|
if(getFeature2D_Fast_gpu() && CVCUDA::getCudaEnabledDeviceCount())
|
2011-10-25 15:48:19 +00:00
|
|
|
{
|
2015-07-10 14:27:11 -04:00
|
|
|
feature2D = new GPUFAST(
|
2014-10-24 02:46:03 +00:00
|
|
|
getFeature2D_Fast_threshold(),
|
|
|
|
|
getFeature2D_Fast_nonmaxSuppression());
|
|
|
|
|
UDEBUG("type=%s GPU", strategies.at(index).toStdString().c_str());
|
2011-10-25 15:48:19 +00:00
|
|
|
}
|
2014-10-24 02:46:03 +00:00
|
|
|
else
|
2011-10-25 15:48:19 +00:00
|
|
|
{
|
2015-06-23 16:38:47 -04:00
|
|
|
#if CV_MAJOR_VERSION < 3
|
2015-07-10 14:27:11 -04:00
|
|
|
feature2D = new Feature2D(cv::Ptr<cv::FeatureDetector>(new cv::FastFeatureDetector(
|
2015-06-23 16:38:47 -04:00
|
|
|
getFeature2D_Fast_threshold(),
|
2015-07-10 14:27:11 -04:00
|
|
|
getFeature2D_Fast_nonmaxSuppression())));
|
2015-06-23 16:38:47 -04:00
|
|
|
#else
|
2015-07-10 14:27:11 -04:00
|
|
|
feature2D = new Feature2D(cv::FastFeatureDetector::create(
|
2014-10-24 02:46:03 +00:00
|
|
|
getFeature2D_Fast_threshold(),
|
2015-07-10 14:27:11 -04:00
|
|
|
getFeature2D_Fast_nonmaxSuppression()));
|
2015-06-23 16:38:47 -04:00
|
|
|
#endif
|
2014-08-22 22:36:09 +00:00
|
|
|
UDEBUG("type=%s", strategies.at(index).toStdString().c_str());
|
2011-10-25 15:48:19 +00:00
|
|
|
}
|
2014-10-24 02:46:03 +00:00
|
|
|
}
|
2015-06-23 16:38:47 -04:00
|
|
|
else if(strategies.at(index).compare("AGAST") == 0)
|
|
|
|
|
{
|
|
|
|
|
#if CV_MAJOR_VERSION < 3
|
|
|
|
|
UWARN("Find-Object is not built with OpenCV 3 so AGAST cannot be used!");
|
|
|
|
|
#else
|
2015-07-10 14:27:11 -04:00
|
|
|
feature2D = new Feature2D(cv::AgastFeatureDetector::create(
|
2015-06-23 16:38:47 -04:00
|
|
|
getFeature2D_AGAST_threshold(),
|
2015-07-10 14:27:11 -04:00
|
|
|
getFeature2D_AGAST_nonmaxSuppression()));
|
2015-06-23 16:38:47 -04:00
|
|
|
#endif
|
|
|
|
|
UDEBUG("type=%s", strategies.at(index).toStdString().c_str());
|
|
|
|
|
}
|
2014-10-24 02:46:03 +00:00
|
|
|
else if(strategies.at(index).compare("GFTT") == 0)
|
|
|
|
|
{
|
2015-06-23 16:38:47 -04:00
|
|
|
#if CV_MAJOR_VERSION < 3
|
2015-07-10 14:27:11 -04:00
|
|
|
feature2D = new Feature2D(cv::Ptr<cv::FeatureDetector>(new cv::GFTTDetector(
|
2015-06-23 16:38:47 -04:00
|
|
|
getFeature2D_GFTT_maxCorners(),
|
|
|
|
|
getFeature2D_GFTT_qualityLevel(),
|
|
|
|
|
getFeature2D_GFTT_minDistance(),
|
|
|
|
|
getFeature2D_GFTT_blockSize(),
|
|
|
|
|
getFeature2D_GFTT_useHarrisDetector(),
|
2015-07-10 14:27:11 -04:00
|
|
|
getFeature2D_GFTT_k())));
|
2015-06-23 16:38:47 -04:00
|
|
|
#else
|
2015-07-10 14:27:11 -04:00
|
|
|
feature2D = new Feature2D(cv::GFTTDetector::create(
|
2014-10-24 02:46:03 +00:00
|
|
|
getFeature2D_GFTT_maxCorners(),
|
|
|
|
|
getFeature2D_GFTT_qualityLevel(),
|
|
|
|
|
getFeature2D_GFTT_minDistance(),
|
|
|
|
|
getFeature2D_GFTT_blockSize(),
|
|
|
|
|
getFeature2D_GFTT_useHarrisDetector(),
|
2015-07-10 14:27:11 -04:00
|
|
|
getFeature2D_GFTT_k()));
|
2015-06-23 16:38:47 -04:00
|
|
|
#endif
|
2014-10-24 02:46:03 +00:00
|
|
|
UDEBUG("type=%s", strategies.at(index).toStdString().c_str());
|
|
|
|
|
}
|
|
|
|
|
else if(strategies.at(index).compare("MSER") == 0)
|
|
|
|
|
{
|
2015-06-23 16:38:47 -04:00
|
|
|
#if CV_MAJOR_VERSION < 3
|
2015-07-10 14:27:11 -04:00
|
|
|
feature2D = new Feature2D(cv::Ptr<cv::FeatureDetector>(new cv::MSER(
|
2015-06-23 16:38:47 -04:00
|
|
|
getFeature2D_MSER_delta(),
|
|
|
|
|
getFeature2D_MSER_minArea(),
|
|
|
|
|
getFeature2D_MSER_maxArea(),
|
|
|
|
|
getFeature2D_MSER_maxVariation(),
|
|
|
|
|
getFeature2D_MSER_minDiversity(),
|
|
|
|
|
getFeature2D_MSER_maxEvolution(),
|
|
|
|
|
getFeature2D_MSER_areaThreshold(),
|
|
|
|
|
getFeature2D_MSER_minMargin(),
|
2015-07-10 14:27:11 -04:00
|
|
|
getFeature2D_MSER_edgeBlurSize())));
|
2015-06-23 16:38:47 -04:00
|
|
|
#else
|
2015-07-10 14:27:11 -04:00
|
|
|
feature2D = new Feature2D(cv::MSER::create(
|
2014-10-24 02:46:03 +00:00
|
|
|
getFeature2D_MSER_delta(),
|
|
|
|
|
getFeature2D_MSER_minArea(),
|
|
|
|
|
getFeature2D_MSER_maxArea(),
|
|
|
|
|
getFeature2D_MSER_maxVariation(),
|
|
|
|
|
getFeature2D_MSER_minDiversity(),
|
|
|
|
|
getFeature2D_MSER_maxEvolution(),
|
|
|
|
|
getFeature2D_MSER_areaThreshold(),
|
|
|
|
|
getFeature2D_MSER_minMargin(),
|
2015-07-10 14:27:11 -04:00
|
|
|
getFeature2D_MSER_edgeBlurSize()));
|
2015-06-23 16:38:47 -04:00
|
|
|
#endif
|
2014-10-24 02:46:03 +00:00
|
|
|
UDEBUG("type=%s", strategies.at(index).toStdString().c_str());
|
|
|
|
|
}
|
|
|
|
|
else if(strategies.at(index).compare("ORB") == 0)
|
|
|
|
|
{
|
2015-06-23 16:38:47 -04:00
|
|
|
if(getFeature2D_ORB_gpu() && CVCUDA::getCudaEnabledDeviceCount())
|
2011-10-25 15:48:19 +00:00
|
|
|
{
|
2015-07-10 14:27:11 -04:00
|
|
|
feature2D = new GPUORB(
|
2014-10-24 02:46:03 +00:00
|
|
|
getFeature2D_ORB_nFeatures(),
|
|
|
|
|
getFeature2D_ORB_scaleFactor(),
|
|
|
|
|
getFeature2D_ORB_nLevels(),
|
|
|
|
|
getFeature2D_ORB_edgeThreshold(),
|
|
|
|
|
getFeature2D_ORB_firstLevel(),
|
|
|
|
|
getFeature2D_ORB_WTA_K(),
|
|
|
|
|
getFeature2D_ORB_scoreType(),
|
|
|
|
|
getFeature2D_ORB_patchSize(),
|
|
|
|
|
getFeature2D_Fast_threshold(),
|
2015-07-10 14:27:11 -04:00
|
|
|
#if CV_MAJOR_VERSION < 3
|
2014-10-24 02:46:03 +00:00
|
|
|
getFeature2D_Fast_nonmaxSuppression());
|
2015-07-10 14:27:11 -04:00
|
|
|
#else
|
|
|
|
|
getFeature2D_ORB_blurForDescriptor());
|
|
|
|
|
#endif
|
2014-10-24 02:46:03 +00:00
|
|
|
UDEBUG("type=%s (GPU)", strategies.at(index).toStdString().c_str());
|
2011-10-25 15:48:19 +00:00
|
|
|
}
|
2014-10-24 02:46:03 +00:00
|
|
|
else
|
2011-10-25 15:48:19 +00:00
|
|
|
{
|
2015-06-23 16:38:47 -04:00
|
|
|
#if CV_MAJOR_VERSION < 3
|
2015-07-10 14:27:11 -04:00
|
|
|
feature2D = new Feature2D(cv::Ptr<cv::Feature2D>(new cv::ORB(
|
2015-06-23 16:38:47 -04:00
|
|
|
getFeature2D_ORB_nFeatures(),
|
|
|
|
|
getFeature2D_ORB_scaleFactor(),
|
|
|
|
|
getFeature2D_ORB_nLevels(),
|
|
|
|
|
getFeature2D_ORB_edgeThreshold(),
|
|
|
|
|
getFeature2D_ORB_firstLevel(),
|
|
|
|
|
getFeature2D_ORB_WTA_K(),
|
|
|
|
|
getFeature2D_ORB_scoreType(),
|
2015-07-10 14:27:11 -04:00
|
|
|
getFeature2D_ORB_patchSize())));
|
2015-06-23 16:38:47 -04:00
|
|
|
#else
|
2015-07-10 14:27:11 -04:00
|
|
|
feature2D = new Feature2D(cv::ORB::create(
|
2014-10-24 02:46:03 +00:00
|
|
|
getFeature2D_ORB_nFeatures(),
|
|
|
|
|
getFeature2D_ORB_scaleFactor(),
|
|
|
|
|
getFeature2D_ORB_nLevels(),
|
|
|
|
|
getFeature2D_ORB_edgeThreshold(),
|
|
|
|
|
getFeature2D_ORB_firstLevel(),
|
|
|
|
|
getFeature2D_ORB_WTA_K(),
|
|
|
|
|
getFeature2D_ORB_scoreType(),
|
2015-07-10 14:27:11 -04:00
|
|
|
getFeature2D_ORB_patchSize(),
|
|
|
|
|
getFeature2D_Fast_threshold()));
|
2015-06-23 16:38:47 -04:00
|
|
|
#endif
|
2014-08-22 22:36:09 +00:00
|
|
|
UDEBUG("type=%s", strategies.at(index).toStdString().c_str());
|
2011-10-25 15:48:19 +00:00
|
|
|
}
|
2014-10-24 02:46:03 +00:00
|
|
|
}
|
|
|
|
|
else if(strategies.at(index).compare("Star") == 0)
|
|
|
|
|
{
|
2015-06-23 16:38:47 -04:00
|
|
|
#if CV_MAJOR_VERSION < 3
|
2015-07-10 14:27:11 -04:00
|
|
|
feature2D = new Feature2D(cv::Ptr<cv::FeatureDetector>(new cv::StarFeatureDetector(
|
2015-06-23 16:38:47 -04:00
|
|
|
getFeature2D_Star_maxSize(),
|
|
|
|
|
getFeature2D_Star_responseThreshold(),
|
|
|
|
|
getFeature2D_Star_lineThresholdProjected(),
|
|
|
|
|
getFeature2D_Star_lineThresholdBinarized(),
|
2015-07-10 14:27:11 -04:00
|
|
|
getFeature2D_Star_suppressNonmaxSize())));
|
2015-06-23 16:38:47 -04:00
|
|
|
#else
|
|
|
|
|
#ifdef HAVE_OPENCV_XFEATURES2D
|
2015-07-10 14:27:11 -04:00
|
|
|
feature2D = new Feature2D(cv::xfeatures2d::StarDetector::create(
|
2015-06-23 16:38:47 -04:00
|
|
|
getFeature2D_Star_maxSize(),
|
|
|
|
|
getFeature2D_Star_responseThreshold(),
|
|
|
|
|
getFeature2D_Star_lineThresholdProjected(),
|
|
|
|
|
getFeature2D_Star_lineThresholdBinarized(),
|
2015-07-10 14:27:11 -04:00
|
|
|
getFeature2D_Star_suppressNonmaxSize()));
|
2015-06-23 16:38:47 -04:00
|
|
|
#else
|
|
|
|
|
UWARN("Find-Object is not built with OpenCV xfeatures2d module so Star cannot be used!");
|
|
|
|
|
#endif
|
|
|
|
|
#endif
|
2014-10-24 02:46:03 +00:00
|
|
|
UDEBUG("type=%s", strategies.at(index).toStdString().c_str());
|
|
|
|
|
}
|
|
|
|
|
else if(strategies.at(index).compare("BRISK") == 0)
|
|
|
|
|
{
|
2015-06-23 16:38:47 -04:00
|
|
|
#if CV_MAJOR_VERSION < 3
|
2015-07-10 14:27:11 -04:00
|
|
|
feature2D = new Feature2D(cv::Ptr<cv::Feature2D>(new cv::BRISK(
|
2015-06-23 16:38:47 -04:00
|
|
|
getFeature2D_BRISK_thresh(),
|
|
|
|
|
getFeature2D_BRISK_octaves(),
|
2015-07-10 14:27:11 -04:00
|
|
|
getFeature2D_BRISK_patternScale())));
|
2015-06-23 16:38:47 -04:00
|
|
|
#else
|
2015-07-10 14:27:11 -04:00
|
|
|
feature2D = new Feature2D(cv::BRISK::create(
|
2014-10-24 02:46:03 +00:00
|
|
|
getFeature2D_BRISK_thresh(),
|
|
|
|
|
getFeature2D_BRISK_octaves(),
|
2015-07-10 14:27:11 -04:00
|
|
|
getFeature2D_BRISK_patternScale()));
|
2015-06-23 16:38:47 -04:00
|
|
|
#endif
|
|
|
|
|
UDEBUG("type=%s", strategies.at(index).toStdString().c_str());
|
|
|
|
|
}
|
|
|
|
|
else if(strategies.at(index).compare("KAZE") == 0)
|
|
|
|
|
{
|
|
|
|
|
#if CV_MAJOR_VERSION < 3
|
|
|
|
|
UWARN("Find-Object is not built with OpenCV 3 so KAZE cannot be used!");
|
|
|
|
|
#else
|
2015-07-10 14:27:11 -04:00
|
|
|
feature2D = new Feature2D(cv::KAZE::create(
|
2015-06-23 16:38:47 -04:00
|
|
|
getFeature2D_KAZE_extended(),
|
|
|
|
|
getFeature2D_KAZE_upright(),
|
|
|
|
|
getFeature2D_KAZE_threshold(),
|
|
|
|
|
getFeature2D_KAZE_nOctaves(),
|
|
|
|
|
getFeature2D_KAZE_nOctaveLayers(),
|
2015-07-10 14:27:11 -04:00
|
|
|
cv::KAZE::DIFF_PM_G2)); // FIXME: make a parameter
|
2015-06-23 16:38:47 -04:00
|
|
|
#endif
|
|
|
|
|
UDEBUG("type=%s", strategies.at(index).toStdString().c_str());
|
|
|
|
|
}
|
|
|
|
|
else if(strategies.at(index).compare("AKAZE") == 0)
|
|
|
|
|
{
|
|
|
|
|
#if CV_MAJOR_VERSION < 3
|
|
|
|
|
UWARN("Find-Object is not built with OpenCV 3 so AKAZE cannot be used!");
|
|
|
|
|
#else
|
2015-07-10 14:27:11 -04:00
|
|
|
feature2D = new Feature2D(cv::AKAZE::create(
|
2015-06-23 16:38:47 -04:00
|
|
|
cv::AKAZE::DESCRIPTOR_MLDB, // FIXME: make a parameter
|
|
|
|
|
getFeature2D_AKAZE_descriptorSize(),
|
|
|
|
|
getFeature2D_AKAZE_descriptorChannels(),
|
|
|
|
|
getFeature2D_AKAZE_threshold(),
|
|
|
|
|
getFeature2D_AKAZE_nOctaves(),
|
|
|
|
|
getFeature2D_AKAZE_nOctaveLayers(),
|
2015-07-10 14:27:11 -04:00
|
|
|
cv::KAZE::DIFF_PM_G2)); // FIXME: make a parameter
|
2015-06-23 16:38:47 -04:00
|
|
|
#endif
|
2014-10-24 02:46:03 +00:00
|
|
|
UDEBUG("type=%s", strategies.at(index).toStdString().c_str());
|
|
|
|
|
}
|
2014-11-28 21:47:02 +00:00
|
|
|
#if FINDOBJECT_NONFREE == 1
|
2014-10-24 02:46:03 +00:00
|
|
|
else if(strategies.at(index).compare("SIFT") == 0)
|
|
|
|
|
{
|
2015-06-23 16:38:47 -04:00
|
|
|
#if CV_MAJOR_VERSION < 3
|
2015-07-10 14:27:11 -04:00
|
|
|
feature2D = new Feature2D(cv::Ptr<cv::Feature2D>(new cv::SIFT(
|
2015-06-23 16:38:47 -04:00
|
|
|
getFeature2D_SIFT_nfeatures(),
|
|
|
|
|
getFeature2D_SIFT_nOctaveLayers(),
|
|
|
|
|
getFeature2D_SIFT_contrastThreshold(),
|
|
|
|
|
getFeature2D_SIFT_edgeThreshold(),
|
2015-07-10 14:27:11 -04:00
|
|
|
getFeature2D_SIFT_sigma())));
|
2015-06-23 16:38:47 -04:00
|
|
|
#else
|
2015-07-10 14:27:11 -04:00
|
|
|
feature2D = new Feature2D(cv::xfeatures2d::SIFT::create(
|
2014-10-24 02:46:03 +00:00
|
|
|
getFeature2D_SIFT_nfeatures(),
|
|
|
|
|
getFeature2D_SIFT_nOctaveLayers(),
|
|
|
|
|
getFeature2D_SIFT_contrastThreshold(),
|
|
|
|
|
getFeature2D_SIFT_edgeThreshold(),
|
2015-07-10 14:27:11 -04:00
|
|
|
getFeature2D_SIFT_sigma()));
|
2015-06-23 16:38:47 -04:00
|
|
|
#endif
|
2014-10-24 02:46:03 +00:00
|
|
|
UDEBUG("type=%s", strategies.at(index).toStdString().c_str());
|
|
|
|
|
}
|
|
|
|
|
else if(strategies.at(index).compare("SURF") == 0)
|
|
|
|
|
{
|
2015-06-23 16:38:47 -04:00
|
|
|
if(getFeature2D_SURF_gpu() && CVCUDA::getCudaEnabledDeviceCount())
|
2011-10-25 15:48:19 +00:00
|
|
|
{
|
2015-07-10 14:27:11 -04:00
|
|
|
feature2D = new GPUSURF(
|
2012-10-29 20:00:44 +00:00
|
|
|
getFeature2D_SURF_hessianThreshold(),
|
|
|
|
|
getFeature2D_SURF_nOctaves(),
|
|
|
|
|
getFeature2D_SURF_nOctaveLayers(),
|
|
|
|
|
getFeature2D_SURF_extended(),
|
2014-10-24 02:46:03 +00:00
|
|
|
getFeature2D_SURF_keypointsRatio(),
|
2012-10-29 20:00:44 +00:00
|
|
|
getFeature2D_SURF_upright());
|
2014-10-24 02:46:03 +00:00
|
|
|
UDEBUG("type=%s (GPU)", strategies.at(index).toStdString().c_str());
|
2011-10-25 15:48:19 +00:00
|
|
|
}
|
2014-10-24 02:46:03 +00:00
|
|
|
else
|
2012-10-29 20:00:44 +00:00
|
|
|
{
|
2015-06-23 16:38:47 -04:00
|
|
|
#if CV_MAJOR_VERSION < 3
|
2015-07-10 14:27:11 -04:00
|
|
|
feature2D = new Feature2D(cv::Ptr<cv::Feature2D>(new cv::SURF(
|
2015-06-23 16:38:47 -04:00
|
|
|
getFeature2D_SURF_hessianThreshold(),
|
|
|
|
|
getFeature2D_SURF_nOctaves(),
|
|
|
|
|
getFeature2D_SURF_nOctaveLayers(),
|
|
|
|
|
getFeature2D_SURF_extended(),
|
2015-07-10 14:27:11 -04:00
|
|
|
getFeature2D_SURF_upright())));
|
2015-06-23 16:38:47 -04:00
|
|
|
#else
|
2015-07-10 14:27:11 -04:00
|
|
|
feature2D = new Feature2D(cv::xfeatures2d::SURF::create(
|
2014-10-24 02:46:03 +00:00
|
|
|
getFeature2D_SURF_hessianThreshold(),
|
|
|
|
|
getFeature2D_SURF_nOctaves(),
|
|
|
|
|
getFeature2D_SURF_nOctaveLayers(),
|
|
|
|
|
getFeature2D_SURF_extended(),
|
2015-07-10 14:27:11 -04:00
|
|
|
getFeature2D_SURF_upright()));
|
2015-06-23 16:38:47 -04:00
|
|
|
#endif
|
2014-08-22 22:36:09 +00:00
|
|
|
UDEBUG("type=%s", strategies.at(index).toStdString().c_str());
|
2012-10-29 20:00:44 +00:00
|
|
|
}
|
2011-10-25 15:48:19 +00:00
|
|
|
}
|
2014-10-24 02:46:03 +00:00
|
|
|
#endif
|
2011-10-25 15:48:19 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2014-06-19 21:52:04 +00:00
|
|
|
|
2015-07-10 14:27:11 -04:00
|
|
|
return feature2D;
|
2011-10-25 15:48:19 +00:00
|
|
|
}
|
|
|
|
|
|
2015-07-10 14:27:11 -04:00
|
|
|
Feature2D * Settings::createDescriptorExtractor()
|
2011-10-25 15:48:19 +00:00
|
|
|
{
|
2015-07-10 14:27:11 -04:00
|
|
|
Feature2D * feature2D = 0;
|
2012-10-29 20:00:44 +00:00
|
|
|
QString str = getFeature2D_2Descriptor();
|
2011-10-25 15:48:19 +00:00
|
|
|
QStringList split = str.split(':');
|
|
|
|
|
if(split.size()==2)
|
|
|
|
|
{
|
|
|
|
|
bool ok = false;
|
|
|
|
|
int index = split.first().toInt(&ok);
|
|
|
|
|
if(ok)
|
|
|
|
|
{
|
|
|
|
|
QStringList strategies = split.last().split(';');
|
2015-06-23 16:38:47 -04:00
|
|
|
if(index>=0 && index<strategies.size())
|
2011-10-25 15:48:19 +00:00
|
|
|
{
|
2014-11-28 21:47:02 +00:00
|
|
|
|
|
|
|
|
#if FINDOBJECT_NONFREE == 0
|
|
|
|
|
//check for nonfree stuff
|
|
|
|
|
if(strategies.at(index).compare("SIFT") == 0 ||
|
|
|
|
|
strategies.at(index).compare("SURF") == 0)
|
|
|
|
|
{
|
|
|
|
|
index = Settings::defaultFeature2D_2Descriptor().split(':').first().toInt();
|
|
|
|
|
UERROR("Find-Object is not built with OpenCV nonfree module so "
|
|
|
|
|
"SIFT/SURF cannot be used! Using default \"%s\" instead.",
|
|
|
|
|
strategies.at(index).toStdString().c_str());
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
#endif
|
|
|
|
|
|
2015-08-07 23:29:52 -04:00
|
|
|
#if CV_MAJOR_VERSION < 3
|
|
|
|
|
if(strategies.at(index).compare("KAZE") == 0 ||
|
|
|
|
|
strategies.at(index).compare("AKAZE") == 0)
|
|
|
|
|
{
|
|
|
|
|
index = Settings::defaultFeature2D_2Descriptor().split(':').first().toInt();
|
|
|
|
|
UERROR("Find-Object is built with OpenCV 2 so "
|
|
|
|
|
"KAZE/AKAZE cannot be used! Using default \"%s\" instead.",
|
|
|
|
|
strategies.at(index).toStdString().c_str());
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
#else
|
|
|
|
|
#ifndef HAVE_OPENCV_XFEATURES2D
|
|
|
|
|
if(strategies.at(index).compare("Brief") == 0 ||
|
|
|
|
|
strategies.at(index).compare("FREAK") == 0 ||
|
|
|
|
|
strategies.at(index).compare("LUCID") == 0 ||
|
|
|
|
|
strategies.at(index).compare("LATCH") == 0 ||
|
|
|
|
|
strategies.at(index).compare("DAISY") == 0)
|
|
|
|
|
{
|
|
|
|
|
index = Settings::defaultFeature2D_2Descriptor().split(':').first().toInt();
|
|
|
|
|
UERROR("Find-Object is not built with OpenCV xfeatures2d module so "
|
|
|
|
|
"Brief/FREAK/LUCID/LATCH/DAISY cannot be used! Using default \"%s\" instead.",
|
|
|
|
|
strategies.at(index).toStdString().c_str());
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
#endif
|
|
|
|
|
#endif
|
|
|
|
|
|
2014-10-24 02:46:03 +00:00
|
|
|
if(strategies.at(index).compare("Brief") == 0)
|
2011-10-25 15:48:19 +00:00
|
|
|
{
|
2015-06-23 16:38:47 -04:00
|
|
|
#if CV_MAJOR_VERSION < 3
|
2015-07-10 14:27:11 -04:00
|
|
|
feature2D = new Feature2D(cv::Ptr<cv::DescriptorExtractor>(new cv::BriefDescriptorExtractor(
|
|
|
|
|
getFeature2D_Brief_bytes())));
|
2015-06-23 16:38:47 -04:00
|
|
|
#else
|
|
|
|
|
#ifdef HAVE_OPENCV_XFEATURES2D
|
2015-07-10 14:27:11 -04:00
|
|
|
feature2D = new Feature2D(cv::xfeatures2d::BriefDescriptorExtractor::create(
|
|
|
|
|
getFeature2D_Brief_bytes()));
|
2015-06-23 16:38:47 -04:00
|
|
|
#else
|
|
|
|
|
UWARN("Find-Object is not built with OpenCV xfeatures2d module so Brief cannot be used!");
|
|
|
|
|
#endif
|
|
|
|
|
#endif
|
2014-10-24 02:46:03 +00:00
|
|
|
UDEBUG("type=%s", strategies.at(index).toStdString().c_str());
|
|
|
|
|
}
|
|
|
|
|
else if(strategies.at(index).compare("ORB") == 0)
|
|
|
|
|
{
|
2015-06-23 16:38:47 -04:00
|
|
|
if(getFeature2D_ORB_gpu() && CVCUDA::getCudaEnabledDeviceCount())
|
2011-10-25 15:48:19 +00:00
|
|
|
{
|
2015-07-10 14:27:11 -04:00
|
|
|
feature2D = new GPUORB(
|
2014-10-24 02:46:03 +00:00
|
|
|
getFeature2D_ORB_nFeatures(),
|
|
|
|
|
getFeature2D_ORB_scaleFactor(),
|
|
|
|
|
getFeature2D_ORB_nLevels(),
|
|
|
|
|
getFeature2D_ORB_edgeThreshold(),
|
|
|
|
|
getFeature2D_ORB_firstLevel(),
|
|
|
|
|
getFeature2D_ORB_WTA_K(),
|
|
|
|
|
getFeature2D_ORB_scoreType(),
|
|
|
|
|
getFeature2D_ORB_patchSize(),
|
|
|
|
|
getFeature2D_Fast_threshold(),
|
|
|
|
|
getFeature2D_Fast_nonmaxSuppression());
|
|
|
|
|
UDEBUG("type=%s (GPU)", strategies.at(index).toStdString().c_str());
|
2011-10-25 15:48:19 +00:00
|
|
|
}
|
2014-10-24 02:46:03 +00:00
|
|
|
else
|
2011-10-25 15:48:19 +00:00
|
|
|
{
|
2015-06-23 16:38:47 -04:00
|
|
|
#if CV_MAJOR_VERSION < 3
|
2015-07-10 14:27:11 -04:00
|
|
|
feature2D = new Feature2D(cv::Ptr<cv::Feature2D>(new cv::ORB(
|
2015-06-23 16:38:47 -04:00
|
|
|
getFeature2D_ORB_nFeatures(),
|
|
|
|
|
getFeature2D_ORB_scaleFactor(),
|
|
|
|
|
getFeature2D_ORB_nLevels(),
|
|
|
|
|
getFeature2D_ORB_edgeThreshold(),
|
|
|
|
|
getFeature2D_ORB_firstLevel(),
|
|
|
|
|
getFeature2D_ORB_WTA_K(),
|
|
|
|
|
getFeature2D_ORB_scoreType(),
|
2015-07-10 14:27:11 -04:00
|
|
|
getFeature2D_ORB_patchSize())));
|
2015-06-23 16:38:47 -04:00
|
|
|
#else
|
2015-07-10 14:27:11 -04:00
|
|
|
feature2D = new Feature2D(cv::ORB::create(
|
2014-10-24 02:46:03 +00:00
|
|
|
getFeature2D_ORB_nFeatures(),
|
|
|
|
|
getFeature2D_ORB_scaleFactor(),
|
|
|
|
|
getFeature2D_ORB_nLevels(),
|
|
|
|
|
getFeature2D_ORB_edgeThreshold(),
|
|
|
|
|
getFeature2D_ORB_firstLevel(),
|
|
|
|
|
getFeature2D_ORB_WTA_K(),
|
|
|
|
|
getFeature2D_ORB_scoreType(),
|
2015-07-10 14:27:11 -04:00
|
|
|
getFeature2D_ORB_patchSize(),
|
|
|
|
|
getFeature2D_Fast_threshold()));
|
2015-06-23 16:38:47 -04:00
|
|
|
#endif
|
2014-08-22 22:36:09 +00:00
|
|
|
UDEBUG("type=%s", strategies.at(index).toStdString().c_str());
|
2011-10-25 15:48:19 +00:00
|
|
|
}
|
2014-10-24 02:46:03 +00:00
|
|
|
}
|
|
|
|
|
else if(strategies.at(index).compare("BRISK") == 0)
|
|
|
|
|
{
|
2015-06-23 16:38:47 -04:00
|
|
|
#if CV_MAJOR_VERSION < 3
|
2015-07-10 14:27:11 -04:00
|
|
|
feature2D = new Feature2D(cv::Ptr<cv::Feature2D>(new cv::BRISK(
|
2015-06-23 16:38:47 -04:00
|
|
|
getFeature2D_BRISK_thresh(),
|
|
|
|
|
getFeature2D_BRISK_octaves(),
|
2015-07-10 14:27:11 -04:00
|
|
|
getFeature2D_BRISK_patternScale())));
|
2015-06-23 16:38:47 -04:00
|
|
|
#else
|
2015-07-10 14:27:11 -04:00
|
|
|
feature2D = new Feature2D(cv::BRISK::create(
|
2014-10-24 02:46:03 +00:00
|
|
|
getFeature2D_BRISK_thresh(),
|
|
|
|
|
getFeature2D_BRISK_octaves(),
|
2015-07-10 14:27:11 -04:00
|
|
|
getFeature2D_BRISK_patternScale()));
|
2015-06-23 16:38:47 -04:00
|
|
|
#endif
|
|
|
|
|
UDEBUG("type=%s", strategies.at(index).toStdString().c_str());
|
|
|
|
|
}
|
|
|
|
|
else if(strategies.at(index).compare("KAZE") == 0)
|
|
|
|
|
{
|
|
|
|
|
#if CV_MAJOR_VERSION < 3
|
|
|
|
|
UWARN("Find-Object is not built with OpenCV 3 so KAZE cannot be used!");
|
|
|
|
|
#else
|
2015-07-10 14:27:11 -04:00
|
|
|
feature2D = new Feature2D(cv::KAZE::create(
|
2015-06-23 16:38:47 -04:00
|
|
|
getFeature2D_KAZE_extended(),
|
|
|
|
|
getFeature2D_KAZE_upright(),
|
|
|
|
|
getFeature2D_KAZE_threshold(),
|
|
|
|
|
getFeature2D_KAZE_nOctaves(),
|
|
|
|
|
getFeature2D_KAZE_nOctaveLayers(),
|
2015-07-10 14:27:11 -04:00
|
|
|
cv::KAZE::DIFF_PM_G2)); // FIXME: make a parameter
|
2015-06-23 16:38:47 -04:00
|
|
|
#endif
|
|
|
|
|
UDEBUG("type=%s", strategies.at(index).toStdString().c_str());
|
|
|
|
|
}
|
|
|
|
|
else if(strategies.at(index).compare("AKAZE") == 0)
|
|
|
|
|
{
|
|
|
|
|
#if CV_MAJOR_VERSION < 3
|
|
|
|
|
UWARN("Find-Object is not built with OpenCV 3 so AKAZE cannot be used!");
|
|
|
|
|
#else
|
2015-07-10 14:27:11 -04:00
|
|
|
feature2D = new Feature2D(cv::AKAZE::create(
|
2015-06-23 16:38:47 -04:00
|
|
|
cv::AKAZE::DESCRIPTOR_MLDB, // FIXME: make a parameter
|
|
|
|
|
getFeature2D_AKAZE_descriptorSize(),
|
|
|
|
|
getFeature2D_AKAZE_descriptorChannels(),
|
|
|
|
|
getFeature2D_AKAZE_threshold(),
|
|
|
|
|
getFeature2D_AKAZE_nOctaves(),
|
|
|
|
|
getFeature2D_AKAZE_nOctaveLayers(),
|
2015-07-10 14:27:11 -04:00
|
|
|
cv::KAZE::DIFF_PM_G2)); // FIXME: make a parameter
|
2015-06-23 16:38:47 -04:00
|
|
|
#endif
|
2014-10-24 02:46:03 +00:00
|
|
|
UDEBUG("type=%s", strategies.at(index).toStdString().c_str());
|
|
|
|
|
}
|
|
|
|
|
else if(strategies.at(index).compare("FREAK") == 0)
|
|
|
|
|
{
|
2015-06-23 16:38:47 -04:00
|
|
|
#if CV_MAJOR_VERSION < 3
|
2015-07-10 14:27:11 -04:00
|
|
|
feature2D = new Feature2D(cv::Ptr<cv::DescriptorExtractor>(new cv::FREAK(
|
2015-06-23 16:38:47 -04:00
|
|
|
getFeature2D_FREAK_orientationNormalized(),
|
|
|
|
|
getFeature2D_FREAK_scaleNormalized(),
|
|
|
|
|
getFeature2D_FREAK_patternScale(),
|
2015-07-10 14:27:11 -04:00
|
|
|
getFeature2D_FREAK_nOctaves())));
|
2015-06-23 16:38:47 -04:00
|
|
|
#else
|
|
|
|
|
#ifdef HAVE_OPENCV_XFEATURES2D
|
2015-07-10 14:27:11 -04:00
|
|
|
feature2D = new Feature2D(cv::xfeatures2d::FREAK::create(
|
2014-10-24 02:46:03 +00:00
|
|
|
getFeature2D_FREAK_orientationNormalized(),
|
|
|
|
|
getFeature2D_FREAK_scaleNormalized(),
|
|
|
|
|
getFeature2D_FREAK_patternScale(),
|
2015-07-10 14:27:11 -04:00
|
|
|
getFeature2D_FREAK_nOctaves()));
|
2015-06-23 16:38:47 -04:00
|
|
|
#else
|
|
|
|
|
UWARN("Find-Object is not built with OpenCV xfeatures2d module so Freak cannot be used!");
|
|
|
|
|
#endif
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
UDEBUG("type=%s", strategies.at(index).toStdString().c_str());
|
|
|
|
|
}
|
|
|
|
|
#ifdef HAVE_OPENCV_XFEATURES2D
|
|
|
|
|
else if(strategies.at(index).compare("LUCID") == 0)
|
|
|
|
|
{
|
2015-07-10 14:27:11 -04:00
|
|
|
feature2D = new Feature2D(cv::xfeatures2d::LUCID::create(
|
2015-06-23 16:38:47 -04:00
|
|
|
getFeature2D_LUCID_kernel(),
|
2015-07-10 14:27:11 -04:00
|
|
|
getFeature2D_LUCID_blur_kernel()));
|
2015-06-23 16:38:47 -04:00
|
|
|
|
|
|
|
|
UDEBUG("type=%s", strategies.at(index).toStdString().c_str());
|
|
|
|
|
}
|
|
|
|
|
else if(strategies.at(index).compare("LATCH") == 0)
|
|
|
|
|
{
|
2015-07-10 14:27:11 -04:00
|
|
|
feature2D = new Feature2D(cv::xfeatures2d::LATCH::create(
|
2015-06-23 16:38:47 -04:00
|
|
|
getFeature2D_LATCH_bytes(),
|
|
|
|
|
getFeature2D_LATCH_rotationInvariance(),
|
2015-07-10 14:27:11 -04:00
|
|
|
getFeature2D_LATCH_half_ssd_size()));
|
2015-06-23 16:38:47 -04:00
|
|
|
|
|
|
|
|
UDEBUG("type=%s", strategies.at(index).toStdString().c_str());
|
|
|
|
|
}
|
|
|
|
|
else if(strategies.at(index).compare("DAISY") == 0)
|
|
|
|
|
{
|
2015-07-10 14:27:11 -04:00
|
|
|
feature2D = new Feature2D(cv::xfeatures2d::DAISY::create(
|
2015-06-23 16:38:47 -04:00
|
|
|
getFeature2D_DAISY_radius(),
|
|
|
|
|
getFeature2D_DAISY_q_radius(),
|
|
|
|
|
getFeature2D_DAISY_q_theta(),
|
|
|
|
|
getFeature2D_DAISY_q_hist(),
|
|
|
|
|
cv::xfeatures2d::DAISY::NRM_NONE,
|
|
|
|
|
cv::noArray(),
|
|
|
|
|
getFeature2D_DAISY_interpolation(),
|
2015-07-10 14:27:11 -04:00
|
|
|
getFeature2D_DAISY_use_orientation()));
|
2015-06-23 16:38:47 -04:00
|
|
|
|
2014-10-24 02:46:03 +00:00
|
|
|
UDEBUG("type=%s", strategies.at(index).toStdString().c_str());
|
|
|
|
|
}
|
2015-06-23 16:38:47 -04:00
|
|
|
#endif
|
2014-11-28 21:47:02 +00:00
|
|
|
#if FINDOBJECT_NONFREE == 1
|
2014-10-24 02:46:03 +00:00
|
|
|
else if(strategies.at(index).compare("SIFT") == 0)
|
|
|
|
|
{
|
2015-06-23 16:38:47 -04:00
|
|
|
#if CV_MAJOR_VERSION < 3
|
2015-07-10 14:27:11 -04:00
|
|
|
feature2D = new Feature2D(cv::Ptr<cv::Feature2D>(new cv::SIFT(
|
2015-06-23 16:38:47 -04:00
|
|
|
getFeature2D_SIFT_nfeatures(),
|
|
|
|
|
getFeature2D_SIFT_nOctaveLayers(),
|
|
|
|
|
getFeature2D_SIFT_contrastThreshold(),
|
|
|
|
|
getFeature2D_SIFT_edgeThreshold(),
|
2015-07-10 14:27:11 -04:00
|
|
|
getFeature2D_SIFT_sigma())));
|
2015-06-23 16:38:47 -04:00
|
|
|
#else
|
2015-07-10 14:27:11 -04:00
|
|
|
feature2D = new Feature2D(cv::xfeatures2d::SIFT::create(
|
2014-10-24 02:46:03 +00:00
|
|
|
getFeature2D_SIFT_nfeatures(),
|
|
|
|
|
getFeature2D_SIFT_nOctaveLayers(),
|
|
|
|
|
getFeature2D_SIFT_contrastThreshold(),
|
|
|
|
|
getFeature2D_SIFT_edgeThreshold(),
|
2015-07-10 14:27:11 -04:00
|
|
|
getFeature2D_SIFT_sigma()));
|
2015-06-23 16:38:47 -04:00
|
|
|
#endif
|
2014-10-24 02:46:03 +00:00
|
|
|
UDEBUG("type=%s", strategies.at(index).toStdString().c_str());
|
|
|
|
|
}
|
|
|
|
|
else if(strategies.at(index).compare("SURF") == 0)
|
|
|
|
|
{
|
2015-06-23 16:38:47 -04:00
|
|
|
if(getFeature2D_SURF_gpu() && CVCUDA::getCudaEnabledDeviceCount())
|
2012-10-29 20:00:44 +00:00
|
|
|
{
|
2015-07-10 14:27:11 -04:00
|
|
|
feature2D = new GPUSURF(
|
2014-10-24 02:46:03 +00:00
|
|
|
getFeature2D_SURF_hessianThreshold(),
|
|
|
|
|
getFeature2D_SURF_nOctaves(),
|
|
|
|
|
getFeature2D_SURF_nOctaveLayers(),
|
|
|
|
|
getFeature2D_SURF_extended(),
|
|
|
|
|
getFeature2D_SURF_keypointsRatio(),
|
|
|
|
|
getFeature2D_SURF_upright());
|
|
|
|
|
UDEBUG("type=%s (GPU)", strategies.at(index).toStdString().c_str());
|
2012-10-29 20:00:44 +00:00
|
|
|
}
|
2014-10-24 02:46:03 +00:00
|
|
|
else
|
2012-10-29 20:00:44 +00:00
|
|
|
{
|
2015-06-23 16:38:47 -04:00
|
|
|
#if CV_MAJOR_VERSION < 3
|
2015-07-10 14:27:11 -04:00
|
|
|
feature2D = new Feature2D(cv::Ptr<cv::Feature2D>(new cv::SURF(
|
2015-06-23 16:38:47 -04:00
|
|
|
getFeature2D_SURF_hessianThreshold(),
|
|
|
|
|
getFeature2D_SURF_nOctaves(),
|
|
|
|
|
getFeature2D_SURF_nOctaveLayers(),
|
|
|
|
|
getFeature2D_SURF_extended(),
|
2015-07-10 14:27:11 -04:00
|
|
|
getFeature2D_SURF_upright())));
|
2015-06-23 16:38:47 -04:00
|
|
|
#else
|
2015-07-10 14:27:11 -04:00
|
|
|
feature2D = new Feature2D(cv::xfeatures2d::SURF::create(
|
2014-10-24 02:46:03 +00:00
|
|
|
getFeature2D_SURF_hessianThreshold(),
|
|
|
|
|
getFeature2D_SURF_nOctaves(),
|
|
|
|
|
getFeature2D_SURF_nOctaveLayers(),
|
|
|
|
|
getFeature2D_SURF_extended(),
|
2015-07-10 14:27:11 -04:00
|
|
|
getFeature2D_SURF_upright()));
|
2015-06-23 16:38:47 -04:00
|
|
|
#endif
|
2014-08-22 22:36:09 +00:00
|
|
|
UDEBUG("type=%s", strategies.at(index).toStdString().c_str());
|
2012-10-29 20:00:44 +00:00
|
|
|
}
|
2011-10-25 15:48:19 +00:00
|
|
|
}
|
2014-10-24 02:46:03 +00:00
|
|
|
#endif
|
2011-10-25 15:48:19 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2014-06-19 21:52:04 +00:00
|
|
|
|
2015-07-10 14:27:11 -04:00
|
|
|
return feature2D;
|
2011-10-25 15:48:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QString Settings::currentDetectorType()
|
|
|
|
|
{
|
2012-10-29 20:00:44 +00:00
|
|
|
int index = getFeature2D_1Detector().split(':').first().toInt();
|
|
|
|
|
return getFeature2D_1Detector().split(':').last().split(';').at(index);
|
2011-10-25 15:48:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QString Settings::currentDescriptorType()
|
|
|
|
|
{
|
2012-10-29 20:00:44 +00:00
|
|
|
int index = getFeature2D_2Descriptor().split(':').first().toInt();
|
|
|
|
|
return getFeature2D_2Descriptor().split(':').last().split(';').at(index);
|
2012-08-28 13:44:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QString Settings::currentNearestNeighborType()
|
|
|
|
|
{
|
|
|
|
|
int index = getNearestNeighbor_1Strategy().split(':').first().toInt();
|
|
|
|
|
return getNearestNeighbor_1Strategy().split(':').last().split(';').at(index);
|
|
|
|
|
}
|
|
|
|
|
|
2014-10-24 02:46:03 +00:00
|
|
|
bool Settings::isBruteForceNearestNeighbor()
|
|
|
|
|
{
|
|
|
|
|
bool bruteForce = false;
|
|
|
|
|
QString str = getNearestNeighbor_1Strategy();
|
|
|
|
|
QStringList split = str.split(':');
|
|
|
|
|
if(split.size()==2)
|
|
|
|
|
{
|
|
|
|
|
bool ok = false;
|
|
|
|
|
int index = split.first().toInt(&ok);
|
|
|
|
|
if(ok)
|
|
|
|
|
{
|
|
|
|
|
QStringList strategies = split.last().split(';');
|
|
|
|
|
if(strategies.size() >= 7 && index == 6)
|
|
|
|
|
{
|
|
|
|
|
bruteForce = true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return bruteForce;
|
|
|
|
|
}
|
|
|
|
|
|
2012-08-28 13:44:57 +00:00
|
|
|
cv::flann::IndexParams * Settings::createFlannIndexParams()
|
|
|
|
|
{
|
|
|
|
|
cv::flann::IndexParams * params = 0;
|
|
|
|
|
QString str = getNearestNeighbor_1Strategy();
|
|
|
|
|
QStringList split = str.split(':');
|
|
|
|
|
if(split.size()==2)
|
|
|
|
|
{
|
|
|
|
|
bool ok = false;
|
|
|
|
|
int index = split.first().toInt(&ok);
|
|
|
|
|
if(ok)
|
|
|
|
|
{
|
|
|
|
|
QStringList strategies = split.last().split(';');
|
2014-10-24 02:46:03 +00:00
|
|
|
if(strategies.size() >= 6 && index>=0 && index<6)
|
2012-08-28 13:44:57 +00:00
|
|
|
{
|
|
|
|
|
switch(index)
|
|
|
|
|
{
|
|
|
|
|
case 0:
|
|
|
|
|
if(strategies.at(index).compare("Linear") == 0)
|
|
|
|
|
{
|
2014-08-22 22:36:09 +00:00
|
|
|
UDEBUG("type=%s", "Linear");
|
2012-08-28 13:44:57 +00:00
|
|
|
params = new cv::flann::LinearIndexParams();
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
case 1:
|
|
|
|
|
if(strategies.at(index).compare("KDTree") == 0)
|
|
|
|
|
{
|
2014-08-22 22:36:09 +00:00
|
|
|
UDEBUG("type=%s", "KDTree");
|
2012-08-28 13:44:57 +00:00
|
|
|
params = new cv::flann::KDTreeIndexParams(
|
|
|
|
|
getNearestNeighbor_KDTree_trees());
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
case 2:
|
|
|
|
|
if(strategies.at(index).compare("KMeans") == 0)
|
|
|
|
|
{
|
|
|
|
|
cvflann::flann_centers_init_t centers_init = cvflann::FLANN_CENTERS_RANDOM;
|
|
|
|
|
QString str = getNearestNeighbor_KMeans_centers_init();
|
|
|
|
|
QStringList split = str.split(':');
|
|
|
|
|
if(split.size()==2)
|
|
|
|
|
{
|
|
|
|
|
bool ok = false;
|
|
|
|
|
int index = split.first().toInt(&ok);
|
|
|
|
|
if(ok)
|
|
|
|
|
{
|
|
|
|
|
centers_init = (cvflann::flann_centers_init_t)index;
|
|
|
|
|
}
|
|
|
|
|
}
|
2014-08-22 22:36:09 +00:00
|
|
|
UDEBUG("type=%s", "KMeans");
|
2012-08-28 13:44:57 +00:00
|
|
|
params = new cv::flann::KMeansIndexParams(
|
|
|
|
|
getNearestNeighbor_KMeans_branching(),
|
|
|
|
|
getNearestNeighbor_KMeans_iterations(),
|
|
|
|
|
centers_init,
|
|
|
|
|
getNearestNeighbor_KMeans_cb_index());
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
case 3:
|
|
|
|
|
if(strategies.at(index).compare("Composite") == 0)
|
|
|
|
|
{
|
|
|
|
|
cvflann::flann_centers_init_t centers_init = cvflann::FLANN_CENTERS_RANDOM;
|
|
|
|
|
QString str = getNearestNeighbor_Composite_centers_init();
|
|
|
|
|
QStringList split = str.split(':');
|
|
|
|
|
if(split.size()==2)
|
|
|
|
|
{
|
|
|
|
|
bool ok = false;
|
|
|
|
|
int index = split.first().toInt(&ok);
|
|
|
|
|
if(ok)
|
|
|
|
|
{
|
|
|
|
|
centers_init = (cvflann::flann_centers_init_t)index;
|
|
|
|
|
}
|
|
|
|
|
}
|
2014-08-22 22:36:09 +00:00
|
|
|
UDEBUG("type=%s", "Composite");
|
2012-08-28 13:44:57 +00:00
|
|
|
params = new cv::flann::CompositeIndexParams(
|
|
|
|
|
getNearestNeighbor_Composite_trees(),
|
|
|
|
|
getNearestNeighbor_Composite_branching(),
|
|
|
|
|
getNearestNeighbor_Composite_iterations(),
|
|
|
|
|
centers_init,
|
|
|
|
|
getNearestNeighbor_Composite_cb_index());
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
case 4:
|
|
|
|
|
if(strategies.at(index).compare("Autotuned") == 0)
|
|
|
|
|
{
|
2014-08-22 22:36:09 +00:00
|
|
|
UDEBUG("type=%s", "Autotuned");
|
2012-08-28 13:44:57 +00:00
|
|
|
params = new cv::flann::AutotunedIndexParams(
|
|
|
|
|
getNearestNeighbor_Autotuned_target_precision(),
|
|
|
|
|
getNearestNeighbor_Autotuned_build_weight(),
|
|
|
|
|
getNearestNeighbor_Autotuned_memory_weight(),
|
|
|
|
|
getNearestNeighbor_Autotuned_sample_fraction());
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
case 5:
|
|
|
|
|
if(strategies.at(index).compare("Lsh") == 0)
|
|
|
|
|
{
|
2014-08-22 22:36:09 +00:00
|
|
|
UDEBUG("type=%s", "Lsh");
|
2012-08-28 13:44:57 +00:00
|
|
|
params = new cv::flann::LshIndexParams(
|
|
|
|
|
getNearestNeighbor_Lsh_table_number(),
|
|
|
|
|
getNearestNeighbor_Lsh_key_size(),
|
|
|
|
|
getNearestNeighbor_Lsh_multi_probe_level());
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if(!params)
|
|
|
|
|
{
|
2014-07-31 19:02:31 +00:00
|
|
|
UERROR("NN strategy not found !? Using default KDTRee...");
|
2012-08-28 13:44:57 +00:00
|
|
|
params = new cv::flann::KDTreeIndexParams();
|
|
|
|
|
}
|
|
|
|
|
return params ;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
cvflann::flann_distance_t Settings::getFlannDistanceType()
|
|
|
|
|
{
|
|
|
|
|
cvflann::flann_distance_t distance = cvflann::FLANN_DIST_L2;
|
|
|
|
|
QString str = getNearestNeighbor_2Distance_type();
|
|
|
|
|
QStringList split = str.split(':');
|
|
|
|
|
if(split.size()==2)
|
|
|
|
|
{
|
|
|
|
|
bool ok = false;
|
|
|
|
|
int index = split.first().toInt(&ok);
|
|
|
|
|
if(ok)
|
|
|
|
|
{
|
|
|
|
|
QStringList strategies = split.last().split(';');
|
2014-06-19 15:29:00 +00:00
|
|
|
if(strategies.size() == 9 && index>=0 && index<=8)
|
2012-08-28 13:44:57 +00:00
|
|
|
{
|
|
|
|
|
distance = (cvflann::flann_distance_t)(index+1);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return distance;
|
|
|
|
|
}
|
|
|
|
|
|
2014-04-11 19:24:59 +00:00
|
|
|
int Settings::getHomographyMethod()
|
|
|
|
|
{
|
|
|
|
|
int method = cv::RANSAC;
|
|
|
|
|
QString str = getHomography_method();
|
|
|
|
|
QStringList split = str.split(':');
|
|
|
|
|
if(split.size()==2)
|
|
|
|
|
{
|
|
|
|
|
bool ok = false;
|
|
|
|
|
int index = split.first().toInt(&ok);
|
|
|
|
|
if(ok)
|
|
|
|
|
{
|
|
|
|
|
QStringList strategies = split.last().split(';');
|
|
|
|
|
if(strategies.size() == 2 && index>=0 && index<2)
|
|
|
|
|
{
|
|
|
|
|
switch(method)
|
|
|
|
|
{
|
2016-01-17 12:24:42 -05:00
|
|
|
#if CV_MAJOR_VERSION >= 3
|
|
|
|
|
case 2:
|
|
|
|
|
method = cv::RHO;
|
|
|
|
|
break;
|
|
|
|
|
#endif
|
2014-04-11 19:24:59 +00:00
|
|
|
case 0:
|
|
|
|
|
method = cv::LMEDS;
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
method = cv::RANSAC;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2014-08-22 22:36:09 +00:00
|
|
|
UDEBUG("method=%d", method);
|
2014-04-11 19:24:59 +00:00
|
|
|
return method;
|
|
|
|
|
}
|
2014-06-19 21:52:04 +00:00
|
|
|
|
2015-07-10 14:27:11 -04:00
|
|
|
#if CV_MAJOR_VERSION < 3
|
|
|
|
|
Feature2D::Feature2D(cv::Ptr<cv::FeatureDetector> featureDetector) :
|
|
|
|
|
featureDetector_(featureDetector)
|
2014-06-19 21:52:04 +00:00
|
|
|
{
|
2015-06-23 16:38:47 -04:00
|
|
|
UASSERT(!featureDetector_.empty());
|
2014-06-19 21:52:04 +00:00
|
|
|
}
|
2015-07-10 14:27:11 -04:00
|
|
|
Feature2D::Feature2D(cv::Ptr<cv::DescriptorExtractor> descriptorExtractor) :
|
|
|
|
|
descriptorExtractor_(descriptorExtractor)
|
2014-06-19 21:52:04 +00:00
|
|
|
{
|
2015-07-10 14:27:11 -04:00
|
|
|
UASSERT(!descriptorExtractor_.empty());
|
2014-06-19 21:52:04 +00:00
|
|
|
}
|
2015-07-10 14:27:11 -04:00
|
|
|
#endif
|
|
|
|
|
Feature2D::Feature2D(cv::Ptr<cv::Feature2D> feature2D) :
|
|
|
|
|
feature2D_(feature2D)
|
2015-06-23 16:38:47 -04:00
|
|
|
{
|
2015-07-10 14:27:11 -04:00
|
|
|
UASSERT(!feature2D_.empty());
|
2015-06-23 16:38:47 -04:00
|
|
|
}
|
2015-07-10 14:27:11 -04:00
|
|
|
|
|
|
|
|
void Feature2D::detect(const cv::Mat & image,
|
2014-08-22 22:36:09 +00:00
|
|
|
std::vector<cv::KeyPoint> & keypoints,
|
|
|
|
|
const cv::Mat & mask)
|
2014-06-19 21:52:04 +00:00
|
|
|
{
|
2015-07-10 14:27:11 -04:00
|
|
|
#if CV_MAJOR_VERSION < 3
|
2015-06-23 16:38:47 -04:00
|
|
|
if(!featureDetector_.empty())
|
2014-06-19 21:52:04 +00:00
|
|
|
{
|
2014-08-22 22:36:09 +00:00
|
|
|
featureDetector_->detect(image, keypoints, mask);
|
2014-06-19 21:52:04 +00:00
|
|
|
}
|
2015-07-10 14:27:11 -04:00
|
|
|
else
|
|
|
|
|
#endif
|
|
|
|
|
if(!feature2D_.empty())
|
2014-06-19 21:52:04 +00:00
|
|
|
{
|
2015-07-10 14:27:11 -04:00
|
|
|
feature2D_->detect(image, keypoints, mask);
|
2014-06-19 21:52:04 +00:00
|
|
|
}
|
2015-07-10 14:27:11 -04:00
|
|
|
else
|
2015-06-23 16:38:47 -04:00
|
|
|
{
|
2015-07-10 14:27:11 -04:00
|
|
|
UERROR("Feature2D not set!?!?");
|
2015-06-23 16:38:47 -04:00
|
|
|
}
|
|
|
|
|
}
|
2015-07-10 14:27:11 -04:00
|
|
|
|
|
|
|
|
void Feature2D::compute(const cv::Mat & image,
|
2014-06-19 21:52:04 +00:00
|
|
|
std::vector<cv::KeyPoint> & keypoints,
|
|
|
|
|
cv::Mat & descriptors)
|
|
|
|
|
{
|
2015-07-10 14:27:11 -04:00
|
|
|
#if CV_MAJOR_VERSION < 3
|
2015-06-23 16:38:47 -04:00
|
|
|
if(!descriptorExtractor_.empty())
|
2014-06-19 21:52:04 +00:00
|
|
|
{
|
|
|
|
|
descriptorExtractor_->compute(image, keypoints, descriptors);
|
|
|
|
|
}
|
2015-07-10 14:27:11 -04:00
|
|
|
else
|
|
|
|
|
#endif
|
|
|
|
|
if(!feature2D_.empty())
|
|
|
|
|
{
|
|
|
|
|
feature2D_->compute(image, keypoints, descriptors);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
UERROR("Feature2D not set!?!?");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void Feature2D::detectAndCompute(const cv::Mat & image,
|
|
|
|
|
std::vector<cv::KeyPoint> & keypoints,
|
|
|
|
|
cv::Mat & descriptors,
|
|
|
|
|
const cv::Mat & mask)
|
|
|
|
|
{
|
|
|
|
|
if(!feature2D_.empty())
|
|
|
|
|
{
|
|
|
|
|
#if CV_MAJOR_VERSION < 3
|
|
|
|
|
(*feature2D_)(image, mask, keypoints, descriptors);
|
|
|
|
|
#else
|
|
|
|
|
feature2D_->detectAndCompute(image, mask, keypoints, descriptors);
|
|
|
|
|
#endif
|
|
|
|
|
}
|
|
|
|
|
else
|
2014-06-19 21:52:04 +00:00
|
|
|
{
|
2015-07-10 14:27:11 -04:00
|
|
|
UERROR("Cannot use Feature2D::detectAndCompute() if feature2D member is not set.");
|
2014-06-19 21:52:04 +00:00
|
|
|
}
|
|
|
|
|
}
|
2014-08-06 13:43:29 +00:00
|
|
|
|
|
|
|
|
} // namespace find_object
|