From 8b5056d208658bc80a1a4f79b85c09b7614abc47 Mon Sep 17 00:00:00 2001 From: matlabbe Date: Tue, 5 Aug 2014 18:52:31 +0000 Subject: [PATCH] added --My/Parameter and --params options to find_object app git-svn-id: http://find-object.googlecode.com/svn/trunk/find_object@376 620bd6b2-0a58-f614-fd9a-1bd335dccda9 --- app/main.cpp | 73 ++++++++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 65 insertions(+), 8 deletions(-) diff --git a/app/main.cpp b/app/main.cpp index dfb1908e..74fb9e8f 100644 --- a/app/main.cpp +++ b/app/main.cpp @@ -1,6 +1,8 @@ #include #include #include +#include +#include #include "find_object/MainWindow.h" #include "find_object/Settings.h" #include "find_object/FindObject.h" @@ -67,16 +69,20 @@ void showUsage() " find_object [options]\n" #endif "Options:\n" - " --console Don't use the GUI (by default the camera will be\n" - " started automatically). Option --objects must also be\n" - " used with valid objects.\n" - " --objects \"path\" Directory of the objects to detect.\n" - " --config \"path\" Path to configuration file (default: %s).\n" - " --scene \"path\" Path to a scene image file.\n" - " --help Show usage.\n", Settings::iniDefaultPath().toStdString().c_str()); + " --console Don't use the GUI (by default the camera will be\n" + " started automatically). Option --objects must also be\n" + " used with valid objects.\n" + " --objects \"path\" Directory of the objects to detect.\n" + " --config \"path\" Path to configuration file (default: %s).\n" + " --scene \"path\" Path to a scene image file.\n" + " --params Show all parameters.\n" + " --My/Parameter \"value\" Set find-Object's parameter (look --params for parameters' name).\n" + " It will override the one in --config. Example to set 4 threads:\n" + " $ find_object --General/threads 4\n" + " --help Show usage.\n", Settings::iniDefaultPath().toStdString().c_str()); if(JsonWriter::available()) { - printf(" --json \"path\" Path to an output JSON file (only in --console mode with --scene).\n"); + printf(" --json \"path\" Path to an output JSON file (only in --console mode with --scene).\n"); } exit(-1); } @@ -96,6 +102,7 @@ int main(int argc, char* argv[]) QString scenePath = ""; QString configPath = Settings::iniDefaultPath(); QString jsonPath; + ParametersMap customParameters; for(int i=1; i 2) + { + //strip the "--" + name.remove(0, 2); + if(parameters.contains(name)) + { + ++i; + if(i < argc) + { + customParameters.insert(name, argv[i]); + } + else + { + showUsage(); + } + continue; + } + } UERROR("Unrecognized option : %s", argv[i]); showUsage(); @@ -215,6 +262,10 @@ int main(int argc, char* argv[]) { UINFO(" JSON path: \"%s\"", jsonPath.toStdString().c_str()); } + for(ParametersMap::iterator iter= customParameters.begin(); iter!=customParameters.end(); ++iter) + { + UINFO(" Param \"%s\"=\"%s\"", iter.key().toStdString().c_str(), iter.value().toString().toStdString().c_str()); + } ////////////////////////// // parse options END @@ -223,6 +274,12 @@ int main(int argc, char* argv[]) // Load settings, should be loaded before creating other objects Settings::init(configPath); + // Override custom parameters: + for(ParametersMap::iterator iter= customParameters.begin(); iter!=customParameters.end(); ++iter) + { + Settings::setParameter(iter.key(), iter.value()); + } + // Create FindObject FindObject * findObject = new FindObject();