The use of Cv::commandlineparser.
I Suppose Commandlineparser::has ("something") should is true when the command line is in --something
it.
./a.out-H. /a.out--help
Print the keys for the relevant content.
#include <opencv2/core/utility.hpp> #include <iostream>using namespace std;const char* keys ={ "{b Build | | Print Complete Build Info} " " {h help | | Print this help } "};int main (int argc, const char* argv[]) { CV: : Commandlineparser parser (ARGC, argv, keys); if (Parser.has ("Help")) { parser.printmessage (); } else if (!parser.check ()) { parser.printerrors (); } else if (Parser.has ("Build")) { std::cout << cv::getbuildinformation () << Std::endl; } else { std::cout << "Welcome to OpenCV" << cv_version << Std::endl; } return 0;}
A better example:
For example, define:
" {Ncount| |} ";
Call:
1 $./my-app-N=23 $./my-app--count= - //Note application of equal sign
keys Assignment:
Const string Keys="{help h usage? | | Print this message}" "{@image1 | | Image1 for Compare}" "{@image2 |<none>| image2 for compare}" "{@repeat | |" "{Path |/HOME/UNSW | path to File}" "{fps | -1.0 | fps for output video}" "{N Count |100 | Count of Objects}" "{ts Timestamp | | Use time stamp}" ;
so parse:
cv::commandlineparser Parser (argc, argv, keys); Parser.about ("Application name v1.0.0"); if(Parser.has (" Help") ) {parser.printmessage (); return 0; } intN = parser.Get<int> ("N"); cout<<"N ="<< N <<Endl; DoubleFPS = parser.Get<Double> ("fps"); stringPath = parser.Get<string> ("Path"); cout<<"Path:"<< Path <<Endl; time_t Use_time_stamp= Parser.has ("timestamp"); stringIMG1 = parser.Get<string> (0); cout<<"IMG1:"<< IMG1 <<Endl; stringIMG2 = parser.Get<string> (1); cout<<"Img2:"<< Img2 <<Endl; intrepeat = parser.Get<int> (2); cout<<"Repeat:"<< Repeat <<Endl; if(!Parser.check ()) {parser.printerrors (); return 0; }
Operation Result:
No problem!
[OpenCV] Samples 13:opencv_version