sample/simple/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 172 2006-07-25 14:05:47Z daniel $
37 * @file
38  * ======================================================================== */
39 
40 
41 //
42 // Simple example to demonstrate usage of 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 
50 class MyLogger : public ARToolKitPlus::Logger
51 {
52  void artLog(const char* nStr)
53  {
54  printf("%s", nStr);
55  }
56 };
57 
58 
59 int main(int argc, char** argv)
60 {
61  // switch this between true and false to test
62  // simple-id versus BCH-id markers
63  //
64  const bool useBCH = false;
65 
66  const int width = 320, height = 240, bpp = 1;
67  size_t numPixels = width*height*bpp;
68  size_t numBytesRead;
69  const char *fName = useBCH ? "data/image_320_240_8_marker_id_bch_nr0100.raw" :
70  "data/image_320_240_8_marker_id_simple_nr031.raw";
71  unsigned char *cameraBuffer = new unsigned char[numPixels];
72  MyLogger logger;
73 
74  // try to load a test camera image.
75  // these images files are expected to be simple 8-bit raw pixel
76  // data without any header. the images are expetected to have a
77  // size of 320x240.
78  //
79  if(FILE* fp = fopen(fName, "rb"))
80  {
81  numBytesRead = fread(cameraBuffer, 1, numPixels, fp);
82  fclose(fp);
83  }
84  else
85  {
86  printf("Failed to open %s\n", fName);
87  delete cameraBuffer;
88  return -1;
89  }
90 
91  if(numBytesRead != numPixels)
92  {
93  printf("Failed to read %s\n", fName);
94  delete cameraBuffer;
95  return -1;
96  }
97 
98  // create a tracker that does:
99  // - 6x6 sized marker images
100  // - samples at a maximum of 6x6
101  // - works with luminance (gray) images
102  // - can load a maximum of 1 pattern
103  // - can detect a maximum of 8 patterns in one image
105 
106  const char* description = tracker->getDescription();
107  printf("ARToolKitPlus compile-time information:\n%s\n\n", description);
108 
109  // set a logger so we can output error messages
110  //
111  tracker->setLogger(&logger);
113  //tracker->setLoadUndistLUT(true);
114 
115  // load a camera file. two types of camera files are supported:
116  // - Std. ARToolKit
117  // - MATLAB Camera Calibration Toolbox
118  if(!tracker->init("data/LogitechPro4000.dat", 1.0f, 1000.0f)) // load std. ARToolKit camera file
119  //if(!tracker->init("data/PGR_M12x0.5_2.5mm.cal", 1.0f, 1000.0f)) // load MATLAB file
120  {
121  printf("ERROR: init() failed\n");
122  delete cameraBuffer;
123  delete tracker;
124  return -1;
125  }
126 
127  // define size of the marker
128  tracker->setPatternWidth(80);
129 
130  // the marker in the BCH test image has a thin border...
131  tracker->setBorderWidth(useBCH ? 0.125f : 0.250f);
132 
133  // set a threshold. alternatively we could also activate automatic thresholding
134  tracker->setThreshold(150);
135 
136  // let's use lookup-table undistortion for high-speed
137  // note: LUT only works with images up to 1024x1024
139 
140  // RPP is more robust than ARToolKit's standard pose estimator
141  //tracker->setPoseEstimator(ARToolKitPlus::POSE_ESTIMATOR_RPP);
142 
143  // switch to simple ID based markers
144  // use the tool in tools/IdPatGen to generate markers
146 
147 
148  // do the OpenGL camera setup
149  //glMatrixMode(GL_PROJECTION)
150  //glLoadMatrixf(tracker->getProjectionMatrix());
151 
152  // here we go, just one call to find the camera pose
153  int markerId = tracker->calc(cameraBuffer);
154  float conf = (float)tracker->getConfidence();
155 
156  // use the result of calc() to setup the OpenGL transformation
157  //glMatrixMode(GL_MODELVIEW)
158  //glLoadMatrixf(tracker->getModelViewMatrix());
159 
160 
161  printf("\n\nFound marker %d (confidence %d%%)\n\nPose-Matrix:\n ", markerId, (int(conf*100.0f)));
162  for(int i=0; i<16; i++)
163  printf("%.2f %s", tracker->getModelViewMatrix()[i], (i%4==3)?"\n " : "");
164 
165  delete [] cameraBuffer;
166  delete tracker;
167 
168  return 0;
169 }
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 bool setPixelFormat(PIXEL_FORMAT nFormat)=0
Sets the pixel format of the camera image.
virtual ARFloat getConfidence() const =0
Returns the confidence value of the currently best detected marker.
TrackerSingleMarkerImpl implements the TrackerSingleMarker interface.
int main(int argc, char **argv)
virtual bool init(const char *nCamParamFile, ARFloat nNearClip, ARFloat nFarClip, ARToolKitPlus::Logger *nLogger=NULL)=0
initializes TrackerSingleMarker
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
virtual void setUndistortionMode(UNDIST_MODE nMode)=0
Changes the undistortion mode.
Defines a simple interface for single-marker tracking with ARToolKitPlus.
ARToolKit::Logger specifies the interface for a logging application.
Definition: Logger.h:61
virtual int calc(const unsigned char *nImage, int nPattern=-1, bool nUpdateMatrix=true, ARMarkerInfo **nMarker_info=NULL, int *nNumMarkers=NULL)=0
calculates the transformation matrix
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 setPatternWidth(ARFloat nWidth)=0
Sets the width and height of the patterns.
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