aruco_create_markermap.cpp
Go to the documentation of this file.
1 /*****************************
2 Copyright 2016 Rafael Muñoz Salinas. All rights reserved.
3 
4 Redistribution and use in source and binary forms, with or without modification, are
5 permitted provided that the following conditions are met:
6 
7  1. Redistributions of source code must retain the above copyright notice, this list of
8  conditions and the following disclaimer.
9 
10  2. Redistributions in binary form must reproduce the above copyright notice, this list
11  of conditions and the following disclaimer in the documentation and/or other materials
12  provided with the distribution.
13 
14 THIS SOFTWARE IS PROVIDED BY Rafael Muñoz Salinas ''AS IS'' AND ANY EXPRESS OR IMPLIED
15 WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
16 FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL Rafael Muñoz Salinas OR
17 CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
18 CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
19 SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
20 ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
21 NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
22 ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
23 
24 The views and conclusions contained in the software and documentation are those of the
25 authors and should not be interpreted as representing official policies, either expressed
26 or implied, of Rafael Muñoz Salinas.
27 ********************************/
28 
29 //Creation of MarkerMap to be printed in a piece of paper. This is the old boards in Aruco 1.x.x
30 
31 #include <string>
32 #include "markermap.h"
33 #include <cstdio>
34 #include "dictionary.h"
35 #include <opencv2/highgui/highgui.hpp>
36 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] ); }};
37 
38 using namespace std;
39 using namespace cv;
40 int main(int argc, char **argv) {
41  try {
42  CmdLineParser cml(argc,argv);
43  if (argc < 4 || cml["-h"]) {
44  cerr << "Usage: X:Y Image.png Configuration.yml [-d dictionary_name (ARUCO_MIP_36h12 default)] [-s <pixSize>] [-t <Type>(0: panel,1: chessboard )] [-r rand_seed] [-i interMarkerDistance(0,1)]" << endl;
45  cerr<<"\tDictionaries: "; for(auto dict:aruco::Dictionary::getDicTypes()) cerr<<dict<<" ";cerr<<endl;
46  return -1;
47  }
48  int XSize, YSize;
49  if (sscanf(argv[1], "%d:%d", &XSize, &YSize) != 2) {
50  cerr << "Incorrect X:Y specification" << endl;
51  return -1;
52  }
53 
54  auto Dict=aruco::Dictionary::loadPredefined(cml("-d","ARUCO_MIP_36h12"));
55  int pixSize = stoi(cml("-s","500"));
56  int typeMarkerMap = stoi(cml("-t","0"));
57  int rand_seed = stoi(cml("-r","0"));
58  float interMarkerDistance = stof(cml("-i","0.2"));
59 
60  if ((interMarkerDistance > 1.f) || (interMarkerDistance < 0.f)) {
61  cerr << "Incorrect interMarkerDistance '" << interMarkerDistance << "' -- needs to be [0,1]" << endl;
62  return -1;
63  }
64 
65  //get the list of ids
66  std::vector<int> ids;
67  for(auto d:Dict.getMapCode()) ids.push_back(d.second);
68  //random shuffle
69  srand(rand_seed);
70  std::random_shuffle(ids.begin(),ids.end());
71  //take the required ones
72  ids.resize(XSize*YSize);
73  aruco::MarkerMap BInfo=Dict.createMarkerMap(Size(XSize, YSize), pixSize, pixSize * interMarkerDistance,ids,typeMarkerMap==1);
74  //create a printable image to save
75  cv::Mat MarkerMapImage=BInfo.getImage();
76 
77  //save
78  BInfo.saveToFile(argv[3]);
79  imwrite(argv[2], MarkerMapImage);
80 
81  } catch (std::exception &ex) {
82  cout << ex.what() << endl;
83  }
84 }
d
void saveToFile(string sfile)
Definition: markermap.cpp:58
bool param(const std::string &param_name, T &param_val, const T &default_val)
f
static std::vector< std::string > getDicTypes()
Definition: dictionary.cpp:270
CmdLineParser(int _argc, char **_argv)
string operator()(string param, string defvalue="-1")
bool operator[](string param)
int main(int argc, char **argv)
static Dictionary loadPredefined(DICT_TYPES type)
Definition: dictionary.cpp:63
cv::Mat getImage(float METER2PIX=0) const
Definition: markermap.cpp:314
This class defines a set of markers whose locations are attached to a common reference system...
Definition: markermap.h:71


tuw_aruco
Author(s): Lukas Pfeifhofer
autogenerated on Mon Jun 10 2019 15:40:45