34 #include <opencv2/highgui/highgui.hpp> 36 using namespace aruco;
45 pair< double, double >
AvrgTime(0, 0);
48 class CmdLineParser{
int argc;
char **argv;
public:
CmdLineParser(
int _argc,
char **_argv):argc(_argc),argv(_argv){}
bool operator[] (
string param ) {
int idx=-1;
for (
int i=0; i<argc && idx==-1; i++ )
if (
string ( argv[i] ) ==param ) idx=i;
return ( idx!=-1 ) ; }
string operator()(
string param,
string defvalue=
"-1"){
int idx=-1;
for (
int i=0; i<argc && idx==-1; i++ )
if (
string ( argv[i] ) ==param ) idx=i;
if ( idx==-1 )
return defvalue;
else return ( argv[ idx+1] ); }};
58 int main(
int argc,
char **argv) {
61 if (argc < 2 || cml[
"-h"]) {
62 cerr <<
"Invalid number of arguments" << endl;
63 cerr <<
"Usage: (in.avi|live[:idx_cam=0]) [-c camera_params.yml] [-s marker_size_in_meters] [-d dictionary:ARUCO by default] [-h]" << endl;
77 if (TheInputVideo.find(
"live") != string::npos) {
81 if (TheInputVideo.find(
":") != string::npos) {
82 std::replace(TheInputVideo.begin(), TheInputVideo.end(),
':',
' ');
83 sscanf(TheInputVideo.c_str(),
"%s %d", cad, &vIdx);
85 cout <<
"Opening camera index " << vIdx << endl;
91 if (!
TheVideoCapturer.isOpened())
throw std::runtime_error(
"Could not open video");
97 if (TheCameraParameters.
isValid())
98 TheCameraParameters.
resize(TheInputImage.size());
106 cv::namedWindow(
"in");
118 double tick = (double)getTickCount();
120 TheMarkers= MDetector.
detect(TheInputImage, TheCameraParameters, TheMarkerSize);
122 AvrgTime.first += ((double)getTickCount() - tick) / getTickFrequency();
124 cout <<
"\rTime detection=" << 1000 *
AvrgTime.first /
AvrgTime.second <<
" milliseconds nmarkers=" <<
TheMarkers.size() << std::endl;
129 for (
unsigned int i = 0; i <
TheMarkers.size(); i++) {
135 if (TheCameraParameters.
isValid() && TheMarkerSize>0)
136 for (
unsigned int i = 0; i <
TheMarkers.size(); i++) {
152 }
catch (std::exception &ex)
155 cout <<
"Exception :" << ex.what() << endl;
174 for (
unsigned int i = 0; i <
TheMarkers.size(); i++)
178 if (TheCameraParameters.
isValid())
179 for (
unsigned int i = 0; i <
TheMarkers.size(); i++)
void setThresholdParams(double param1, double param2)
bool param(const std::string ¶m_name, T ¶m_val, const T &default_val)
void resize(cv::Size size)
int main(int argc, char **argv)
static std::vector< std::string > getDicTypes()
void setDictionary(std::string dict_type, float error_correction_rate=0)
std::vector< aruco::Marker > detect(const cv::Mat &input)
void cvTackBarEvents(int pos, void *)
void readFromXMLFile(string filePath)
void setThresholdParamRange(size_t r1=0, size_t r2=0)
CameraParameters TheCameraParameters
vector< Marker > TheMarkers
Main class for marker detection.
const cv::Mat & getThresholdedImage()
Parameters of the camera.
pair< double, double > AvrgTime(0, 0)
VideoCapture TheVideoCapturer