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
|
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
|
void Settings::loadSettings(const QString & fileName, QByteArray * windowGeometry)
|
|
|
|
|
{
|
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();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void Settings::saveSettings(const QString & fileName, const QByteArray & windowGeometry)
|
|
|
|
|
{
|
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);
|
|
|
|
|
}
|
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-01-04 17:30:36 +00:00
|
|
|
QString str = getDetector_Type();
|
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(
|
|
|
|
|
getDense_initFeatureScale(),
|
|
|
|
|
getDense_featureScaleLevels(),
|
|
|
|
|
getDense_featureScaleMul(),
|
|
|
|
|
getDense_initXyStep(),
|
|
|
|
|
getDense_initImgBound(),
|
|
|
|
|
getDense_varyXyStepWithScale(),
|
|
|
|
|
getDense_varyImgBoundWithScale());
|
2011-10-25 15:48:19 +00:00
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
case 1:
|
|
|
|
|
if(strategies.at(index).compare("Fast") == 0)
|
|
|
|
|
{
|
|
|
|
|
detector = new cv::FastFeatureDetector(
|
2012-01-04 17:30:36 +00:00
|
|
|
getFast_threshold(),
|
|
|
|
|
getFast_nonmaxSuppression());
|
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(
|
|
|
|
|
getGFTT_maxCorners(),
|
|
|
|
|
getGFTT_qualityLevel(),
|
|
|
|
|
getGFTT_minDistance(),
|
|
|
|
|
getGFTT_blockSize(),
|
|
|
|
|
getGFTT_useHarrisDetector(),
|
|
|
|
|
getGFTT_k());
|
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(
|
|
|
|
|
getMSER_delta(),
|
|
|
|
|
getMSER_minArea(),
|
|
|
|
|
getMSER_maxArea(),
|
|
|
|
|
getMSER_maxVariation(),
|
|
|
|
|
getMSER_minDiversity(),
|
|
|
|
|
getMSER_maxEvolution(),
|
|
|
|
|
getMSER_areaThreshold(),
|
|
|
|
|
getMSER_minMargin(),
|
|
|
|
|
getMSER_edgeBlurSize());
|
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(
|
|
|
|
|
getORB_nFeatures(),
|
|
|
|
|
getORB_scaleFactor(),
|
|
|
|
|
getORB_nLevels(),
|
|
|
|
|
getORB_edgeThreshold(),
|
|
|
|
|
getORB_firstLevel(),
|
|
|
|
|
getORB_WTA_K(),
|
|
|
|
|
getORB_scoreType(),
|
|
|
|
|
getORB_patchSize());
|
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(
|
|
|
|
|
getSIFT_nfeatures(),
|
|
|
|
|
getSIFT_nOctaveLayers(),
|
|
|
|
|
getSIFT_contrastThreshold(),
|
|
|
|
|
getSIFT_edgeThreshold(),
|
|
|
|
|
getSIFT_sigma());
|
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(
|
|
|
|
|
getStar_maxSize(),
|
|
|
|
|
getStar_responseThreshold(),
|
|
|
|
|
getStar_lineThresholdProjected(),
|
|
|
|
|
getStar_lineThresholdBinarized(),
|
|
|
|
|
getStar_suppressNonmaxSize());
|
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(
|
|
|
|
|
getSURF_hessianThreshold(),
|
|
|
|
|
getSURF_nOctaves(),
|
|
|
|
|
getSURF_nOctaveLayers(),
|
|
|
|
|
getSURF_extended(),
|
|
|
|
|
getSURF_upright());
|
2011-10-25 15:48:19 +00:00
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return detector;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
cv::DescriptorExtractor * Settings::createDescriptorsExtractor()
|
|
|
|
|
{
|
|
|
|
|
cv::DescriptorExtractor * extractor = 0;
|
2012-01-04 17:30:36 +00:00
|
|
|
QString str = getDescriptor_Type();
|
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-01-04 17:30:36 +00:00
|
|
|
getBrief_bytes());
|
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(
|
|
|
|
|
getORB_nFeatures(),
|
|
|
|
|
getORB_scaleFactor(),
|
|
|
|
|
getORB_nLevels(),
|
|
|
|
|
getORB_edgeThreshold(),
|
|
|
|
|
getORB_firstLevel(),
|
|
|
|
|
getORB_WTA_K(),
|
|
|
|
|
getORB_scoreType(),
|
|
|
|
|
getORB_patchSize());
|
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(
|
|
|
|
|
getSIFT_nfeatures(),
|
|
|
|
|
getSIFT_nOctaveLayers(),
|
|
|
|
|
getSIFT_contrastThreshold(),
|
|
|
|
|
getSIFT_edgeThreshold(),
|
|
|
|
|
getSIFT_sigma());
|
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(
|
|
|
|
|
getSURF_hessianThreshold(),
|
|
|
|
|
getSURF_nOctaves(),
|
|
|
|
|
getSURF_nOctaveLayers(),
|
|
|
|
|
getSURF_extended(),
|
|
|
|
|
getSURF_upright());
|
2011-10-25 15:48:19 +00:00
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return extractor;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QString Settings::currentDetectorType()
|
|
|
|
|
{
|
2012-01-04 17:30:36 +00:00
|
|
|
int index = Settings::getDetector_Type().split(':').first().toInt();
|
|
|
|
|
return getDetector_Type().split(':').last().split(';').at(index);
|
2011-10-25 15:48:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QString Settings::currentDescriptorType()
|
|
|
|
|
{
|
2012-01-04 17:30:36 +00:00
|
|
|
int index = Settings::getDescriptor_Type().split(':').first().toInt();
|
|
|
|
|
return getDescriptor_Type().split(':').last().split(';').at(index);
|
2011-10-25 15:48:19 +00:00
|
|
|
}
|
|
|
|
|
|