If a config file is set on arguments (or if there are custom parameters), parameters overwrite those in a loaded session.
This commit is contained in:
parent
ade5dd6729
commit
0424bf181c
@ -79,7 +79,6 @@ public:
|
|||||||
sharedSemaphore_(threads)
|
sharedSemaphore_(threads)
|
||||||
{
|
{
|
||||||
UASSERT(sharedFindObject != 0);
|
UASSERT(sharedFindObject != 0);
|
||||||
UASSERT(port!=0);
|
|
||||||
UASSERT(threads>=1);
|
UASSERT(threads>=1);
|
||||||
|
|
||||||
qRegisterMetaType<cv::Mat>("cv::Mat");
|
qRegisterMetaType<cv::Mat>("cv::Mat");
|
||||||
@ -87,7 +86,7 @@ public:
|
|||||||
threadPool_.resize(threads);
|
threadPool_.resize(threads);
|
||||||
for(int i=0; i<threads; ++i)
|
for(int i=0; i<threads; ++i)
|
||||||
{
|
{
|
||||||
find_object::TcpServer * tcpServer = new find_object::TcpServer(port++);
|
find_object::TcpServer * tcpServer = new find_object::TcpServer(port!=0?port++:0);
|
||||||
UINFO("TcpServer set on port: %d (IP=%s)",
|
UINFO("TcpServer set on port: %d (IP=%s)",
|
||||||
tcpServer->getPort(),
|
tcpServer->getPort(),
|
||||||
tcpServer->getHostAddress().toString().toStdString().c_str());
|
tcpServer->getHostAddress().toString().toStdString().c_str());
|
||||||
|
|||||||
47
app/main.cpp
47
app/main.cpp
@ -147,7 +147,7 @@ int main(int argc, char* argv[])
|
|||||||
QString objectsPath = "";
|
QString objectsPath = "";
|
||||||
QString objectPath = "";
|
QString objectPath = "";
|
||||||
QString scenePath = "";
|
QString scenePath = "";
|
||||||
QString configPath = find_object::Settings::iniDefaultPath();
|
QString configPath = "";
|
||||||
QString vocabularyPath = "";
|
QString vocabularyPath = "";
|
||||||
QString jsonPath;
|
QString jsonPath;
|
||||||
find_object::ParametersMap customParameters;
|
find_object::ParametersMap customParameters;
|
||||||
@ -433,9 +433,25 @@ int main(int argc, char* argv[])
|
|||||||
else
|
else
|
||||||
{
|
{
|
||||||
UINFO(" Session path: \"%s\"", sessionPath.toStdString().c_str());
|
UINFO(" Session path: \"%s\"", sessionPath.toStdString().c_str());
|
||||||
|
if(!vocabularyPath.isEmpty())
|
||||||
|
{
|
||||||
|
UWARN("Vocabulary \"%s\" is not loaded as a session \"%s\" is already "
|
||||||
|
"loaded, ignoring vocabulary file...",
|
||||||
|
vocabularyPath.toStdString().c_str(),
|
||||||
|
sessionPath.toStdString().c_str());
|
||||||
|
vocabularyPath.clear();
|
||||||
|
}
|
||||||
|
if(!configPath.isEmpty())
|
||||||
|
{
|
||||||
|
UWARN("A session \"%s\" is loaded and a config file is also used, "
|
||||||
|
"the parameters of the session will be overwritten by "
|
||||||
|
"those in the config file \"%s\".",
|
||||||
|
sessionPath.toStdString().c_str(),
|
||||||
|
configPath.toStdString().c_str());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if(!objectsPath.isEmpty())
|
if(!objectsPath.isEmpty())
|
||||||
{
|
{
|
||||||
UINFO(" Objects path: \"%s\"", objectsPath.toStdString().c_str());
|
UINFO(" Objects path: \"%s\"", objectsPath.toStdString().c_str());
|
||||||
}
|
}
|
||||||
@ -475,14 +491,20 @@ int main(int argc, char* argv[])
|
|||||||
//////////////////////////
|
//////////////////////////
|
||||||
|
|
||||||
// Load settings, should be loaded before creating other objects
|
// Load settings, should be loaded before creating other objects
|
||||||
find_object::Settings::init(configPath);
|
find_object::ParametersMap parameters;
|
||||||
|
if(!configPath.isEmpty())
|
||||||
|
{
|
||||||
|
parameters = find_object::Settings::init(configPath);
|
||||||
|
}
|
||||||
|
|
||||||
// Override custom parameters:
|
// Override custom parameters:
|
||||||
for(find_object::ParametersMap::iterator iter= customParameters.begin(); iter!=customParameters.end(); ++iter)
|
for(find_object::ParametersMap::iterator iter= customParameters.begin(); iter!=customParameters.end(); ++iter)
|
||||||
{
|
{
|
||||||
find_object::Settings::setParameter(iter.key(), iter.value());
|
find_object::Settings::setParameter(iter.key(), iter.value());
|
||||||
|
parameters.insert(iter.key(), iter.value());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// Create FindObject
|
// Create FindObject
|
||||||
find_object::FindObject * findObject = new find_object::FindObject(guiMode || imagesSaved);
|
find_object::FindObject * findObject = new find_object::FindObject(guiMode || imagesSaved);
|
||||||
|
|
||||||
@ -490,13 +512,7 @@ int main(int argc, char* argv[])
|
|||||||
int objectsLoaded = 0;
|
int objectsLoaded = 0;
|
||||||
if(!sessionPath.isEmpty() && !sessionNew)
|
if(!sessionPath.isEmpty() && !sessionNew)
|
||||||
{
|
{
|
||||||
if(!vocabularyPath.isEmpty() && !findObject->loadVocabulary(vocabularyPath))
|
if(!findObject->loadSession(sessionPath, parameters))
|
||||||
{
|
|
||||||
UWARN("Vocabulary \"%s\" is not loaded as a session \"%s\" is already loaded",
|
|
||||||
vocabularyPath.toStdString().c_str(),
|
|
||||||
sessionPath.toStdString().c_str());
|
|
||||||
}
|
|
||||||
if(!findObject->loadSession(sessionPath))
|
|
||||||
{
|
{
|
||||||
UERROR("Could not load session \"%s\"", sessionPath.toStdString().c_str());
|
UERROR("Could not load session \"%s\"", sessionPath.toStdString().c_str());
|
||||||
}
|
}
|
||||||
@ -505,7 +521,12 @@ int main(int argc, char* argv[])
|
|||||||
objectsLoaded = findObject->objects().size();
|
objectsLoaded = findObject->objects().size();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if(!objectsPath.isEmpty())
|
else if(!vocabularyPath.isEmpty() && !findObject->loadVocabulary(vocabularyPath))
|
||||||
|
{
|
||||||
|
UERROR("Failed to load vocabulary \"%s\"", vocabularyPath.toStdString().c_str());
|
||||||
|
}
|
||||||
|
|
||||||
|
if(!objectsPath.isEmpty())
|
||||||
{
|
{
|
||||||
if(!vocabularyPath.isEmpty() && !findObject->loadVocabulary(vocabularyPath))
|
if(!vocabularyPath.isEmpty() && !findObject->loadVocabulary(vocabularyPath))
|
||||||
{
|
{
|
||||||
@ -536,10 +557,6 @@ int main(int argc, char* argv[])
|
|||||||
UWARN("No object loaded from \"%s\"", objectsPath.toStdString().c_str());
|
UWARN("No object loaded from \"%s\"", objectsPath.toStdString().c_str());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if(!vocabularyPath.isEmpty() && !findObject->loadVocabulary(vocabularyPath))
|
|
||||||
{
|
|
||||||
UERROR("Failed to load vocabulary \"%s\"", vocabularyPath.toStdString().c_str());
|
|
||||||
}
|
|
||||||
|
|
||||||
cv::Mat scene;
|
cv::Mat scene;
|
||||||
if(!scenePath.isEmpty())
|
if(!scenePath.isEmpty())
|
||||||
|
|||||||
@ -31,6 +31,7 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|||||||
#include "find_object/FindObjectExp.h" // DLL export/import defines
|
#include "find_object/FindObjectExp.h" // DLL export/import defines
|
||||||
|
|
||||||
#include "find_object/DetectionInfo.h"
|
#include "find_object/DetectionInfo.h"
|
||||||
|
#include "find_object/Settings.h"
|
||||||
|
|
||||||
#include <QtCore/QObject>
|
#include <QtCore/QObject>
|
||||||
#include <QtCore/QString>
|
#include <QtCore/QString>
|
||||||
@ -64,7 +65,7 @@ public:
|
|||||||
FindObject(bool keepImagesInRAM_ = true, QObject * parent = 0);
|
FindObject(bool keepImagesInRAM_ = true, QObject * parent = 0);
|
||||||
virtual ~FindObject();
|
virtual ~FindObject();
|
||||||
|
|
||||||
bool loadSession(const QString & path);
|
bool loadSession(const QString & path, const ParametersMap & customParameters = ParametersMap());
|
||||||
bool saveSession(const QString & path);
|
bool saveSession(const QString & path);
|
||||||
bool isSessionModified() const {return sessionModified_;}
|
bool isSessionModified() const {return sessionModified_;}
|
||||||
|
|
||||||
|
|||||||
@ -312,9 +312,9 @@ public:
|
|||||||
static QString iniDefaultFileName() {return "config.ini";}
|
static QString iniDefaultFileName() {return "config.ini";}
|
||||||
static QString iniPath();
|
static QString iniPath();
|
||||||
|
|
||||||
static void init(const QString & fileName);
|
static ParametersMap init(const QString & fileName);
|
||||||
|
|
||||||
static void loadSettings(const QString & fileName = QString());
|
static ParametersMap loadSettings(const QString & fileName = QString());
|
||||||
static void loadWindowSettings(QByteArray & windowGeometry, QByteArray & windowState, const QString & fileName = QString());
|
static void loadWindowSettings(QByteArray & windowGeometry, QByteArray & windowState, const QString & fileName = QString());
|
||||||
static void saveSettings(const QString & fileName = QString());
|
static void saveSettings(const QString & fileName = QString());
|
||||||
static void saveWindowSettings(const QByteArray & windowGeometry, const QByteArray & windowState, const QString & fileName = QString());
|
static void saveWindowSettings(const QByteArray & windowGeometry, const QByteArray & windowState, const QString & fileName = QString());
|
||||||
|
|||||||
@ -74,7 +74,7 @@ FindObject::~FindObject() {
|
|||||||
objectsDescriptors_.clear();
|
objectsDescriptors_.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool FindObject::loadSession(const QString & path)
|
bool FindObject::loadSession(const QString & path, const ParametersMap & customParameters)
|
||||||
{
|
{
|
||||||
if(QFile::exists(path) && !path.isEmpty() && QFileInfo(path).suffix().compare("bin") == 0)
|
if(QFile::exists(path) && !path.isEmpty() && QFileInfo(path).suffix().compare("bin") == 0)
|
||||||
{
|
{
|
||||||
@ -88,7 +88,15 @@ bool FindObject::loadSession(const QString & path)
|
|||||||
in >> parameters;
|
in >> parameters;
|
||||||
for(QMap<QString, QVariant>::iterator iter=parameters.begin(); iter!=parameters.end(); ++iter)
|
for(QMap<QString, QVariant>::iterator iter=parameters.begin(); iter!=parameters.end(); ++iter)
|
||||||
{
|
{
|
||||||
Settings::setParameter(iter.key(), iter.value());
|
QMap<QString, QVariant>::const_iterator cter = customParameters.find(iter.key());
|
||||||
|
if(cter != customParameters.constEnd())
|
||||||
|
{
|
||||||
|
Settings::setParameter(cter.key(), cter.value());
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
Settings::setParameter(iter.key(), iter.value());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// load vocabulary
|
// load vocabulary
|
||||||
|
|||||||
@ -94,14 +94,15 @@ QString Settings::iniPath()
|
|||||||
return iniDefaultPath();
|
return iniDefaultPath();
|
||||||
}
|
}
|
||||||
|
|
||||||
void Settings::init(const QString & fileName)
|
ParametersMap Settings::init(const QString & fileName)
|
||||||
{
|
{
|
||||||
iniPath_ = fileName;
|
iniPath_ = fileName;
|
||||||
loadSettings(iniPath_);
|
return loadSettings(iniPath_);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Settings::loadSettings(const QString & fileName)
|
ParametersMap Settings::loadSettings(const QString & fileName)
|
||||||
{
|
{
|
||||||
|
ParametersMap loadedParameters;
|
||||||
QString path = fileName;
|
QString path = fileName;
|
||||||
if(fileName.isEmpty())
|
if(fileName.isEmpty())
|
||||||
{
|
{
|
||||||
@ -173,6 +174,7 @@ void Settings::loadSettings(const QString & fileName)
|
|||||||
value = QVariant(str);
|
value = QVariant(str);
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
loadedParameters.insert(key, value);
|
||||||
setParameter(key, value);
|
setParameter(key, value);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -193,6 +195,7 @@ void Settings::loadSettings(const QString & fileName)
|
|||||||
Settings::setFeature2D_ORB_gpu(false);
|
Settings::setFeature2D_ORB_gpu(false);
|
||||||
Settings::setNearestNeighbor_BruteForce_gpu(false);
|
Settings::setNearestNeighbor_BruteForce_gpu(false);
|
||||||
}
|
}
|
||||||
|
return loadedParameters;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Settings::loadWindowSettings(QByteArray & windowGeometry, QByteArray & windowState, const QString & fileName)
|
void Settings::loadWindowSettings(QByteArray & windowGeometry, QByteArray & windowState, const QString & fileName)
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user