[OpenCV] Samples 13:opencv_version

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.