Created
June 8, 2017 08:33
-
-
Save dboyliao/63beda125afe9279159dee61356fa701 to your computer and use it in GitHub Desktop.
OpenCV CommandLineParser Example
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* Adapt from this example: http://docs.opencv.org/3.0-beta/modules/core/doc/command_line_parser.html | |
*/ | |
#include "opencv2/core.hpp" | |
#include "opencv2/core/cvstd.hpp" // cv::String | |
#include <iostream> | |
using namespace cv; | |
using std::cout; | |
using std::cerr; | |
using std::endl; | |
int main(int argc, char* argv[]) | |
{ | |
String keys = | |
"{help h usage ? | | print this message }" | |
"{@image1 | | image1 for compare }" | |
"{@image2 | | image2 for compare }" | |
"{@repeat |1 | number }" | |
"{path |. | path to file }" | |
"{fps | -1.0 | fps for output video }" | |
"{N count |100 | count of objects }" | |
"{ts timestamp | | use time stamp }"; | |
CommandLineParser parser(argc, argv, keys); | |
parser.about("Trying OpenCV commandline parser"); | |
if (parser.has("help")) | |
{ | |
parser.printMessage(); | |
return 0; | |
} | |
int N = parser.get<int>("N"); | |
double fps = parser.get<double>("fps"); | |
String path = parser.get<String>("path"); | |
bool use_time_stamp = parser.has("timestamp"); | |
String img1 = parser.get<String>(0); | |
String img2 = parser.get<String>(1); | |
int repeat = parser.get<int>(2); | |
if (!parser.check()) | |
{ | |
parser.printErrors(); | |
return 1; | |
} | |
if (img1 == "" || img2 == "") { | |
cerr << "Missing img1 or img2" << endl; | |
parser.printMessage(); | |
return 1; | |
} | |
cout << img1 << endl; | |
cout << img2 << endl; | |
cout << repeat << endl; | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment