Skip to content

Commit 6f9fa2a

Browse files
authored
Merge pull request #160 from alicevision/dev/detection
[apps] improved detection app
2 parents cad8271 + 410d951 commit 6f9fa2a

File tree

5 files changed

+499
-454
lines changed

5 files changed

+499
-454
lines changed

src/applications/CMakeLists.txt

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -117,9 +117,4 @@ add_executable(simulation ${CCTagSimulation_cpp})
117117
target_include_directories(simulation PUBLIC ${OpenCV_INCLUDE_DIRS})
118118
target_link_libraries(simulation PUBLIC ${OpenCV_LIBS})
119119

120-
foreach(_app detection regression simulation)
121-
set_target_properties(${_app} PROPERTIES VERSION ${PROJECT_VERSION})
122-
set_target_properties(${_app} PROPERTIES DEBUG_POSTFIX "d")
123-
endforeach()
124-
125120
install(TARGETS detection regression simulation DESTINATION ${CMAKE_INSTALL_BINDIR})

src/applications/detection/CmdLine.cpp

Lines changed: 60 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -15,90 +15,87 @@
1515
namespace cctag {
1616

1717

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;
3324

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");
3830

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)")
4442
#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)")
4947
#endif
50-
;
48+
;
5149

52-
_allParams.add(required).add(optional);
50+
_allParams.add(required).add(optional);
5351
}
5452

55-
bool CmdLine::parse( int argc, char* argv[] )
53+
bool CmdLine::parse(int argc, char* argv[])
5654
{
55+
using namespace boost::program_options;
5756

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+
}
7572
return true;
7673
}
7774

78-
void CmdLine::print( const char* const argv0 )
75+
void CmdLine::print(const char* const argv0) const
7976
{
8077
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;
8687
#ifdef CCTAG_WITH_CUDA
87-
std::cout << " --parallel " << _parallel << std::endl;
88-
if( _switchSync )
88+
std::cout << " --parallel " << _parallel << std::endl;
89+
if(_switchSync)
8990
std::cout << " --sync " << std::endl;
90-
if( _debugDir != "" )
91+
if(!_debugDir.empty())
9192
std::cout << " --debug-dir " << _debugDir << std::endl;
92-
if( _useCuda )
93+
if(_useCuda)
9394
std::cout << " --use-cuda " << std::endl;
9495
#endif
9596
std::cout << std::endl;
9697
}
9798

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; }
102100

103101
}
104-

src/applications/detection/CmdLine.hpp

Lines changed: 20 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -7,36 +7,38 @@
77
*/
88
#pragma once
99

10-
#include <string>
1110
#include <boost/program_options.hpp>
1211

12+
#include <string>
13+
1314
namespace cctag {
1415

1516
class CmdLine
1617
{
17-
public:
18-
std::string _filename;
19-
std::string _cctagBankFilename;
20-
std::string _paramsFilename;
21-
std::size_t _nRings;
22-
std::string _outputFolderName;
18+
public:
19+
std::string _filename{};
20+
std::string _cctagBankFilename{};
21+
std::string _paramsFilename{};
22+
std::size_t _nRings{3};
23+
std::string _outputFolderName{};
24+
bool _saveDetectedImage{false};
25+
bool _showUnreliableDetections{false};
2326
#ifdef CCTAG_WITH_CUDA
24-
bool _switchSync;
25-
std::string _debugDir;
26-
bool _useCuda;
27-
int _parallel;
27+
bool _switchSync{false};
28+
std::string _debugDir{};
29+
bool _useCuda{false};
30+
int _parallel{1};
2831
#endif
2932

30-
CmdLine( );
33+
CmdLine();
3134

32-
bool parse( int argc, char* argv[] );
33-
void print( const char* const argv0 );
35+
bool parse(int argc, char* argv[]);
36+
void print(const char* const argv0) const;
3437

35-
void usage( const char* const argv0 );
38+
void usage(const char* const argv0) const;
3639

37-
private:
38-
boost::program_options::options_description _allParams;
40+
private:
41+
boost::program_options::options_description _allParams;
3942
};
4043

4144
}
42-

0 commit comments

Comments
 (0)