[OpenCV] Background subtraction

Posted 机器学习水很深

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了[OpenCV] Background subtraction相关的知识,希望对你有一定的参考价值。

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

运行结果:

没毛病!

 

以上是关于[OpenCV] Background subtraction的主要内容,如果未能解决你的问题,请参考以下文章

openCV 2.4.13 iOS background_segm.hpp 'list' file not found

iOS 上的 OpenCv 2.4.7 错误 background_segm.hpp #include <list> not found

OpenCV版本4.1.0 drawContours

Build OpenCV text(OCR) module on windows

背景减法器MOG2 & OpenCV

怎样使用OpenCV进行人脸识别