OpenCV CommandLineParser 的用法
OpenCV CommandLineParser 的用法
去百度了一下,关键字:OpenCV CommandLineParser 发现,最多的讲解是:opencv源码解析之(5):CommandLineParser类的简单理解 链接:http://www.cnblogs.com/tornadomeet/archive/2012/04/15/2450505.html
// minimalistic foreground-background segmentation sample, based off OpenCV's bgfg_segm sample #include "BackgroundSubtractorSuBSENSE.h" #include <opencv2/core/core.hpp>
#include <opencv2/imgproc/imgproc.hpp>
#include <opencv2/video/background_segm.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <stdio.h> static void help() {
printf("\nMinimalistic example of foreground-background segmentation in a video sequence using\n"
"OpenCV's BackgroundSubtractor interface; will analyze frames from the default camera\n"
"or from a specified file.\n\n"
"Usage: \n"
" ./bgfg_segm [--camera]=<use camera, true/false>, [--file]=<path to file> \n\n");
} const char* keys = {
"{c |camera |true | use camera or not}"
"{f |file |tree.avi | movie file path }"
}; int main(int argc, const char** argv) {
help();
cv::CommandLineParser parser(argc, argv, keys);
const bool bUseDefaultCamera = parser.get<bool>("camera");
const std::string sVideoFilePath = parser.get<std::string>("file");
cv::VideoCapture oVideoInput;
cv::Mat oCurrInputFrame, oCurrSegmMask, oCurrReconstrBGImg;
if(bUseDefaultCamera) {
oVideoInput.open();
oVideoInput >> oCurrInputFrame;
}
else {
oVideoInput.open(sVideoFilePath);
oVideoInput >> oCurrInputFrame;
oVideoInput.set(CV_CAP_PROP_POS_FRAMES,);
}
parser.printParams();
if(!oVideoInput.isOpened() || oCurrInputFrame.empty()) {
if(bUseDefaultCamera)
printf("Could not open default camera.\n");
else
printf("Could not open video file at '%s'.\n",sVideoFilePath.c_str());
return -;
}
oCurrSegmMask.create(oCurrInputFrame.size(),CV_8UC1);
oCurrReconstrBGImg.create(oCurrInputFrame.size(),oCurrInputFrame.type());
cv::Mat oSequenceROI(oCurrInputFrame.size(),CV_8UC1,cv::Scalar_<uchar>()); // for optimal results, pass a constrained ROI to the algorithm (ex: for CDnet, use ROI.bmp)
cv::namedWindow("input",cv::WINDOW_NORMAL);
cv::namedWindow("segmentation mask",cv::WINDOW_NORMAL);
cv::namedWindow("reconstructed background",cv::WINDOW_NORMAL);
BackgroundSubtractorSuBSENSE oBGSAlg;
oBGSAlg.initialize(oCurrInputFrame,oSequenceROI);
for(int k=;;++k) {
oVideoInput >> oCurrInputFrame;
if(oCurrInputFrame.empty())
break;
oBGSAlg(oCurrInputFrame,oCurrSegmMask,double(k<=)); // lower rate in the early frames helps bootstrap the model when foreground is present
oBGSAlg.getBackgroundImage(oCurrReconstrBGImg);
imshow("input",oCurrInputFrame);
imshow("segmentation mask",oCurrSegmMask);
imshow("reconstructed background",oCurrReconstrBGImg);
if(cv::waitKey()==)
break;
}
return ;
}
以下内容出自:http://www.cnblogs.com/tornadomeet/archive/2012/04/15/2450505.html
第一行就是这个类的构造函数,前2个参数是命令行传过来的,第3个就是刚刚定义的keys了,keys的结构有一定规 律,比如说"{c |camera |false | use camera or not}" 都是用大括号和双引号引起来,然后中间的内容分成4断,用”|”分隔开,分别表示简称,文件来源,文件值和帮助语句。第二行和第三行表示打开摄像头和打开 文件,文件的文件名等都在keys指针中了。
最后一行为打印keys中的参数,如下:

