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)
|
||||
{
|
||||
UASSERT(sharedFindObject != 0);
|
||||
UASSERT(port!=0);
|
||||
UASSERT(threads>=1);
|
||||
|
||||
qRegisterMetaType<cv::Mat>("cv::Mat");
|
||||
@ -87,7 +86,7 @@ public:
|
||||
threadPool_.resize(threads);
|
||||
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)",
|
||||
tcpServer->getPort(),
|
||||
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 objectPath = "";
|
||||
QString scenePath = "";
|
||||
QString configPath = find_object::Settings::iniDefaultPath();
|
||||
QString configPath = "";
|
||||
QString vocabularyPath = "";
|
||||
QString jsonPath;
|
||||
find_object::ParametersMap customParameters;
|
||||
@ -433,9 +433,25 @@ int main(int argc, char* argv[])
|
||||
else
|
||||
{
|
||||
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());
|
||||
}
|
||||
@ -475,14 +491,20 @@ int main(int argc, char* argv[])
|
||||
//////////////////////////
|
||||
|
||||
// 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:
|
||||
for(find_object::ParametersMap::iterator iter= customParameters.begin(); iter!=customParameters.end(); ++iter)
|
||||
{
|
||||
find_object::Settings::setParameter(iter.key(), iter.value());
|
||||
parameters.insert(iter.key(), iter.value());
|
||||
}
|
||||
|
||||
|
||||
// Create FindObject
|
||||
find_object::FindObject * findObject = new find_object::FindObject(guiMode || imagesSaved);
|
||||
|
||||
@ -490,13 +512,7 @@ int main(int argc, char* argv[])
|
||||
int objectsLoaded = 0;
|
||||
if(!sessionPath.isEmpty() && !sessionNew)
|
||||
{
|
||||
if(!vocabularyPath.isEmpty() && !findObject->loadVocabulary(vocabularyPath))
|
||||
{
|
||||
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))
|
||||
if(!findObject->loadSession(sessionPath, parameters))
|
||||
{
|
||||
UERROR("Could not load session \"%s\"", sessionPath.toStdString().c_str());
|
||||
}
|
||||
@ -505,7 +521,12 @@ int main(int argc, char* argv[])
|
||||
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))
|
||||
{
|
||||
@ -536,10 +557,6 @@ int main(int argc, char* argv[])
|
||||
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;
|
||||
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/DetectionInfo.h"
|
||||
#include "find_object/Settings.h"
|
||||
|
||||
#include <QtCore/QObject>
|
||||
#include <QtCore/QString>
|
||||
@ -64,7 +65,7 @@ public:
|
||||
FindObject(bool keepImagesInRAM_ = true, QObject * parent = 0);
|
||||
virtual ~FindObject();
|
||||
|
||||
bool loadSession(const QString & path);
|
||||
bool loadSession(const QString & path, const ParametersMap & customParameters = ParametersMap());
|
||||
bool saveSession(const QString & path);
|
||||
bool isSessionModified() const {return sessionModified_;}
|
||||
|
||||
|
||||
@ -312,9 +312,9 @@ public:
|
||||
static QString iniDefaultFileName() {return "config.ini";}
|
||||
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 saveSettings(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();
|
||||
}
|
||||
|
||||
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)
|
||||
{
|
||||
@ -87,9 +87,17 @@ bool FindObject::loadSession(const QString & path)
|
||||
// load parameters
|
||||
in >> parameters;
|
||||
for(QMap<QString, QVariant>::iterator iter=parameters.begin(); iter!=parameters.end(); ++iter)
|
||||
{
|
||||
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
|
||||
vocabulary_->load(in);
|
||||
|
||||
@ -94,14 +94,15 @@ QString Settings::iniPath()
|
||||
return iniDefaultPath();
|
||||
}
|
||||
|
||||
void Settings::init(const QString & fileName)
|
||||
ParametersMap Settings::init(const QString & 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;
|
||||
if(fileName.isEmpty())
|
||||
{
|
||||
@ -173,6 +174,7 @@ void Settings::loadSettings(const QString & fileName)
|
||||
value = QVariant(str);
|
||||
#endif
|
||||
}
|
||||
loadedParameters.insert(key, value);
|
||||
setParameter(key, value);
|
||||
}
|
||||
}
|
||||
@ -193,6 +195,7 @@ void Settings::loadSettings(const QString & fileName)
|
||||
Settings::setFeature2D_ORB_gpu(false);
|
||||
Settings::setNearestNeighbor_BruteForce_gpu(false);
|
||||
}
|
||||
return loadedParameters;
|
||||
}
|
||||
|
||||
void Settings::loadWindowSettings(QByteArray & windowGeometry, QByteArray & windowState, const QString & fileName)
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user