学习记录
树莓派3B opencv命令行解析器commandlineparser用法
环境
- 树莓派3B
- OpenCV 3.4.1
示例代码
命令行解析器接收的键值
// OpenCV command line parser functions
// Keys accecpted by command line parser
const char* keys =
{
"{help h usage ? | | print this message}"
"{@image || Image to process}"
"{@lightPattern || Image light pattern to apply to image input}"
"{lightMethod | 1 | Method to remove backgroun light, 0 differenec, 1 div, 2 no light removal' }"
"{segMethod | 1 | Method to segment: 1 connected Components, 2 connectec components with stats, 3 find Contours }"
};
解析过程
CommandLineParser parser(argc, argv, keys);
parser.about("Chapter 5. PhotoTool v1.0.0");
//If requires help show
if (parser.has("help"))
{
parser.printMessage();
return 0;
}
String img_file= parser.get<String>(0);
String light_pattern_file= parser.get<String>(1);
int method_light= parser.get<int>("lightMethod");
int method_seg= parser.get<int>("segMethod");
// Check if params are correctly parsed in his variables
if (!parser.check())
{
parser.printErrors();
return 0;
}
用法
./Process -h
查看帮助
./Process ../data/test_noise.pgm ../data/light.pgm -lightMethod=2 -segMethod=3
关键字 | 内容 |
---|---|
img_file | …/data/test_noise.pgm |
light_pattern_file | …/data/light.pgm |
method_light | -lightMethod=2 |
method_seg | -segMethod=3 |