sample/multi/src/main.cpp
Go to the documentation of this file.
1 /* ========================================================================
2 * PROJECT: ARToolKitPlus
3 * ========================================================================
4 * This work is based on the original ARToolKit developed by
5 * Hirokazu Kato
6 * Mark Billinghurst
7 * HITLab, University of Washington, Seattle
8 * http://www.hitl.washington.edu/artoolkit/
9 *
10 * Copyright of the derived and new portions of this work
11 * (C) 2006 Graz University of Technology
12 *
13 * This framework is free software; you can redistribute it and/or modify
14 * it under the terms of the GNU General Public License as published by
15 * the Free Software Foundation; either version 2 of the License, or
16 * (at your option) any later version.
17 *
18 * This framework is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU General Public License for more details.
22 *
23 * You should have received a copy of the GNU General Public License
24 * along with this framework; if not, write to the Free Software
25 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
26 *
27 * For further information please contact
28 * Dieter Schmalstieg
29 * <schmalstieg@icg.tu-graz.ac.at>
30 * Graz University of Technology,
31 * Institut for Computer Graphics and Vision,
32 * Inffeldgasse 16a, 8010 Graz, Austria.
33 * ========================================================================
34 ** @author Daniel Wagner
35 *
36 * $Id: main.cpp 126 2006-01-26 14:01:41Z daniel $
37 * @file
38  * ======================================================================== */
39 
40 
41 //
42 // Simple example to demonstrate multi-marker tracking with ARToolKitPlus
43 // This sample does not open any graphics window. It just
44 // loads test images and shows use to use the ARToolKitPlus API.
45 //
46 
48 
49 
51 {
52  void artLog(const char* nStr)
53  {
54  printf(nStr);
55  }
56 };
57 
58 
59 int main(int argc, char** argv)
60 {
61  const int width = 320, height = 240, bpp = 1;
62  size_t numPixels = width*height*bpp;
63  size_t numBytesRead;
64  const char *fName = "data/markerboard_480-499.raw";
65  unsigned char *cameraBuffer = new unsigned char[numPixels];
66  MyLogger logger;
67 
68  // try to load a test camera image.
69  // these images files are expected to be simple 8-bit raw pixel
70  // data without any header. the images are expetected to have a
71  // size of 320x240.
72  //
73  if(FILE* fp = fopen(fName, "rb"))
74  {
75  numBytesRead = fread(cameraBuffer, 1, numPixels, fp);
76  fclose(fp);
77  }
78  else
79  {
80  printf("Failed to open %s\n", fName);
81  delete cameraBuffer;
82  return -1;
83  }
84 
85  if(numBytesRead != numPixels)
86  {
87  printf("Failed to read %s\n", fName);
88  delete cameraBuffer;
89  return -1;
90  }
91 
92  // create a tracker that does:
93  // - 6x6 sized marker images
94  // - samples at a maximum of 6x6
95  // - works with luminance (gray) images
96  // - can load a maximum of 1 pattern
97  // - can detect a maximum of 8 patterns in one image
99 
100  const char* description = tracker->getDescription();
101  printf("ARToolKitPlus compile-time information:\n%s\n\n", description);
102 
103  // set a logger so we can output error messages
104  //
105  tracker->setLogger(&logger);
107 
108  // load a camera file. two types of camera files are supported:
109  // - Std. ARToolKit
110  // - MATLAB Camera Calibration Toolbox
111  if(!tracker->init("data/LogitechPro4000.dat", "data/markerboard_480-499.cfg", 1.0f, 1000.0f))
112  {
113  printf("ERROR: init() failed\n");
114  delete cameraBuffer;
115  delete tracker;
116  return -1;
117  }
118 
119  // the marker in the BCH test image has a thiner border...
120  tracker->setBorderWidth(0.125f);
121 
122  // set a threshold. we could also activate automatic thresholding
123  tracker->setThreshold(160);
124 
125  // let's use lookup-table undistortion for high-speed
126  // note: LUT only works with images up to 1024x1024
128 
129  // RPP is more robust than ARToolKit's standard pose estimator
130  //tracker->setPoseEstimator(ARToolKitPlus::POSE_ESTIMATOR_RPP);
131 
132  // switch to simple ID based markers
133  // use the tool in tools/IdPatGen to generate markers
135 
136  // do the OpenGL camera setup
137  //glMatrixMode(GL_PROJECTION)
138  //glLoadMatrixf(tracker->getProjectionMatrix());
139 
140  // here we go, just one call to find the camera pose
141  int numDetected = tracker->calc(cameraBuffer);
142 
143  // use the result of calc() to setup the OpenGL transformation
144  //glMatrixMode(GL_MODELVIEW)
145  //glLoadMatrixf(tracker->getModelViewMatrix());
146 
147  printf("\n%d good Markers found and used for pose estimation.\nPose-Matrix:\n ", numDetected);
148  for(int i=0; i<16; i++)
149  printf("%.2f %s", tracker->getModelViewMatrix()[i], (i%4==3)?"\n " : "");
150 
151  bool showConfig = false;
152 
153  if(showConfig)
154  {
155  const ARToolKitPlus::ARMultiMarkerInfoT *artkpConfig = tracker->getMultiMarkerConfig();
156  printf("%d markers defined in multi marker cfg\n", artkpConfig->marker_num);
157 
158  printf("marker matrices:\n");
159  for(int multiMarkerCounter = 0; multiMarkerCounter < artkpConfig->marker_num; multiMarkerCounter++)
160  {
161  printf("marker %d, id %d:\n", multiMarkerCounter, artkpConfig->marker[multiMarkerCounter].patt_id);
162  for(int row = 0; row < 3; row++)
163  {
164  for(int column = 0; column < 4; column++)
165  printf("%.2f ", artkpConfig->marker[multiMarkerCounter].trans[row][column]);
166  printf("\n");
167  }
168  }
169  }
170 
171  delete [] cameraBuffer;
172  delete tracker;
173  return 0;
174 }
int main(int argc, char **argv)
virtual void setBorderWidth(ARFloat nFraction)=0
Sets a new relative border width. ARToolKit&#39;s default value is 0.25.
f
virtual const char * getDescription()=0
Returns a short description with compiled-in settings.
virtual const ARMultiMarkerInfoT * getMultiMarkerConfig() const =0
Returns the loaded ARMultiMarkerInfoT object.
virtual bool setPixelFormat(PIXEL_FORMAT nFormat)=0
Sets the pixel format of the camera image.
virtual bool init(const char *nCamParamFile, const char *nMultiFile, ARFloat nNearClip, ARFloat nFarClip, ARToolKitPlus::Logger *nLogger=NULL)=0
ARMultiEachMarkerInfoT * marker
Definition: arMulti.h:67
Defines a simple interface for multi-marker tracking with ARToolKitPlus.
void artLog(const char *nStr)
Passes a simple string to the implementing instance.
virtual void setLogger(ARToolKitPlus::Logger *nLogger)=0
sets an instance which implements the ARToolKit::Logger interface
TrackerMultiMarkerImpl implements the TrackerMultiMarker interface.
virtual void setUndistortionMode(UNDIST_MODE nMode)=0
Changes the undistortion mode.
virtual int calc(const unsigned char *nImage)=0
calculates the transformation matrix
ARToolKit::Logger specifies the interface for a logging application.
Definition: Logger.h:61
virtual const ARFloat * getModelViewMatrix() const =0
Returns an opengl-style modelview transformation matrix.
virtual void setMarkerMode(MARKER_MODE nMarkerMode)=0
activate the usage of id-based markers rather than template based markers
virtual void setThreshold(int nValue)=0
Sets the threshold value that is used for black/white conversion.


tuw_artoolkitplus
Author(s): Markus Bader
autogenerated on Sun Sep 4 2016 03:24:33