[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

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

码农张三疯

你的打赏是我写文章最大的动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值