大概可以看出来用这个类的好处就是很方便,因为以前版本没这个类时,如果要运行带参数的.exe,必须在命令行中输入文件路径以及各种参数,并且输入的参 数格式要与代码中的if语句判断内容格式一样,一不小心就输错了,很不方便。另外如果想要更改输入格式的话在主函数文件中要相应更改很多地方。现在有了这 个类,只需要改keys里面的内容就可以了,并且运行时可以直接在vs下用F5,不需要cmd命令行带参运行。最后这个类封装了很多函数,可以直接用,只 不过这个本来就是类结构的优点。
---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
OpenCV CommandLineParser 的用法的更多相关文章
- Opencv的imread用法
所有参考来自网上仅仅做学习记录用,具体正确性需要在具体项目各自验证,不涉及具体错误代码处理调试等问题,欢迎发现发现问题~ 参考: 1. https://blog.csdn.net/LiheZhu/ar ...
- opencv matchTemplate函数用法
模板匹配函数,就是在一幅图中,找到另外一幅的在本图的相似的地方 CV_EXPORTS_W void matchTemplate( InputArray image, InputArray templ, ...
- OpenCV成长之路(8):直线、轮廓的提取与描述
基于内容的图像分析的重点是提取出图像中具有代表性的特征,而线条.轮廓.块往往是最能体现特征的几个元素,这篇文章就针对于这几个重要的图像特征,研究它们在OpenCV中的用法,以及做一些简单的基础应用. ...
- OpenCV成长之路:直线、轮廓的提取与描述
http://ronny.blog.51cto.com/8801997/1394139 OpenCV成长之路:直线.轮廓的提取与描述 原创作品,允许转载,转载时请务必以超链接形式标明文章 原始出处 . ...
- libsvm Minist Hog 手写体识别
统计手写数字集的HOG特征 转载请注明出处,楼燚(yì)航的blog,http://www.cnblogs.com/louyihang-loves-baiyan/ 这篇文章是模式识别的小作业,利用sv ...
- OpenCV教程二 - Mat对象与它各种用法
学习OpenCV大家都会遇到一个对象叫做Mat,此对象非常神奇,支持各种操作.很多初学者因此被搞得头晕脑胀,它各种用法太多太杂,搞得初学者应接不暇,感觉有心无力.无处下手之感.这里我们首先要正本清源, ...
- OpenCV中cv2的用法
一.读入图像 使用函数cv2.imread(filepath,flags)读入一副图片 filepath:要读入图片的完整路径 flags:读入图片的标志 cv2.IMREAD_COLOR:默认参数 ...
- opencv学习笔记——cv::CommandLineParser函数详解
命令行解析类CommandLineParser 该类的作用主要用于命令行的解析,也就是分解命令行的作用.以前版本没这个类时,如果要运行带参数的.exe,必须在命令行中输入文件路径以及各种参数,并且输入 ...
- OpenCV 学习笔记03 boundingRect、minAreaRect、minEnclosingCircle、boxPoints、int0、circle、rectangle函数的用法
函数中的代码是部分代码,详细代码在最后 1 cv2.boundingRect 作用:矩形边框(boundingRect),用于计算图像一系列点的外部矩形边界. cv2.boundingRect(arr ...
随机推荐
- Javascript 基础(二)
一.js运算符: +.-.*./.% %(去模 就是计算两个数的余数,通常判断是否能整除),主要用于整数. var a=90; var b=8; if(a%b==0) window.alert(&qu ...
- 《同一个类中不同方法之间的调用相关问题(省略的类名或者this)》
//同一个类中不同方法之间的调用相关问题(省略的类名或者this) class A { public void B() { System.out.println("b方法运行"); ...
- sql server手工注入
sql server手工注入 测试网站testasp.vulnweb.com 1. http://testasp.vulnweb.com/showforum.asp?id=0 http://testa ...
- EditTest输入类型设置
1,当输入为文字性密码时,输入前有提示效果,输入后有遮蔽效果 android:hint="@string/hint_etPassword" android:inputType=&q ...
- LeetCode---- 二叉树中,找出和为某值的所有路径
Given a binary tree and a sum, find all root-to-leaf paths where each path's sum equals the given su ...
- Java custom annotations
Custom annotation definition is similar as Interface, just with @ in front. Annotation interface its ...
- 【LEETCODE OJ】Single Number II
Problem link: http://oj.leetcode.com/problems/single-number-ii/ The problem seems like the Single Nu ...
- Terrible Sets_单调栈
Description Let N be the set of all natural numbers {0 , 1 , 2 , . . . }, and R be the set of all re ...
- 2012开源项目计划-WPF企业级应用整合平台
2012开源项目计划-WPF企业级应用整合平台 开篇 2012年,提前祝大家新年快乐,为了加快2012年的开发计划,特打算年前和大家分享一下2012年的开发计划和年后具体的实施计划,希望有兴趣或者有志 ...
- 创建XML文档结构
static void CreateXML(string outputPath) { XmlDocument _xmlDoc = new XmlDocument(); string _xmlNode ...