[OpenCV] Background subtraction

时间:2023-03-09 02:42:33
[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:

  $ ./my-app -N=
# or
$ ./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 ;
}
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>();
cout << "img1: " << img1 << endl;
string img2 = parser.get<string>();
cout << "img2: " << img2 << endl;
int repeat = parser.get<int>();
cout << "repeat: " << repeat << endl;
if (!parser.check())
{
parser.printErrors();
return ;
}

运行结果:

[OpenCV] Background subtraction

没毛病!