main.cpp
Go to the documentation of this file.
00001 /* ========================================================================
00002 * PROJECT: ARToolKitPlus
00003 * ========================================================================
00004 * This work is based on the original ARToolKit developed by
00005 *   Hirokazu Kato
00006 *   Mark Billinghurst
00007 *   HITLab, University of Washington, Seattle
00008 * http://www.hitl.washington.edu/artoolkit/
00009 *
00010 * Copyright of the derived and new portions of this work
00011 *     (C) 2006 Graz University of Technology
00012 *
00013 * This framework is free software; you can redistribute it and/or modify
00014 * it under the terms of the GNU General Public License as published by
00015 * the Free Software Foundation; either version 2 of the License, or
00016 * (at your option) any later version.
00017 *
00018 * This framework is distributed in the hope that it will be useful,
00019 * but WITHOUT ANY WARRANTY; without even the implied warranty of
00020 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00021 * GNU General Public License for more details.
00022 *
00023 * You should have received a copy of the GNU General Public License
00024 * along with this framework; if not, write to the Free Software
00025 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00026 *
00027 * For further information please contact 
00028 *   Dieter Schmalstieg
00029 *   <schmalstieg@icg.tu-graz.ac.at>
00030 *   Graz University of Technology, 
00031 *   Institut for Computer Graphics and Vision,
00032 *   Inffeldgasse 16a, 8010 Graz, Austria.
00033 * ========================================================================
00034 ** @author   Daniel Wagner
00035 *
00036 * $Id: main.cpp 126 2006-01-26 14:01:41Z daniel $
00037 * @file
00038  * ======================================================================== */
00039 
00040 
00041 //
00042 // Simple example to demonstrate multi-marker tracking with ARToolKitPlus
00043 // This sample does not open any graphics window. It just
00044 // loads test images and shows use to use the ARToolKitPlus API.
00045 //
00046 
00047 #include "ARToolKitPlus/TrackerMultiMarkerImpl.h"
00048 
00049 
00050 class MyLogger : public ARToolKitPlus::Logger
00051 {
00052     void artLog(const char* nStr)
00053     {
00054         printf(nStr);
00055     }
00056 };
00057 
00058 
00059 int main(int argc, char** argv)
00060 {
00061     const int     width = 320, height = 240, bpp = 1;
00062     size_t        numPixels = width*height*bpp;
00063     size_t        numBytesRead;
00064     const char    *fName = "data/markerboard_480-499.raw";
00065     unsigned char *cameraBuffer = new unsigned char[numPixels];
00066     MyLogger      logger;
00067 
00068     // try to load a test camera image.
00069     // these images files are expected to be simple 8-bit raw pixel
00070     // data without any header. the images are expetected to have a
00071     // size of 320x240.
00072     //
00073     if(FILE* fp = fopen(fName, "rb"))
00074     {
00075         numBytesRead = fread(cameraBuffer, 1, numPixels, fp);
00076         fclose(fp);
00077     }
00078     else
00079     {
00080         printf("Failed to open %s\n", fName);
00081         delete cameraBuffer;
00082         return -1;
00083     }
00084 
00085     if(numBytesRead != numPixels)
00086     {
00087         printf("Failed to read %s\n", fName);
00088         delete cameraBuffer;
00089         return -1;
00090     }
00091 
00092     // create a tracker that does:
00093     //  - 6x6 sized marker images
00094     //  - samples at a maximum of 6x6
00095     //  - works with luminance (gray) images
00096     //  - can load a maximum of 1 pattern
00097     //  - can detect a maximum of 8 patterns in one image
00098     ARToolKitPlus::TrackerMultiMarker *tracker = new ARToolKitPlus::TrackerMultiMarkerImpl<6,6,6, 1, 16>(width,height);
00099 
00100         const char* description = tracker->getDescription();
00101         printf("ARToolKitPlus compile-time information:\n%s\n\n", description);
00102 
00103     // set a logger so we can output error messages
00104     //
00105     tracker->setLogger(&logger);
00106         tracker->setPixelFormat(ARToolKitPlus::PIXEL_FORMAT_LUM);
00107 
00108     // load a camera file. two types of camera files are supported:
00109     //  - Std. ARToolKit
00110     //  - MATLAB Camera Calibration Toolbox
00111         if(!tracker->init("data/LogitechPro4000.dat", "data/markerboard_480-499.cfg", 1.0f, 1000.0f))
00112         {
00113                 printf("ERROR: init() failed\n");
00114                 delete cameraBuffer;
00115                 delete tracker;
00116                 return -1;
00117         }
00118 
00119         // the marker in the BCH test image has a thiner border...
00120     tracker->setBorderWidth(0.125f);
00121 
00122     // set a threshold. we could also activate automatic thresholding
00123     tracker->setThreshold(160);
00124 
00125     // let's use lookup-table undistortion for high-speed
00126     // note: LUT only works with images up to 1024x1024
00127     tracker->setUndistortionMode(ARToolKitPlus::UNDIST_LUT);
00128 
00129     // RPP is more robust than ARToolKit's standard pose estimator
00130     //tracker->setPoseEstimator(ARToolKitPlus::POSE_ESTIMATOR_RPP);
00131 
00132     // switch to simple ID based markers
00133     // use the tool in tools/IdPatGen to generate markers
00134     tracker->setMarkerMode(ARToolKitPlus::MARKER_ID_SIMPLE);
00135 
00136     // do the OpenGL camera setup
00137     //glMatrixMode(GL_PROJECTION)
00138     //glLoadMatrixf(tracker->getProjectionMatrix());
00139 
00140     // here we go, just one call to find the camera pose
00141     int numDetected = tracker->calc(cameraBuffer);
00142 
00143     // use the result of calc() to setup the OpenGL transformation
00144     //glMatrixMode(GL_MODELVIEW)
00145     //glLoadMatrixf(tracker->getModelViewMatrix());
00146 
00147         printf("\n%d good Markers found and used for pose estimation.\nPose-Matrix:\n  ", numDetected);
00148         for(int i=0; i<16; i++)
00149                 printf("%.2f  %s", tracker->getModelViewMatrix()[i], (i%4==3)?"\n  " : "");
00150 
00151         bool showConfig = false;
00152 
00153         if(showConfig)
00154         {
00155                 const ARToolKitPlus::ARMultiMarkerInfoT *artkpConfig = tracker->getMultiMarkerConfig();
00156                 printf("%d markers defined in multi marker cfg\n", artkpConfig->marker_num);
00157 
00158                 printf("marker matrices:\n");
00159                 for(int multiMarkerCounter = 0; multiMarkerCounter < artkpConfig->marker_num; multiMarkerCounter++)
00160                 {
00161                         printf("marker %d, id %d:\n", multiMarkerCounter, artkpConfig->marker[multiMarkerCounter].patt_id);
00162                         for(int row = 0; row < 3; row++)
00163                         {
00164                                 for(int column = 0; column < 4; column++)
00165                                         printf("%.2f  ", artkpConfig->marker[multiMarkerCounter].trans[row][column]);
00166                                 printf("\n");
00167                         }
00168                 }
00169         }
00170 
00171     delete [] cameraBuffer;
00172         delete tracker;
00173         return 0;
00174 }


v4r_artoolkitplus
Author(s): Markus Bader
autogenerated on Wed Aug 26 2015 16:41:52