Skip to content

Commit

Permalink
Merge pull request #160 from alicevision/dev/detection
Browse files Browse the repository at this point in the history
[apps] improved detection app
  • Loading branch information
simogasp authored May 15, 2021
2 parents cad8271 + 410d951 commit 6f9fa2a
Show file tree
Hide file tree
Showing 5 changed files with 499 additions and 454 deletions.
5 changes: 0 additions & 5 deletions src/applications/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -117,9 +117,4 @@ add_executable(simulation ${CCTagSimulation_cpp})
target_include_directories(simulation PUBLIC ${OpenCV_INCLUDE_DIRS})
target_link_libraries(simulation PUBLIC ${OpenCV_LIBS})

foreach(_app detection regression simulation)
set_target_properties(${_app} PROPERTIES VERSION ${PROJECT_VERSION})
set_target_properties(${_app} PROPERTIES DEBUG_POSTFIX "d")
endforeach()

install(TARGETS detection regression simulation DESTINATION ${CMAKE_INSTALL_BINDIR})
123 changes: 60 additions & 63 deletions src/applications/detection/CmdLine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,90 +15,87 @@
namespace cctag {


CmdLine::CmdLine( )
: _filename( "" )
, _nRings( 0 )
, _cctagBankFilename( "" )
, _paramsFilename( "" )
, _outputFolderName( "" )
#ifdef CCTAG_WITH_CUDA
, _switchSync( false )
, _debugDir( "" )
, _useCuda( false )
, _parallel( 1 )
#endif
, _allParams("Program for detecting CCTags in images or in a video")
{
using namespace boost::program_options;
CmdLine::CmdLine( ) :
_allParams("Program for detecting CCTags in one image, in a directory or in a video\n"
"For each image or video frame it detects the markers and it shows the image with a graphical overlay"
"showing the center of the tag, its ID and the outer ellipse")
{
using namespace boost::program_options;

options_description required("Required input parameters");
required.add_options()
("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...)")
("nbrings,n", value<std::size_t>(&_nRings)->required(), "Number of rings of the CCTags to detect");
options_description required("Required input parameters");
required.add_options()
("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...) or to a directory containing the images to process")
("nbrings,n", value<std::size_t>(&_nRings)->required(), "Number of rings of the CCTags to detect");

options_description optional("Optional parameters");
optional.add_options()
("bank,b", value<std::string>(&_cctagBankFilename)->default_value(_cctagBankFilename), "Path to a bank parameter file, e.g. 4Crowns/ids.txt")
("params,p", value<std::string>(&_paramsFilename)->default_value(_paramsFilename), "Path to configuration XML file")
("output,o", value<std::string>(&_outputFolderName)->default_value(_outputFolderName), "Output folder name")
options_description optional("Optional parameters");
optional.add_options()
("bank,b", value<std::string>(&_cctagBankFilename)->default_value(_cctagBankFilename), "Path to a bank parameter file, e.g. 4Crowns/ids.txt")
("params,p", value<std::string>(&_paramsFilename)->default_value(_paramsFilename), "Path to configuration XML file")
("output,o", value<std::string>(&_outputFolderName)->default_value(_outputFolderName), "Output folder name")
("save-detected-image,s", bool_switch(&_saveDetectedImage), "Save an image with the graphical overlay of the detected tags. "
"For single images the saved images will have a '_detected' suffix and it will be placed either in "
"the current directory or in the directory given by --output. For videos a file named #####.png "
"will be saved instead with the #s representing the zero-padded frame number, either in the current directory "
"or in the directory given by --output.")
("show-unreliable,u", bool_switch(&_showUnreliableDetections), "Show the unreliable tags (marker id = -1)")
#ifdef CCTAG_WITH_CUDA
("sync", bool_switch(&_switchSync), "CUDA debug option, run all CUDA ops synchronously")
("use-cuda", bool_switch(&_useCuda), "Select GPU code instead of CPU code")
("debug-dir", value<std::string>(&_debugDir)->default_value(_debugDir), "Path storing image to debug intermediate GPU results")
("parallel", value<int>(&_parallel)->default_value(_parallel), "Use <n> CUDA pipes concurrently (default 1)")
("sync", bool_switch(&_switchSync), "CUDA debug option, run all CUDA ops synchronously")
("use-cuda", bool_switch(&_useCuda), "Select GPU code instead of CPU code")
("debug-dir", value<std::string>(&_debugDir)->default_value(_debugDir), "Path storing image to debug intermediate GPU results")
("parallel", value<int>(&_parallel)->default_value(_parallel), "Use <n> CUDA pipes concurrently (default 1)")
#endif
;
;

_allParams.add(required).add(optional);
_allParams.add(required).add(optional);
}

bool CmdLine::parse( int argc, char* argv[] )
bool CmdLine::parse(int argc, char* argv[])
{
using namespace boost::program_options;

using namespace boost::program_options;

variables_map vm;
try
{
store(parse_command_line(argc, argv, _allParams), vm);
if (vm.count("help") || (argc == 1))
{
return false;
}
notify(vm);
}
catch (const std::exception& e)
{
std::cout << e.what() << std::endl;
return false;
}
variables_map vm;
try
{
store(parse_command_line(argc, argv, _allParams), vm);
if(vm.count("help") || (argc == 1))
{
return false;
}
notify(vm);
}
catch(const std::exception& e)
{
std::cout << e.what() << std::endl;
return false;
}
return true;
}

void CmdLine::print( const char* const argv0 )
void CmdLine::print(const char* const argv0) const
{
std::cout << "You called " << argv0 << " with:" << std::endl
<< " --input " << _filename << std::endl
<< " --nbrings " << _nRings << std::endl
<< " --bank " << _cctagBankFilename << std::endl
<< " --params " << _paramsFilename << std::endl
<< " --output " << _outputFolderName << std::endl;
<< " --input " << _filename << std::endl
<< " --nbrings " << _nRings << std::endl
<< " --bank " << _cctagBankFilename << std::endl
<< " --params " << _paramsFilename << std::endl
<< " --output " << _outputFolderName << std::endl;
if(_saveDetectedImage)
std::cout << " --save-detected-image" << std::endl;
if(_showUnreliableDetections)
std::cout << " --show-unreliable" << std::endl;
#ifdef CCTAG_WITH_CUDA
std::cout << " --parallel " << _parallel << std::endl;
if( _switchSync )
std::cout << " --parallel " << _parallel << std::endl;
if(_switchSync)
std::cout << " --sync " << std::endl;
if( _debugDir != "" )
if(!_debugDir.empty())
std::cout << " --debug-dir " << _debugDir << std::endl;
if( _useCuda )
if(_useCuda)
std::cout << " --use-cuda " << std::endl;
#endif
std::cout << std::endl;
}

void CmdLine::usage( const char* const argv0 )
{
std::cout << _allParams << std::endl;
}
void CmdLine::usage(const char* const argv0) const { std::cout << _allParams << std::endl; }

}

38 changes: 20 additions & 18 deletions src/applications/detection/CmdLine.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,36 +7,38 @@
*/
#pragma once

#include <string>
#include <boost/program_options.hpp>

#include <string>

namespace cctag {

class CmdLine
{
public:
std::string _filename;
std::string _cctagBankFilename;
std::string _paramsFilename;
std::size_t _nRings;
std::string _outputFolderName;
public:
std::string _filename{};
std::string _cctagBankFilename{};
std::string _paramsFilename{};
std::size_t _nRings{3};
std::string _outputFolderName{};
bool _saveDetectedImage{false};
bool _showUnreliableDetections{false};
#ifdef CCTAG_WITH_CUDA
bool _switchSync;
std::string _debugDir;
bool _useCuda;
int _parallel;
bool _switchSync{false};
std::string _debugDir{};
bool _useCuda{false};
int _parallel{1};
#endif

CmdLine( );
CmdLine();

bool parse( int argc, char* argv[] );
void print( const char* const argv0 );
bool parse(int argc, char* argv[]);
void print(const char* const argv0) const;

void usage( const char* const argv0 );
void usage(const char* const argv0) const;

private:
boost::program_options::options_description _allParams;
private:
boost::program_options::options_description _allParams;
};

}

Loading

0 comments on commit 6f9fa2a

Please sign in to comment.