2011-10-25 15:48:19 +00:00
|
|
|
/*
|
2011-12-02 18:34:08 +00:00
|
|
|
* Copyright (C) 2011, Mathieu Labbe - IntRoLab - Universite de Sherbrooke
|
2011-10-25 15:48:19 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#include "Settings.h"
|
|
|
|
|
#include "Camera.h"
|
|
|
|
|
#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>
|
2012-05-07 22:36:59 +00:00
|
|
|
#include <opencv2/nonfree/features2d.hpp>
|
2011-10-25 15:48:19 +00:00
|
|
|
|
2012-08-28 13:44:57 +00:00
|
|
|
#define VERBOSE 0
|
|
|
|
|
|
2011-10-25 15:48:19 +00:00
|
|
|
ParametersMap Settings::defaultParameters_;
|
|
|
|
|
ParametersMap Settings::parameters_;
|
|
|
|
|
ParametersType Settings::parametersType_;
|
|
|
|
|
Settings Settings::dummyInit_;
|
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
|
|
|
|
2012-08-28 13:44:57 +00:00
|
|
|
void Settings::loadSettings(const QString & fileName, QByteArray * windowGeometry, QByteArray * windowState)
|
2011-10-25 15:48:19 +00:00
|
|
|
{
|
2011-11-10 14:00:20 +00:00
|
|
|
QString path = fileName;
|
|
|
|
|
if(fileName.isEmpty())
|
|
|
|
|
{
|
|
|
|
|
path = iniDefaultPath();
|
|
|
|
|
}
|
|
|
|
|
QSettings ini(path, QSettings::IniFormat);
|
2011-10-25 15:48:19 +00:00
|
|
|
for(ParametersMap::const_iterator iter = defaultParameters_.begin(); iter!=defaultParameters_.end(); ++iter)
|
|
|
|
|
{
|
|
|
|
|
const QString & key = iter.key();
|
|
|
|
|
QVariant value = ini.value(key, QVariant());
|
|
|
|
|
if(value.isValid())
|
|
|
|
|
{
|
|
|
|
|
setParameter(key, value);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if(windowGeometry)
|
|
|
|
|
{
|
|
|
|
|
QVariant value = ini.value("windowGeometry", QVariant());
|
|
|
|
|
if(value.isValid())
|
|
|
|
|
{
|
|
|
|
|
*windowGeometry = value.toByteArray();
|
|
|
|
|
}
|
|
|
|
|
}
|
2012-08-28 13:44:57 +00:00
|
|
|
if(windowState)
|
|
|
|
|
{
|
|
|
|
|
QVariant value = ini.value("windowState", QVariant());
|
|
|
|
|
if(value.isValid())
|
|
|
|
|
{
|
|
|
|
|
*windowState = value.toByteArray();
|
|
|
|
|
}
|
|
|
|
|
}
|
2011-10-25 15:48:19 +00:00
|
|
|
|
2011-11-10 14:00:20 +00:00
|
|
|
printf("Settings loaded from %s\n", path.toStdString().c_str());
|
2011-10-25 15:48:19 +00:00
|
|
|
}
|
|
|
|
|
|
2012-08-28 13:44:57 +00:00
|
|
|
void Settings::saveSettings(const QString & fileName, const QByteArray & windowGeometry, const QByteArray & windowState)
|
2011-10-25 15:48:19 +00:00
|
|
|
{
|
2011-11-10 14:00:20 +00:00
|
|
|
QString path = fileName;
|
|
|
|
|
if(fileName.isEmpty())
|
|
|
|
|
{
|
|
|
|
|
path = iniDefaultPath();
|
|
|
|
|
}
|
|
|
|
|
QSettings ini(path, QSettings::IniFormat);
|
2011-10-25 15:48:19 +00:00
|
|
|
for(ParametersMap::const_iterator iter = parameters_.begin(); iter!=parameters_.end(); ++iter)
|
|
|
|
|
{
|
|
|
|
|
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());
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if(!windowGeometry.isEmpty())
|
|
|
|
|
{
|
|
|
|
|
ini.setValue("windowGeometry", windowGeometry);
|
|
|
|
|
}
|
2012-08-28 13:44:57 +00:00
|
|
|
if(!windowState.isEmpty())
|
|
|
|
|
{
|
|
|
|
|
ini.setValue("windowState", windowState);
|
|
|
|
|
}
|
2011-11-10 14:00:20 +00:00
|
|
|
printf("Settings saved to %s\n", path.toStdString().c_str());
|
2011-10-25 15:48:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
cv::FeatureDetector * Settings::createFeaturesDetector()
|
|
|
|
|
{
|
|
|
|
|
cv::FeatureDetector * detector = 0;
|
2012-08-28 13:44:57 +00:00
|
|
|
QString str = getDetector_Descriptor_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(';');
|
|
|
|
|
if(strategies.size() == 8 && index>=0 && index<8)
|
|
|
|
|
{
|
|
|
|
|
switch(index)
|
|
|
|
|
{
|
|
|
|
|
case 0:
|
|
|
|
|
if(strategies.at(index).compare("Dense") == 0)
|
|
|
|
|
{
|
2012-05-07 22:36:59 +00:00
|
|
|
detector = new cv::DenseFeatureDetector(
|
2012-08-28 13:44:57 +00:00
|
|
|
getDetector_Descriptor_Dense_initFeatureScale(),
|
|
|
|
|
getDetector_Descriptor_Dense_featureScaleLevels(),
|
|
|
|
|
getDetector_Descriptor_Dense_featureScaleMul(),
|
|
|
|
|
getDetector_Descriptor_Dense_initXyStep(),
|
|
|
|
|
getDetector_Descriptor_Dense_initImgBound(),
|
|
|
|
|
getDetector_Descriptor_Dense_varyXyStepWithScale(),
|
|
|
|
|
getDetector_Descriptor_Dense_varyImgBoundWithScale());
|
|
|
|
|
if(VERBOSE)printf("Settings::createFeaturesDetector() type=%s\n", "Dense");
|
2011-10-25 15:48:19 +00:00
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
case 1:
|
|
|
|
|
if(strategies.at(index).compare("Fast") == 0)
|
|
|
|
|
{
|
|
|
|
|
detector = new cv::FastFeatureDetector(
|
2012-08-28 13:44:57 +00:00
|
|
|
getDetector_Descriptor_Fast_threshold(),
|
|
|
|
|
getDetector_Descriptor_Fast_nonmaxSuppression());
|
|
|
|
|
if(VERBOSE)printf("Settings::createFeaturesDetector() type=%s\n", "Fast");
|
2011-10-25 15:48:19 +00:00
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
case 2:
|
2012-05-07 22:36:59 +00:00
|
|
|
if(strategies.at(index).compare("GFTT") == 0)
|
2011-10-25 15:48:19 +00:00
|
|
|
{
|
2012-05-07 22:36:59 +00:00
|
|
|
detector = new cv::GFTTDetector(
|
2012-08-28 13:44:57 +00:00
|
|
|
getDetector_Descriptor_GFTT_maxCorners(),
|
|
|
|
|
getDetector_Descriptor_GFTT_qualityLevel(),
|
|
|
|
|
getDetector_Descriptor_GFTT_minDistance(),
|
|
|
|
|
getDetector_Descriptor_GFTT_blockSize(),
|
|
|
|
|
getDetector_Descriptor_GFTT_useHarrisDetector(),
|
|
|
|
|
getDetector_Descriptor_GFTT_k());
|
|
|
|
|
if(VERBOSE)printf("Settings::createFeaturesDetector() type=%s\n", "GFTT");
|
2011-10-25 15:48:19 +00:00
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
case 3:
|
2012-05-07 22:36:59 +00:00
|
|
|
if(strategies.at(index).compare("MSER") == 0)
|
2011-10-25 15:48:19 +00:00
|
|
|
{
|
2012-05-07 22:36:59 +00:00
|
|
|
detector = new cv::MSER(
|
2012-08-28 13:44:57 +00:00
|
|
|
getDetector_Descriptor_MSER_delta(),
|
|
|
|
|
getDetector_Descriptor_MSER_minArea(),
|
|
|
|
|
getDetector_Descriptor_MSER_maxArea(),
|
|
|
|
|
getDetector_Descriptor_MSER_maxVariation(),
|
|
|
|
|
getDetector_Descriptor_MSER_minDiversity(),
|
|
|
|
|
getDetector_Descriptor_MSER_maxEvolution(),
|
|
|
|
|
getDetector_Descriptor_MSER_areaThreshold(),
|
|
|
|
|
getDetector_Descriptor_MSER_minMargin(),
|
|
|
|
|
getDetector_Descriptor_MSER_edgeBlurSize());
|
|
|
|
|
if(VERBOSE)printf("Settings::createFeaturesDetector() type=%s\n", "MSER");
|
2011-10-25 15:48:19 +00:00
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
case 4:
|
2012-05-07 22:36:59 +00:00
|
|
|
if(strategies.at(index).compare("ORB") == 0)
|
2011-10-25 15:48:19 +00:00
|
|
|
{
|
2012-05-07 22:36:59 +00:00
|
|
|
detector = new cv::ORB(
|
2012-08-28 13:44:57 +00:00
|
|
|
getDetector_Descriptor_ORB_nFeatures(),
|
|
|
|
|
getDetector_Descriptor_ORB_scaleFactor(),
|
|
|
|
|
getDetector_Descriptor_ORB_nLevels(),
|
|
|
|
|
getDetector_Descriptor_ORB_edgeThreshold(),
|
|
|
|
|
getDetector_Descriptor_ORB_firstLevel(),
|
|
|
|
|
getDetector_Descriptor_ORB_WTA_K(),
|
|
|
|
|
getDetector_Descriptor_ORB_scoreType(),
|
|
|
|
|
getDetector_Descriptor_ORB_patchSize());
|
|
|
|
|
if(VERBOSE)printf("Settings::createFeaturesDetector() type=%s\n", "ORB");
|
2011-10-25 15:48:19 +00:00
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
case 5:
|
2012-05-07 22:36:59 +00:00
|
|
|
if(strategies.at(index).compare("SIFT") == 0)
|
2011-10-25 15:48:19 +00:00
|
|
|
{
|
2012-05-07 22:36:59 +00:00
|
|
|
detector = new cv::SIFT(
|
2012-08-28 13:44:57 +00:00
|
|
|
getDetector_Descriptor_SIFT_nfeatures(),
|
|
|
|
|
getDetector_Descriptor_SIFT_nOctaveLayers(),
|
|
|
|
|
getDetector_Descriptor_SIFT_contrastThreshold(),
|
|
|
|
|
getDetector_Descriptor_SIFT_edgeThreshold(),
|
|
|
|
|
getDetector_Descriptor_SIFT_sigma());
|
|
|
|
|
if(VERBOSE)printf("Settings::createFeaturesDetector() type=%s\n", "SIFT");
|
2011-10-25 15:48:19 +00:00
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
case 6:
|
|
|
|
|
if(strategies.at(index).compare("Star") == 0)
|
|
|
|
|
{
|
2012-05-07 22:36:59 +00:00
|
|
|
detector = new cv::StarFeatureDetector(
|
2012-08-28 13:44:57 +00:00
|
|
|
getDetector_Descriptor_Star_maxSize(),
|
|
|
|
|
getDetector_Descriptor_Star_responseThreshold(),
|
|
|
|
|
getDetector_Descriptor_Star_lineThresholdProjected(),
|
|
|
|
|
getDetector_Descriptor_Star_lineThresholdBinarized(),
|
|
|
|
|
getDetector_Descriptor_Star_suppressNonmaxSize());
|
|
|
|
|
if(VERBOSE)printf("Settings::createFeaturesDetector() type=%s\n", "Star");
|
2011-10-25 15:48:19 +00:00
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
case 7:
|
2012-05-07 22:36:59 +00:00
|
|
|
if(strategies.at(index).compare("SURF") == 0)
|
2011-10-25 15:48:19 +00:00
|
|
|
{
|
2012-05-07 22:36:59 +00:00
|
|
|
detector = new cv::SURF(
|
2012-08-28 13:44:57 +00:00
|
|
|
getDetector_Descriptor_SURF_hessianThreshold(),
|
|
|
|
|
getDetector_Descriptor_SURF_nOctaves(),
|
|
|
|
|
getDetector_Descriptor_SURF_nOctaveLayers(),
|
|
|
|
|
getDetector_Descriptor_SURF_extended(),
|
|
|
|
|
getDetector_Descriptor_SURF_upright());
|
|
|
|
|
if(VERBOSE)printf("Settings::createFeaturesDetector() type=%s\n", "SURF");
|
2011-10-25 15:48:19 +00:00
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2012-08-28 13:44:57 +00:00
|
|
|
if(!detector)
|
|
|
|
|
{
|
|
|
|
|
printf("ERROR: detector strategy not found !? Using default SURF...\n");
|
|
|
|
|
detector = new cv::SURF();
|
|
|
|
|
}
|
2011-10-25 15:48:19 +00:00
|
|
|
return detector;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
cv::DescriptorExtractor * Settings::createDescriptorsExtractor()
|
|
|
|
|
{
|
|
|
|
|
cv::DescriptorExtractor * extractor = 0;
|
2012-08-28 13:44:57 +00:00
|
|
|
QString str = getDetector_Descriptor_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(';');
|
|
|
|
|
if(strategies.size() == 4 && index>=0 && index<4)
|
|
|
|
|
{
|
|
|
|
|
switch(index)
|
|
|
|
|
{
|
|
|
|
|
case 0:
|
|
|
|
|
if(strategies.at(index).compare("Brief") == 0)
|
|
|
|
|
{
|
|
|
|
|
extractor = new cv::BriefDescriptorExtractor(
|
2012-08-28 13:44:57 +00:00
|
|
|
getDetector_Descriptor_Brief_bytes());
|
|
|
|
|
if(VERBOSE)printf("Settings::createDescriptorsExtractor() type=%s\n", "Brief");
|
2011-10-25 15:48:19 +00:00
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
case 1:
|
2012-05-07 22:36:59 +00:00
|
|
|
if(strategies.at(index).compare("ORB") == 0)
|
2011-10-25 15:48:19 +00:00
|
|
|
{
|
2012-05-07 22:36:59 +00:00
|
|
|
extractor = new cv::ORB(
|
2012-08-28 13:44:57 +00:00
|
|
|
getDetector_Descriptor_ORB_nFeatures(),
|
|
|
|
|
getDetector_Descriptor_ORB_scaleFactor(),
|
|
|
|
|
getDetector_Descriptor_ORB_nLevels(),
|
|
|
|
|
getDetector_Descriptor_ORB_edgeThreshold(),
|
|
|
|
|
getDetector_Descriptor_ORB_firstLevel(),
|
|
|
|
|
getDetector_Descriptor_ORB_WTA_K(),
|
|
|
|
|
getDetector_Descriptor_ORB_scoreType(),
|
|
|
|
|
getDetector_Descriptor_ORB_patchSize());
|
|
|
|
|
if(VERBOSE)printf("Settings::createDescriptorsExtractor() type=%s\n", "ORB");
|
2011-10-25 15:48:19 +00:00
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
case 2:
|
2012-05-07 22:36:59 +00:00
|
|
|
if(strategies.at(index).compare("SIFT") == 0)
|
2011-10-25 15:48:19 +00:00
|
|
|
{
|
2012-05-07 22:36:59 +00:00
|
|
|
extractor = new cv::SIFT(
|
2012-08-28 13:44:57 +00:00
|
|
|
getDetector_Descriptor_SIFT_nfeatures(),
|
|
|
|
|
getDetector_Descriptor_SIFT_nOctaveLayers(),
|
|
|
|
|
getDetector_Descriptor_SIFT_contrastThreshold(),
|
|
|
|
|
getDetector_Descriptor_SIFT_edgeThreshold(),
|
|
|
|
|
getDetector_Descriptor_SIFT_sigma());
|
|
|
|
|
if(VERBOSE)printf("Settings::createDescriptorsExtractor() type=%s\n", "SIFT");
|
2011-10-25 15:48:19 +00:00
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
case 3:
|
2012-05-07 22:36:59 +00:00
|
|
|
if(strategies.at(index).compare("SURF") == 0)
|
2011-10-25 15:48:19 +00:00
|
|
|
{
|
2012-05-07 22:36:59 +00:00
|
|
|
extractor = new cv::SURF(
|
2012-08-28 13:44:57 +00:00
|
|
|
getDetector_Descriptor_SURF_hessianThreshold(),
|
|
|
|
|
getDetector_Descriptor_SURF_nOctaves(),
|
|
|
|
|
getDetector_Descriptor_SURF_nOctaveLayers(),
|
|
|
|
|
getDetector_Descriptor_SURF_extended(),
|
|
|
|
|
getDetector_Descriptor_SURF_upright());
|
|
|
|
|
if(VERBOSE)printf("Settings::createDescriptorsExtractor() type=%s\n", "SURF");
|
2011-10-25 15:48:19 +00:00
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2012-08-28 13:44:57 +00:00
|
|
|
if(!extractor)
|
|
|
|
|
{
|
|
|
|
|
printf("ERROR: descriptor strategy not found !? Using default SURF...\n");
|
|
|
|
|
extractor = new cv::SURF();
|
|
|
|
|
}
|
2011-10-25 15:48:19 +00:00
|
|
|
return extractor;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QString Settings::currentDetectorType()
|
|
|
|
|
{
|
2012-08-28 13:44:57 +00:00
|
|
|
int index = getDetector_Descriptor_1Detector().split(':').first().toInt();
|
|
|
|
|
return getDetector_Descriptor_1Detector().split(':').last().split(';').at(index);
|
2011-10-25 15:48:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QString Settings::currentDescriptorType()
|
|
|
|
|
{
|
2012-08-28 13:44:57 +00:00
|
|
|
int index = getDetector_Descriptor_2Descriptor().split(':').first().toInt();
|
|
|
|
|
return getDetector_Descriptor_2Descriptor().split(':').last().split(';').at(index);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QString Settings::currentNearestNeighborType()
|
|
|
|
|
{
|
|
|
|
|
int index = getNearestNeighbor_1Strategy().split(':').first().toInt();
|
|
|
|
|
return getNearestNeighbor_1Strategy().split(':').last().split(';').at(index);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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(';');
|
|
|
|
|
if(strategies.size() == 6 && index>=0 && index<6)
|
|
|
|
|
{
|
|
|
|
|
switch(index)
|
|
|
|
|
{
|
|
|
|
|
case 0:
|
|
|
|
|
if(strategies.at(index).compare("Linear") == 0)
|
|
|
|
|
{
|
|
|
|
|
if(VERBOSE)printf("Settings::getFlannIndexParams() type=%s\n", "Linear");
|
|
|
|
|
params = new cv::flann::LinearIndexParams();
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
case 1:
|
|
|
|
|
if(strategies.at(index).compare("KDTree") == 0)
|
|
|
|
|
{
|
|
|
|
|
if(VERBOSE)printf("Settings::getFlannIndexParams() type=%s\n", "KDTree");
|
|
|
|
|
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;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if(VERBOSE)printf("Settings::getFlannIndexParams() type=%s\n", "KMeans");
|
|
|
|
|
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;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if(VERBOSE)printf("Settings::getFlannIndexParams() type=%s\n", "Composite");
|
|
|
|
|
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)
|
|
|
|
|
{
|
|
|
|
|
if(VERBOSE)printf("Settings::getFlannIndexParams() type=%s\n", "Autotuned");
|
|
|
|
|
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)
|
|
|
|
|
{
|
|
|
|
|
if(VERBOSE)printf("Settings::getFlannIndexParams() type=%s\n", "Lsh");
|
|
|
|
|
params = new cv::flann::LshIndexParams(
|
|
|
|
|
getNearestNeighbor_Lsh_table_number(),
|
|
|
|
|
getNearestNeighbor_Lsh_key_size(),
|
|
|
|
|
getNearestNeighbor_Lsh_multi_probe_level());
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if(!params)
|
|
|
|
|
{
|
|
|
|
|
printf("ERROR: NN strategy not found !? Using default KDTRee...\n");
|
|
|
|
|
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(';');
|
|
|
|
|
if(strategies.size() == 8 && index>=0 && index<8)
|
|
|
|
|
{
|
|
|
|
|
distance = (cvflann::flann_distance_t)(index+1);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if(VERBOSE)printf("Settings::getFlannDistanceType() distance=%d\n", distance);
|
|
|
|
|
return distance;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
cv::flann::SearchParams Settings::getFlannSearchParams()
|
|
|
|
|
{
|
|
|
|
|
return cv::flann::SearchParams();
|
2011-10-25 15:48:19 +00:00
|
|
|
}
|
|
|
|
|
|