[OpenCV] Samples 13: opencv_version

cv::CommandLineParser的使用。

I suppose CommandLineParser::has("something") should be true when the command line has --something in it.

./a.out -h
./a.out --help

打印keys的相关内容。

#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;
}

  

一个更好的例子

For example, define:

String keys = "{N count||}";

Call:

 1 $ ./my-app -N=20
 2 # or
 3 $ ./my-app --count=20  // 注意等号的应用

Keys赋值:

const string keys =
    "{help h usage ? |      | print this message   }"
    "{@image1        |      | image1 for compare   }"
    "{@image2        |<none>| image2 for compare   }"
    "{@repeat        |1     | number               }"
    "{path           |/home/unsw     | path to file         }"
    "{fps            | -1.0 | fps for output video }"
    "{N count        |100   | count of objects     }"
    "{ts timestamp   |      | use time stamp       }"
    ;

如此解析:

    cv::CommandLineParser parser(argc, argv, keys);
    parser.about("Application name v1.0.0");
    if (parser.has("help"))
    {
        parser.printMessage();
        return 0;
    }
    int N = parser.get<int>("N");
    cout << "N = " << N << endl;
    double fps = parser.get<double>("fps");
    string path = parser.get<string>("path");
    cout << "path: " << path << endl;
    time_t use_time_stamp = parser.has("timestamp");
    string img1 = parser.get<string>(0);
    cout << "img1: " << img1 << endl;
    string img2 = parser.get<string>(1);
    cout << "img2: " << img2 << endl;
    int repeat = parser.get<int>(2);
    cout << "repeat: " << repeat << endl;
    if (!parser.check())
    {
        parser.printErrors();
        return 0;
    }

运行结果:

没毛病!

时间: 2024-12-28 23:43:06

[OpenCV] Samples 13: opencv_version的相关文章

[OpenCV] Samples 10: imagelist_creator

yaml写法的简单例子.将 $ ./ 1 2 3 4 5 命令的参数(代表图片地址)写入yaml中. 写yaml文件. 参考:[OpenCV] Samples 06: [ML] logistic regression 读xml文件. { /* * Jeff --> Load xml. * transform to Mat. * FileStorage. */ cout << "loading the dataset..."; // Step 1. FileStorag

[OpenCV] Samples 05: convexhull

得到了复杂轮廓往往不适合特征的检测,这里再介绍一个点集凸包络的提取函数convexHull,输入参数就可以是contours组中的一个轮廓,返回外凸包络的点集 ---- 如此就能去掉凹进去的边. 对于凸包算法,其中最有名的莫过于Graham扫描算法,它的复杂度为nlog(n) 参考:计算几何之凸包(Algorithm show), 寻找轮廓 高级:Snake模型在轮廓提取中的应用 cvSnakeImage() #include "opencv2/imgproc/imgproc.hpp"

[OpenCV] Samples 04: contours2

要先变为二值图像:cvThreshold 提取轮廓:cvFindContours #include "opencv2/imgproc/imgproc.hpp" #include "opencv2/highgui/highgui.hpp" #include <math.h> #include <iostream> using namespace cv; using namespace std; static void help() { cout

颜色空间转换 cvtColor()[OpenCV 笔记13]

void cvtColor(InputArray src, OutputArray dst, int code, int dstCn=0) src: 输入图像 dst: 输出图像 code: 颜色空间转换标识符 OpenCV2的CV_前缀宏命名规范被OpenCV3中的COLOR_式的宏命名前缀取代 注意RGB色彩空间默认通道顺序为BGR 具体可以参考: enum cv::ColorConversionCodes部分 dstCn: 目标图像的通道数,该参数为0时,目标图像根据源图像的通道数和具体操

Android学习七---Hello OpenCV samples

创建一个能够使用OpenCV JavaCameraView的应用程序来了解基于OpenCV java API 的应用程序的开发流程.有了Android的基础,在程序中需要修改的几个地方1.activity_main.xml 2.AndroidManifest.xml 3.MainActivity.java 一.创建项目 安装创建android程序的方式创建一个blank activity,项目名称为hellosamples,其他采用默认的activity_main.xml,MainActivit

[OpenCV] Samples 12: laplace

先模糊再laplace,也可以替换为sobel等. 变换效果后录成视频,挺好玩. #include "opencv2/videoio/videoio.hpp" #include "opencv2/highgui/highgui.hpp" #include "opencv2/imgproc/imgproc.hpp" #include <opencv2/core/utility.hpp> #include <ctype.h>

[OpenCV] Samples 11: image sequence

一帧一帧地读取视频流. VideoCapture sequence(file_video); sequence >> image. #include <opencv2/core/core.hpp> #include <opencv2/videoio/videoio.hpp> #include <opencv2/highgui/highgui.hpp> #include <iostream> using namespace cv; using na

[OpenCV] Samples 07: create_mask

鼠标画线,圈地,构造相关mask图片(黑白). 支持鼠标左键右键中间键点击事件. /* * create_mask.cpp * * Author: * Siddharth Kherada <siddharthkherada27[at]gmail[dot]com> * * This tutorial demonstrates how to make mask image (black and white). * The program takes as input a source image

[OpenCV] Samples 08: edge

Canny edge detector 效率高,效果可控. TrackBar的使用. 技巧:gray找边缘后作为mask去CopyTo(). #include "opencv2/core/utility.hpp" #include "opencv2/imgproc.hpp" #include "opencv2/imgcodecs.hpp" #include "opencv2/highgui.hpp" #include <