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>
|
|
|
|
|
|
|
|
|
|
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)
|
|
|
|
|
{
|
|
|
|
|
cv::DenseFeatureDetector::Params params;
|
2012-01-04 17:30:36 +00:00
|
|
|
params.initFeatureScale = getDense_initFeatureScale();
|
|
|
|
|
params.featureScaleLevels = getDense_featureScaleLevels();
|
|
|
|
|
params.featureScaleMul = getDense_featureScaleMul();
|
|
|
|
|
params.initXyStep = getDense_initXyStep();
|
|
|
|
|
params.initImgBound = getDense_initImgBound();
|
|
|
|
|
params.varyXyStepWithScale = getDense_varyXyStepWithScale();
|
|
|
|
|
params.varyImgBoundWithScale = getDense_varyImgBoundWithScale();
|
2011-10-25 15:48:19 +00:00
|
|
|
detector = new cv::DenseFeatureDetector(params);
|
|
|
|
|
}
|
|
|
|
|
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:
|
|
|
|
|
if(strategies.at(index).compare("GoodFeaturesToTrack") == 0)
|
|
|
|
|
{
|
|
|
|
|
cv::GoodFeaturesToTrackDetector::Params params;
|
2012-01-04 17:30:36 +00:00
|
|
|
params.maxCorners = getGoodFeaturesToTrack_maxCorners();
|
|
|
|
|
params.qualityLevel = getGoodFeaturesToTrack_qualityLevel();
|
|
|
|
|
params.minDistance = getGoodFeaturesToTrack_minDistance();
|
|
|
|
|
params.blockSize = getGoodFeaturesToTrack_blockSize();
|
|
|
|
|
params.useHarrisDetector = getGoodFeaturesToTrack_useHarrisDetector();
|
|
|
|
|
params.k = getGoodFeaturesToTrack_k();
|
2011-10-25 15:48:19 +00:00
|
|
|
detector = new cv::GoodFeaturesToTrackDetector(params);
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
case 3:
|
|
|
|
|
if(strategies.at(index).compare("Mser") == 0)
|
|
|
|
|
{
|
|
|
|
|
CvMSERParams params = cvMSERParams();
|
2012-01-04 17:30:36 +00:00
|
|
|
params.delta = getMser_delta();
|
|
|
|
|
params.maxArea = getMser_maxArea();
|
|
|
|
|
params.minArea = getMser_minArea();
|
|
|
|
|
params.maxVariation = getMser_maxVariation();
|
|
|
|
|
params.minDiversity = getMser_minDiversity();
|
|
|
|
|
params.maxEvolution = getMser_maxEvolution();
|
|
|
|
|
params.areaThreshold = getMser_areaThreshold();
|
|
|
|
|
params.minMargin = getMser_minMargin();
|
|
|
|
|
params.edgeBlurSize = getMser_edgeBlurSize();
|
2011-10-25 15:48:19 +00:00
|
|
|
detector = new cv::MserFeatureDetector(params);
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
case 4:
|
|
|
|
|
if(strategies.at(index).compare("Orb") == 0)
|
|
|
|
|
{
|
|
|
|
|
cv::ORB::CommonParams params;
|
2012-01-04 17:30:36 +00:00
|
|
|
params.scale_factor_ = getOrb_scaleFactor();
|
|
|
|
|
params.n_levels_ = getOrb_nLevels();
|
|
|
|
|
params.first_level_ = getOrb_firstLevel();
|
|
|
|
|
params.edge_threshold_ = getOrb_edgeThreshold();
|
2011-10-25 15:48:19 +00:00
|
|
|
detector = new cv::OrbFeatureDetector(
|
2012-01-04 17:30:36 +00:00
|
|
|
getOrb_nFeatures(),
|
2011-10-25 15:48:19 +00:00
|
|
|
params);
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
case 5:
|
|
|
|
|
if(strategies.at(index).compare("Sift") == 0)
|
|
|
|
|
{
|
|
|
|
|
cv::SIFT::DetectorParams detectorParams;
|
2012-01-04 17:30:36 +00:00
|
|
|
detectorParams.edgeThreshold = getSift_edgeThreshold();
|
|
|
|
|
detectorParams.threshold = getSift_threshold();
|
2011-10-25 15:48:19 +00:00
|
|
|
cv::SIFT::CommonParams commonParams;
|
2012-01-04 17:30:36 +00:00
|
|
|
commonParams.angleMode = getSift_angleMode();
|
|
|
|
|
commonParams.firstOctave = getSift_firstOctave();
|
|
|
|
|
commonParams.nOctaveLayers = getSift_nOctaveLayers();
|
|
|
|
|
commonParams.nOctaves = getSift_nOctaves();
|
2011-10-25 15:48:19 +00:00
|
|
|
detector = new cv::SiftFeatureDetector(
|
|
|
|
|
detectorParams,
|
|
|
|
|
commonParams);
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
case 6:
|
|
|
|
|
if(strategies.at(index).compare("Star") == 0)
|
|
|
|
|
{
|
|
|
|
|
CvStarDetectorParams params = cvStarDetectorParams();
|
2012-01-04 17:30:36 +00:00
|
|
|
params.lineThresholdBinarized = getStar_lineThresholdBinarized();
|
|
|
|
|
params.lineThresholdProjected = getStar_lineThresholdProjected();
|
|
|
|
|
params.maxSize = getStar_maxSize();
|
|
|
|
|
params.responseThreshold = getStar_responseThreshold();
|
|
|
|
|
params.suppressNonmaxSize = getStar_suppressNonmaxSize();
|
2011-10-25 15:48:19 +00:00
|
|
|
detector = new cv::StarFeatureDetector(params);
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
case 7:
|
|
|
|
|
if(strategies.at(index).compare("Surf") == 0)
|
|
|
|
|
{
|
|
|
|
|
detector = new cv::SurfFeatureDetector(
|
2012-01-04 17:30:36 +00:00
|
|
|
getSurf_hessianThreshold(),
|
|
|
|
|
getSurf_octaves(),
|
|
|
|
|
getSurf_octaveLayers(),
|
|
|
|
|
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:
|
|
|
|
|
if(strategies.at(index).compare("Orb") == 0)
|
|
|
|
|
{
|
|
|
|
|
cv::ORB::CommonParams params;
|
2012-01-04 17:30:36 +00:00
|
|
|
params.scale_factor_ = getOrb_scaleFactor();
|
|
|
|
|
params.n_levels_ = getOrb_nLevels();
|
|
|
|
|
params.first_level_ = getOrb_firstLevel();
|
|
|
|
|
params.edge_threshold_ = getOrb_edgeThreshold();
|
2011-10-25 15:48:19 +00:00
|
|
|
extractor = new cv::OrbDescriptorExtractor(params);
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
case 2:
|
|
|
|
|
if(strategies.at(index).compare("Sift") == 0)
|
|
|
|
|
{
|
|
|
|
|
cv::SIFT::DescriptorParams descriptorParams;
|
2012-01-04 17:30:36 +00:00
|
|
|
descriptorParams.isNormalize = getSift_isNormalize();
|
|
|
|
|
descriptorParams.magnification = getSift_magnification();
|
|
|
|
|
descriptorParams.recalculateAngles = getSift_recalculateAngles();
|
2011-10-25 15:48:19 +00:00
|
|
|
cv::SIFT::CommonParams commonParams;
|
2012-01-04 17:30:36 +00:00
|
|
|
commonParams.angleMode = getSift_angleMode();
|
|
|
|
|
commonParams.firstOctave = getSift_firstOctave();
|
|
|
|
|
commonParams.nOctaveLayers = getSift_nOctaveLayers();
|
|
|
|
|
commonParams.nOctaves = getSift_nOctaves();
|
2011-10-25 15:48:19 +00:00
|
|
|
extractor = new cv::SiftDescriptorExtractor(
|
|
|
|
|
descriptorParams,
|
|
|
|
|
commonParams);
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
case 3:
|
|
|
|
|
if(strategies.at(index).compare("Surf") == 0)
|
|
|
|
|
{
|
|
|
|
|
extractor = new cv::SurfDescriptorExtractor(
|
2012-01-04 17:30:36 +00:00
|
|
|
getSurf_octaves(),
|
|
|
|
|
getSurf_octaveLayers(),
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
|