|
15 | 15 | namespace cctag { |
16 | 16 |
|
17 | 17 |
|
18 | | -CmdLine::CmdLine( ) |
19 | | - : _filename( "" ) |
20 | | - , _nRings( 0 ) |
21 | | - , _cctagBankFilename( "" ) |
22 | | - , _paramsFilename( "" ) |
23 | | - , _outputFolderName( "" ) |
24 | | -#ifdef CCTAG_WITH_CUDA |
25 | | - , _switchSync( false ) |
26 | | - , _debugDir( "" ) |
27 | | - , _useCuda( false ) |
28 | | - , _parallel( 1 ) |
29 | | -#endif |
30 | | - , _allParams("Program for detecting CCTags in images or in a video") |
31 | | -{ |
32 | | - using namespace boost::program_options; |
| 18 | +CmdLine::CmdLine( ) : |
| 19 | + _allParams("Program for detecting CCTags in one image, in a directory or in a video\n" |
| 20 | + "For each image or video frame it detects the markers and it shows the image with a graphical overlay" |
| 21 | + "showing the center of the tag, its ID and the outer ellipse") |
| 22 | +{ |
| 23 | + using namespace boost::program_options; |
33 | 24 |
|
34 | | - options_description required("Required input parameters"); |
35 | | - required.add_options() |
36 | | - ("input,i", value<std::string>(&_filename)->required(), "Path to an image (JPG, PNG) or video (avi, mov) or camera index for live capture (0, 1...)") |
37 | | - ("nbrings,n", value<std::size_t>(&_nRings)->required(), "Number of rings of the CCTags to detect"); |
| 25 | + options_description required("Required input parameters"); |
| 26 | + required.add_options() |
| 27 | + ("input,i", value<std::string>(&_filename)->required(), "Path to an image (JPG, PNG) or video (avi, mov) " |
| 28 | + "or camera index for live capture (0, 1...) or to a directory containing the images to process") |
| 29 | + ("nbrings,n", value<std::size_t>(&_nRings)->required(), "Number of rings of the CCTags to detect"); |
38 | 30 |
|
39 | | - options_description optional("Optional parameters"); |
40 | | - optional.add_options() |
41 | | - ("bank,b", value<std::string>(&_cctagBankFilename)->default_value(_cctagBankFilename), "Path to a bank parameter file, e.g. 4Crowns/ids.txt") |
42 | | - ("params,p", value<std::string>(&_paramsFilename)->default_value(_paramsFilename), "Path to configuration XML file") |
43 | | - ("output,o", value<std::string>(&_outputFolderName)->default_value(_outputFolderName), "Output folder name") |
| 31 | + options_description optional("Optional parameters"); |
| 32 | + optional.add_options() |
| 33 | + ("bank,b", value<std::string>(&_cctagBankFilename)->default_value(_cctagBankFilename), "Path to a bank parameter file, e.g. 4Crowns/ids.txt") |
| 34 | + ("params,p", value<std::string>(&_paramsFilename)->default_value(_paramsFilename), "Path to configuration XML file") |
| 35 | + ("output,o", value<std::string>(&_outputFolderName)->default_value(_outputFolderName), "Output folder name") |
| 36 | + ("save-detected-image,s", bool_switch(&_saveDetectedImage), "Save an image with the graphical overlay of the detected tags. " |
| 37 | + "For single images the saved images will have a '_detected' suffix and it will be placed either in " |
| 38 | + "the current directory or in the directory given by --output. For videos a file named #####.png " |
| 39 | + "will be saved instead with the #s representing the zero-padded frame number, either in the current directory " |
| 40 | + "or in the directory given by --output.") |
| 41 | + ("show-unreliable,u", bool_switch(&_showUnreliableDetections), "Show the unreliable tags (marker id = -1)") |
44 | 42 | #ifdef CCTAG_WITH_CUDA |
45 | | - ("sync", bool_switch(&_switchSync), "CUDA debug option, run all CUDA ops synchronously") |
46 | | - ("use-cuda", bool_switch(&_useCuda), "Select GPU code instead of CPU code") |
47 | | - ("debug-dir", value<std::string>(&_debugDir)->default_value(_debugDir), "Path storing image to debug intermediate GPU results") |
48 | | - ("parallel", value<int>(&_parallel)->default_value(_parallel), "Use <n> CUDA pipes concurrently (default 1)") |
| 43 | + ("sync", bool_switch(&_switchSync), "CUDA debug option, run all CUDA ops synchronously") |
| 44 | + ("use-cuda", bool_switch(&_useCuda), "Select GPU code instead of CPU code") |
| 45 | + ("debug-dir", value<std::string>(&_debugDir)->default_value(_debugDir), "Path storing image to debug intermediate GPU results") |
| 46 | + ("parallel", value<int>(&_parallel)->default_value(_parallel), "Use <n> CUDA pipes concurrently (default 1)") |
49 | 47 | #endif |
50 | | - ; |
| 48 | + ; |
51 | 49 |
|
52 | | - _allParams.add(required).add(optional); |
| 50 | + _allParams.add(required).add(optional); |
53 | 51 | } |
54 | 52 |
|
55 | | -bool CmdLine::parse( int argc, char* argv[] ) |
| 53 | +bool CmdLine::parse(int argc, char* argv[]) |
56 | 54 | { |
| 55 | + using namespace boost::program_options; |
57 | 56 |
|
58 | | - using namespace boost::program_options; |
59 | | - |
60 | | - variables_map vm; |
61 | | - try |
62 | | - { |
63 | | - store(parse_command_line(argc, argv, _allParams), vm); |
64 | | - if (vm.count("help") || (argc == 1)) |
65 | | - { |
66 | | - return false; |
67 | | - } |
68 | | - notify(vm); |
69 | | - } |
70 | | - catch (const std::exception& e) |
71 | | - { |
72 | | - std::cout << e.what() << std::endl; |
73 | | - return false; |
74 | | - } |
| 57 | + variables_map vm; |
| 58 | + try |
| 59 | + { |
| 60 | + store(parse_command_line(argc, argv, _allParams), vm); |
| 61 | + if(vm.count("help") || (argc == 1)) |
| 62 | + { |
| 63 | + return false; |
| 64 | + } |
| 65 | + notify(vm); |
| 66 | + } |
| 67 | + catch(const std::exception& e) |
| 68 | + { |
| 69 | + std::cout << e.what() << std::endl; |
| 70 | + return false; |
| 71 | + } |
75 | 72 | return true; |
76 | 73 | } |
77 | 74 |
|
78 | | -void CmdLine::print( const char* const argv0 ) |
| 75 | +void CmdLine::print(const char* const argv0) const |
79 | 76 | { |
80 | 77 | std::cout << "You called " << argv0 << " with:" << std::endl |
81 | | - << " --input " << _filename << std::endl |
82 | | - << " --nbrings " << _nRings << std::endl |
83 | | - << " --bank " << _cctagBankFilename << std::endl |
84 | | - << " --params " << _paramsFilename << std::endl |
85 | | - << " --output " << _outputFolderName << std::endl; |
| 78 | + << " --input " << _filename << std::endl |
| 79 | + << " --nbrings " << _nRings << std::endl |
| 80 | + << " --bank " << _cctagBankFilename << std::endl |
| 81 | + << " --params " << _paramsFilename << std::endl |
| 82 | + << " --output " << _outputFolderName << std::endl; |
| 83 | + if(_saveDetectedImage) |
| 84 | + std::cout << " --save-detected-image" << std::endl; |
| 85 | + if(_showUnreliableDetections) |
| 86 | + std::cout << " --show-unreliable" << std::endl; |
86 | 87 | #ifdef CCTAG_WITH_CUDA |
87 | | - std::cout << " --parallel " << _parallel << std::endl; |
88 | | - if( _switchSync ) |
| 88 | + std::cout << " --parallel " << _parallel << std::endl; |
| 89 | + if(_switchSync) |
89 | 90 | std::cout << " --sync " << std::endl; |
90 | | - if( _debugDir != "" ) |
| 91 | + if(!_debugDir.empty()) |
91 | 92 | std::cout << " --debug-dir " << _debugDir << std::endl; |
92 | | - if( _useCuda ) |
| 93 | + if(_useCuda) |
93 | 94 | std::cout << " --use-cuda " << std::endl; |
94 | 95 | #endif |
95 | 96 | std::cout << std::endl; |
96 | 97 | } |
97 | 98 |
|
98 | | -void CmdLine::usage( const char* const argv0 ) |
99 | | -{ |
100 | | - std::cout << _allParams << std::endl; |
101 | | -} |
| 99 | +void CmdLine::usage(const char* const argv0) const { std::cout << _allParams << std::endl; } |
102 | 100 |
|
103 | 101 | } |
104 | | - |
0 commit comments