-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcla_parse.cpp
57 lines (48 loc) · 1.45 KB
/
cla_parse.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
// cla_parse.cpp : Parse given command line arguments.
// Austin Hester CS542o nov 2020
// g++.exe (x86_64-posix-seh-rev0, Built by MinGW-W64 project) 8.1.0
#include <opencv2/core/core.hpp>
#include "./include/cla_parse.hpp"
// parse command line arguments
int
parse_arguments(
int argc,
const char** argv,
std::string* input_image,
bool* grayscale
) {
cv::String keys =
"{@filename |<none>| input image}" // input image is the first argument (positional)
"{help h | | show help message}";
if (grayscale != NULL)
keys += "{grayscale g | | read grayscale}";
cv::CommandLineParser parser(argc, argv, keys);
if (parser.has("h")) {
parser.printMessage();
return 0;
}
if (!parser.check()) {
parser.printErrors();
parser.printMessage();
return -1;
}
try {
*input_image = (std::string) parser.get<std::string>(0).c_str();
if (input_image == NULL || input_image->size() == 0) {
parser.printMessage();
return -1;
}
} catch (...) {
std::cerr << "Failed to parse input image argument!:" << std::endl;
return -1;
}
if (grayscale != NULL) {
try {
*grayscale = (bool) parser.has("g") ? true : false;
} catch (...) {
std::cerr << "Failed to parse grayscale argument." << std::endl;
return -1;
}
}
return 1;
}