9     double minx, 
miny, maxx, maxy; 
    35           marker_data_content_type(
MarkerData::MARKER_CONTENT_TYPE_NUMBER),
    36           marker_data_force_strong_hamming(false)
    39         if (img) cvReleaseImage(&img);
    42         std::cout<<
"ADDING MARKER "<<
id<<std::endl;
    43         if (marker_type == 0) {
    44             MarkerData md(marker_side_len, content_res, margin_res);
    45             int side_len = int(marker_side_len*units+0.5);
    47                 img = cvCreateImage(cvSize(side_len, side_len), IPL_DEPTH_8U, 1);
    49                 filename<<
"MarkerData";
    50                 minx = (posx*units) - (marker_side_len*units/2.0);
    51                 miny = (posy*units) - (marker_side_len*units/2.0);
    52                 maxx = (posx*units) + (marker_side_len*units/2.0);
    53                 maxy = (posy*units) + (marker_side_len*units/2.0);
    55                 double new_minx = (posx*units) - (marker_side_len*units/2.0);
    56                 double new_miny = (posy*units) - (marker_side_len*units/2.0);
    57                 double new_maxx = (posx*units) + (marker_side_len*units/2.0);
    58                 double new_maxy = (posy*units) + (marker_side_len*units/2.0);
    59                 if (minx < new_minx) new_minx = minx;
    60                 if (miny < new_miny) new_miny = miny;
    61                 if (maxx > new_maxx) new_maxx = maxx;
    62                 if (maxy > new_maxy) new_maxy = maxy;
    63                 IplImage *new_img = cvCreateImage(cvSize(
int(new_maxx-new_minx+0.5), 
int(new_maxy-new_miny+0.5)), IPL_DEPTH_8U, 1);
    64                 cvSet(new_img, cvScalar(255));
    65                 CvRect roi = cvRect(
int(minx-new_minx+0.5), 
int(miny-new_miny+0.5), img->width, img->height);
    66                 cvSetImageROI(new_img, roi);
    70                 roi.x = int((posx*units) - (marker_side_len*units/2.0) - new_minx + 0.5); 
    71                 roi.y = int((posy*units) - (marker_side_len*units/2.0) - new_miny + 0.5); 
    72                 roi.width = int(marker_side_len*units+0.5); roi.height = int(marker_side_len*units+0.5);
    73                 cvSetImageROI(img, roi);
    74                 minx = new_minx; miny = new_miny;
    75                 maxx = new_maxx; maxy = new_maxy;
    77             if (marker_data_content_type == MarkerData::MARKER_CONTENT_TYPE_NUMBER) {
    79                 md.
SetContent(marker_data_content_type, idi, 0);
    80                 if (filename.str().length()<64) filename<<
"_"<<idi;
    87                 md.
SetContent(marker_data_content_type, 0, 
id);
    92                     if (!isalnum(*p)) filename<<
"_";
    93                     else filename<<(char)tolower(*p);
    95                     if (counter > 8) 
break;
   101         else if (marker_type == 1) {
   104             int side_len = int(marker_side_len*units+0.5);
   105             if (img != 0) cvReleaseImage(&img);
   106             img = cvCreateImage(cvSize(side_len, side_len), IPL_DEPTH_8U, 1);
   108             filename<<
"MarkerArtoolkit";
   110             filename<<
"_"<<atoi(
id);
   116             std::stringstream filenamexml;
   117             filenamexml<<filename.str()<<
".xml";
   119             std::cout<<
"Saving: "<<filename.str()<<std::endl;
   120             cvSaveImage(filename.str().c_str(), img);
   121             if (multi_marker.
Size() > 1) {
   122                 std::cout<<
"Saving: "<<filenamexml.str()<<std::endl;
   129 int main(
int argc, 
char *argv[])
   133         for (
int i=1; i<argc; i++) {
   134             if (strcmp(argv[i],
"-f") == 0) 
   136             else if (strcmp(argv[i],
"-1") == 0) 
   138             else if (strcmp(argv[i],
"-2") == 0) 
   140             else if (strcmp(argv[i],
"-3") == 0) 
   142             else if (strcmp(argv[i],
"-u") == 0)
   144             else if (strcmp(argv[i],
"-uin") == 0)
   146             else if (strcmp(argv[i],
"-ucm") == 0)
   148             else if (strcmp(argv[i],
"-s") == 0)
   150             else if (strcmp(argv[i],
"-r") == 0)
   152             else if (strcmp(argv[i],
"-m") == 0)
   154             else if (strcmp(argv[i],
"-a") == 0)
   156             else if (strcmp(argv[i],
"-p") == 0)
   158             else if (strcmp(argv[i],
"-xy") == 0) {
   159                 st.
posx = atof(argv[++i]);
   160                 st.
posy = atof(argv[++i]);
   162             else if (strcmp(argv[i],
"-ar") == 0) {
   171             filename = filename.substr(filename.find_last_of(
'\\') + 1);
   172             std::cout << 
"SampleMarkerCreator" << std::endl;
   173             std::cout << 
"===================" << std::endl;
   174             std::cout << std::endl;
   175             std::cout << 
"Description:" << std::endl;
   176             std::cout << 
"  This is an example of how to use the 'MarkerData' and 'MarkerArtoolkit'" << std::endl;
   177             std::cout << 
"  classes to generate marker images. This application can be used to" << std::endl;
   178             std::cout << 
"  generate markers and multimarker setups that can be used with" << std::endl;
   179             std::cout << 
"  SampleMarkerDetector and SampleMultiMarker." << std::endl;
   180             std::cout << std::endl;
   181             std::cout << 
"Usage:" << std::endl;
   182             std::cout << 
"  " << filename << 
" [options] argument" << std::endl;
   183             std::cout << std::endl;
   184             std::cout << 
"    65535             marker with number 65535" << std::endl;
   185             std::cout << 
"    -f 65535          force hamming(8,4) encoding" << std::endl;
   186             std::cout << 
"    -1 \"hello world\"  marker with string" << std::endl;
   187             std::cout << 
"    -2 catalog.xml    marker with file reference" << std::endl;
   188             std::cout << 
"    -3 www.vtt.fi     marker with URL" << std::endl;
   189             std::cout << 
"    -u 96             use units corresponding to 1.0 unit per 96 pixels" << std::endl;
   190             std::cout << 
"    -uin              use inches as units (assuming 96 dpi)" << std::endl;
   191             std::cout << 
"    -ucm              use cm's as units (assuming 96 dpi) <default>" << std::endl;
   192             std::cout << 
"    -s 5.0            use marker size 5.0x5.0 units (default 9.0x9.0)" << std::endl;
   193             std::cout << 
"    -r 5              marker content resolution -- 0 uses default" << std::endl;
   194             std::cout << 
"    -m 2.0            marker margin resolution -- 0 uses default" << std::endl;
   195             std::cout << 
"    -a                use ArToolkit style matrix markers" << std::endl;
   196             std::cout << 
"    -p                prompt marker placements interactively from the user" << std::endl;
   197             std::cout << std::endl;
   203                 std::cout<<
"\nPrompt marker placements interactively"<<std::endl;
   204                 std::cout<<
"  units: "<<
st.
units/96.0*2.54<<
" cm "<<
st.
units/96.0<<
" inches"<<std::endl;
   209                 double posx=0.0, posy=0.0;
   212                     std::cout<<
"  marker id (use -1 to end) ["<<marker_id<<
"]: "; std::flush(std::cout);
   213                     std::getline(std::cin, s); 
if (s.length() > 0) marker_id=atoi(s.c_str());
   214                     if (marker_id < 0) 
break;
   215                     std::cout<<
"  x position (in current units) ["<<posx<<
"]: "; std::flush(std::cout);
   216                     std::getline(std::cin, s); 
if (s.length() > 0) posx=atof(s.c_str());
   217                     std::cout<<
"  y position (in current units) ["<<posy<<
"]: "; std::flush(std::cout);
   218                     std::getline(std::cin, s); 
if (s.length() > 0) posy=atof(s.c_str());
   220                     std::stringstream ss;
   232                         if (posy >= posx) vert = 
false;
   244             double rows_distance = 0;
   245             double cols_distance = 0;
   246             bool column_major = 1;
   250             std::cout<<
"\nPrompt marker placements interactively"<<std::endl;
   251             std::cout<<
"  units: "<<
st.
units/96.0*2.54<<
" cm "<<
st.
units/96.0<<
" inches"<<std::endl;
   253             std::cout<<
"Array rows : "; std::flush(std::cout);
   254             std::getline(std::cin, s); 
if (s.length() > 0) rows=atoi(s.c_str());
   255             std::cout<<
"Array cols : "; std::flush(std::cout);
   256             std::getline(std::cin, s); 
if (s.length() > 0) cols=atoi(s.c_str());
   257             std::cout<<
"Rows distance : "; std::flush(std::cout);
   258             std::getline(std::cin, s); 
if (s.length() > 0) rows_distance=atof(s.c_str());
   259             std::cout<<
"Cols distance : "; std::flush(std::cout);
   260             std::getline(std::cin, s); 
if (s.length() > 0) cols_distance=atof(s.c_str());
   261             std::cout<<
"Column major (1 or 0) : "; std::flush(std::cout);
   262             std::getline(std::cin, s); 
if (s.length() > 0) column_major=atoi(s.c_str());
   263             std::cout<<
"First marker ID : "; std::flush(std::cout);
   264             std::getline(std::cin, s); 
if (s.length() > 0) first_id=atoi(s.c_str());
   266                 for(
int row = 0; row<rows; row++)
   267                     for(
int col = 0; col<cols; col++)
   270                         marker_id = first_id + row*cols + col;
   271                         std::stringstream ss;
   277                 for(
int col = 0; col<cols; col++)
   278                     for(
int row = 0; row<rows; row++)
   281                         marker_id = first_id + col*rows + row;
   282                         std::stringstream ss;
   292     catch (
const std::exception &e) {
   293         std::cout << 
"Exception: " << e.what() << endl;
   296         std::cout << 
"Exception: unknown" << std::endl;
 
size_t Size()
Return the number of markers added using PointCloudAdd. 
MarkerData contains matrix of Hamming encoded data. 
Base class for using MultiMarker. 
MarkerData::MarkerContentType marker_data_content_type
bool marker_data_force_strong_hamming
void SetContent(MarkerContentType content_type, unsigned long id, const char *str, bool force_strong_hamming=false, bool verbose=false)
Updates the marker_content by "encoding" the given parameters. 
Pose representation derived from the Rotation class 
void PointCloudAdd(int marker_id, double edge_length, Pose &pose)
Adds marker corners to 3D point cloud of multi marker. 
int main(int argc, char *argv[])
This file implements a multi-marker. 
void ScaleMarkerToImage(IplImage *image) const 
Draw the marker filling the ROI in the given image. 
void SetTranslation(const CvMat *tra)
void AddMarker(const char *id)
bool Save(const char *fname, FILE_FORMAT format=FILE_FORMAT_DEFAULT)
Saves multi marker configuration to a text file.