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 172 2006-07-25 14:05:47Z daniel $
00037 * @file
00038  * ======================================================================== */
00039 
00040 
00041 //
00042 // Simple example to demonstrate usage of 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/TrackerSingleMarkerImpl.h"
00048 
00049 
00050 class MyLogger : public ARToolKitPlus::Logger
00051 {
00052     void artLog(const char* nStr)
00053     {
00054         printf("%s", nStr);
00055     }
00056 };
00057 
00058 
00059 int main(int argc, char** argv)
00060 {
00061     // switch this between true and false to test
00062     // simple-id versus BCH-id markers
00063     //
00064     const bool    useBCH = false;
00065 
00066     const int     width = 320, height = 240, bpp = 1;
00067     size_t        numPixels = width*height*bpp;
00068     size_t        numBytesRead;
00069     const char    *fName = useBCH ? "data/image_320_240_8_marker_id_bch_nr0100.raw" :
00070                                       "data/image_320_240_8_marker_id_simple_nr031.raw";
00071     unsigned char *cameraBuffer = new unsigned char[numPixels];
00072     MyLogger      logger;
00073 
00074     // try to load a test camera image.
00075     // these images files are expected to be simple 8-bit raw pixel
00076     // data without any header. the images are expetected to have a
00077     // size of 320x240.
00078     //
00079     if(FILE* fp = fopen(fName, "rb"))
00080     {
00081         numBytesRead = fread(cameraBuffer, 1, numPixels, fp);
00082         fclose(fp);
00083     }
00084     else
00085     {
00086         printf("Failed to open %s\n", fName);
00087         delete cameraBuffer;
00088         return -1;
00089     }
00090 
00091     if(numBytesRead != numPixels)
00092     {
00093         printf("Failed to read %s\n", fName);
00094         delete cameraBuffer;
00095         return -1;
00096     }
00097 
00098     // create a tracker that does:
00099     //  - 6x6 sized marker images
00100     //  - samples at a maximum of 6x6
00101     //  - works with luminance (gray) images
00102     //  - can load a maximum of 1 pattern
00103     //  - can detect a maximum of 8 patterns in one image
00104     ARToolKitPlus::TrackerSingleMarker *tracker = new ARToolKitPlus::TrackerSingleMarkerImpl<6,6,6, 1, 8>(width,height);
00105 
00106         const char* description = tracker->getDescription();
00107         printf("ARToolKitPlus compile-time information:\n%s\n\n", description);
00108 
00109     // set a logger so we can output error messages
00110     //
00111     tracker->setLogger(&logger);
00112         tracker->setPixelFormat(ARToolKitPlus::PIXEL_FORMAT_LUM);
00113         //tracker->setLoadUndistLUT(true);
00114 
00115     // load a camera file. two types of camera files are supported:
00116     //  - Std. ARToolKit
00117     //  - MATLAB Camera Calibration Toolbox
00118     if(!tracker->init("data/LogitechPro4000.dat", 1.0f, 1000.0f))            // load std. ARToolKit camera file
00119     //if(!tracker->init("data/PGR_M12x0.5_2.5mm.cal", 1.0f, 1000.0f))        // load MATLAB file
00120         {
00121                 printf("ERROR: init() failed\n");
00122                 delete cameraBuffer;
00123                 delete tracker;
00124                 return -1;
00125         }
00126 
00127     // define size of the marker
00128     tracker->setPatternWidth(80);
00129 
00130         // the marker in the BCH test image has a thin border...
00131     tracker->setBorderWidth(useBCH ? 0.125f : 0.250f);
00132 
00133     // set a threshold. alternatively we could also activate automatic thresholding
00134     tracker->setThreshold(150);
00135 
00136     // let's use lookup-table undistortion for high-speed
00137     // note: LUT only works with images up to 1024x1024
00138     tracker->setUndistortionMode(ARToolKitPlus::UNDIST_LUT);
00139 
00140     // RPP is more robust than ARToolKit's standard pose estimator
00141     //tracker->setPoseEstimator(ARToolKitPlus::POSE_ESTIMATOR_RPP);
00142 
00143     // switch to simple ID based markers
00144     // use the tool in tools/IdPatGen to generate markers
00145     tracker->setMarkerMode(useBCH ? ARToolKitPlus::MARKER_ID_BCH : ARToolKitPlus::MARKER_ID_SIMPLE);
00146 
00147 
00148     // do the OpenGL camera setup
00149     //glMatrixMode(GL_PROJECTION)
00150     //glLoadMatrixf(tracker->getProjectionMatrix());
00151 
00152     // here we go, just one call to find the camera pose
00153     int markerId = tracker->calc(cameraBuffer);
00154     float conf = (float)tracker->getConfidence();
00155 
00156     // use the result of calc() to setup the OpenGL transformation
00157     //glMatrixMode(GL_MODELVIEW)
00158     //glLoadMatrixf(tracker->getModelViewMatrix());
00159 
00160 
00161     printf("\n\nFound marker %d  (confidence %d%%)\n\nPose-Matrix:\n  ", markerId, (int(conf*100.0f)));
00162         for(int i=0; i<16; i++)
00163                 printf("%.2f  %s", tracker->getModelViewMatrix()[i], (i%4==3)?"\n  " : "");
00164 
00165     delete [] cameraBuffer;
00166         delete tracker;
00167 
00168         return 0;
00169 }


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