-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdriver.cpp
More file actions
78 lines (63 loc) · 2.17 KB
/
Copy pathdriver.cpp
File metadata and controls
78 lines (63 loc) · 2.17 KB
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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
#include "PGMimageProcessor.cpp"
#include <limits>
static void show_usage(std::string name)
{
std::cerr << "Usage: " << name << " [options] <inputPGMfile> \n"
<< "<inputPGMfile> MUST BE a valid PGM image"
<< "Options:\n"
<< "-s <int> <int> (-s min max) ; set the minimum and maximum valid components size "
<< "-t <int> set the threshold for component detection (default=128, limit to [0. . . 255])"
<< "-p print out all the component data and the total component number and the sizes of the smallest and largest components."
<< "-w <outPGMfile> write out all retained components as foreground/background pixels to a new PGM file given by <outPGMfile>"
<< std::endl;
}
int main(int argc, char *argv[]){
if (argc < 3) {
show_usage(argv[0]);
return 1;
}
int min = 3;
int max = std::numeric_limits<int>::max();
int threshold = 128;
bool print = false;
std::string outfilename = "NULL";
std::string imgfilename = argv[1];
for (int i = 2; i < argc; ++i) {
std::string arg = argv[i];
//set the minimum and maximum valid components size
if (arg == "-s") {
//get min
min = std::stoi(argv[i+1]);
//get max if not another flag
if (argv[i+2][1] != '-'){max = std::stoi(argv[i+2]); i++;}
i++;
}
//set threshold
else if (arg == "-t") {
threshold = std::stoi(argv[i+1]);
i++;
}
//print flag
else if (arg == "-p") {
print = true;
}
// write flag
else if (arg == "-w") {
outfilename = argv[i+1];
i++;
}
}
//process the image
HRLISA004::PGMimageProcessor proc(imgfilename,threshold);
proc.extractComponents(128, min, max);
//print components
if (print == true){
// as the total component number and the sizes of the smallest and largest components.
proc.printComponents();
}
//write file
if (outfilename != "NULL"){
proc.writeComponents(outfilename);
}
return 0;
}