[C++][原创]opencv中CommandLineParser使用
Posted FL1623863129
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了[C++][原创]opencv中CommandLineParser使用相关的知识,希望对你有一定的参考价值。
#include <iostream>
#include <string>
#include <sstream>
#include <opencv2/core.hpp>
#include <opencv2/highgui.hpp>
#include <opencv2/videoio.hpp>
#include <opencv2/opencv.hpp>
using namespace std;
using namespace cv;
const char* keys =
"help h usage ? | | print this message"
"@video | | Video file, if not defined try to use webcamera"
"@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 "
;
int main(int argc, const char** argv) //程序主函数
CommandLineParser parser(argc, argv, keys);
parser.about("Video Capture");
if (parser.has("help")) //帮助信息
parser.printMessage();
return 0;
String videoFile = parser.get<String>(0);
std::cout << videoFile << std::endl;
int N = parser.get<int>("N");
double fps = parser.get<double>("fps");
String path = parser.get<String>("path");
std::cout << path << std::endl;
auto use_time_stamp = parser.has("timestamp");
return 0;
理解:
(1)参数里面有@就是按参数索引获取,比如@video.命令行输入main.exe D:\\car.mp4这样不用参数修饰符
(2)参数没有@要加修饰符,比如main.exe --path D:\\car.mp4这样需要加--path修饰符这样就可以解析到对应参数
参考文献:CommandLineParser类(命令行解析类)_Alba_126的博客-CSDN博客_commandlineparser
以上是关于[C++][原创]opencv中CommandLineParser使用的主要内容,如果未能解决你的问题,请参考以下文章
[opencv][原创]python opencv创建白色图像并画个框