test-BeoSubCanny.C

Go to the documentation of this file.
00001 /*!@file BeoSub/test-BeoSubCanny.C Test BeoSubColor exclusion and shape detection */
00002 
00003 // //////////////////////////////////////////////////////////////////// //
00004 // The iLab Neuromorphic Vision C++ Toolkit - Copyright (C) 2001 by the //
00005 // University of Southern California (USC) and the iLab at USC.         //
00006 // See http://iLab.usc.edu for information about this project.          //
00007 // //////////////////////////////////////////////////////////////////// //
00008 // Major portions of the iLab Neuromorphic Vision Toolkit are protected //
00009 // under the U.S. patent ``Computation of Intrinsic Perceptual Saliency //
00010 // in Visual Environments, and Applications'' by Christof Koch and      //
00011 // Laurent Itti, California Institute of Technology, 2001 (patent       //
00012 // pending; application number 09/912,225 filed July 23, 2001; see      //
00013 // http://pair.uspto.gov/cgi-bin/final/home.pl for current status).     //
00014 // //////////////////////////////////////////////////////////////////// //
00015 // This file is part of the iLab Neuromorphic Vision C++ Toolkit.       //
00016 //                                                                      //
00017 // The iLab Neuromorphic Vision C++ Toolkit is free software; you can   //
00018 // redistribute it and/or modify it under the terms of the GNU General  //
00019 // Public License as published by the Free Software Foundation; either  //
00020 // version 2 of the License, or (at your option) any later version.     //
00021 //                                                                      //
00022 // The iLab Neuromorphic Vision C++ Toolkit is distributed in the hope  //
00023 // that it will be useful, but WITHOUT ANY WARRANTY; without even the   //
00024 // implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR      //
00025 // PURPOSE.  See the GNU General Public License for more details.       //
00026 //                                                                      //
00027 // You should have received a copy of the GNU General Public License    //
00028 // along with the iLab Neuromorphic Vision C++ Toolkit; if not, write   //
00029 // to the Free Software Foundation, Inc., 59 Temple Place, Suite 330,   //
00030 // Boston, MA 02111-1307 USA.                                           //
00031 // //////////////////////////////////////////////////////////////////// //
00032 //
00033 // Primary maintainer for this file: Zack Gossman <gossman@usc.edu>
00034 // $HeadURL: svn://isvn.usc.edu/software/invt/trunk/saliency/src/BeoSub/test-BeoSubCanny.C $
00035 // $Id: test-BeoSubCanny.C 6990 2006-08-11 18:13:51Z rjpeters $
00036 //
00037 
00038 #ifndef TESTBEOSUBCANNY_H_DEFINED
00039 #define TESTBEOSUBCANNY_H_DEFINED
00040 
00041 #include "BeoSub/BeoSubCanny.H"
00042 
00043 //CAMERA STUFF
00044 #include "Image/Image.H"
00045 #include "Image/Pixels.H"
00046 
00047 #include "Component/ModelManager.H"
00048 #include "Devices/FrameGrabberFactory.H"
00049 #include "Util/Timer.H"
00050 #include "Util/Types.H"
00051 #include "Util/log.H"
00052 
00053 #include <cstdio>
00054 #include <cstdlib>
00055 #include <cstring>
00056 //END CAMERA STUFF
00057 //test stuff
00058 //SHAPE STUFF
00059 #include "CannyModel.H"
00060 //END SHAPE STUFF
00061 
00062 int main(int argc, char **argv)
00063 {
00064   if(MYLOGVERB) printf("This should never print\n");
00065   //Parse the command line options
00066   char *infilename = NULL;  //Name of the input image
00067   char *shapeArg = NULL;    //Shape for recognition
00068   char *colorArg = NULL;    //Color for tracking
00069 
00070   if(argc < 3){
00071     fprintf(stderr,"\n<USAGE> %s image shape color \n",argv[0]);
00072     fprintf(stderr,"\n      image:      An image to process. Must be in PGM format.\n");
00073     fprintf(stderr,"                  Type 'none' for camera input.\n");
00074     fprintf(stderr,"      shape:      Shape on which to run recognition\n");
00075     fprintf(stderr,"                  Candidates: Rectangle, Square, Circle, Octagon.\n");
00076     fprintf(stderr,"      color:       Color to track\n");
00077     fprintf(stderr,"                  Candidates: Blue, Yellow, none (for no color tracking).\n");
00078     exit(1);
00079   }
00080   infilename = argv[1];
00081   shapeArg = argv[2];
00082   colorArg = argv[3];
00083 
00084   printf("READ: 1: %s 2: %s 3: %s\n", infilename, shapeArg, colorArg);
00085 
00086 
00087   // instantiate a model manager (for camera input):
00088   ModelManager manager("Canny Tester");
00089   // Instantiate our various ModelComponents:
00090 
00091   nub::soft_ref<FrameIstream>
00092     gb(makeIEEE1394grabber(manager, "cannycam", "cc"));
00093 
00094   if(!strcmp(infilename, "none")){//if the camera is to be used
00095 
00096     //GRAB image from camera to be tested
00097     manager.addSubComponent(gb);
00098 
00099   }
00100 
00101   // Instantiate our various ModelComponents:
00102   nub::soft_ref<BeoSubCanny> test(new BeoSubCanny(manager));
00103   manager.addSubComponent(test);
00104 
00105   if(!strcmp(infilename, "none")){
00106     //Load in config file for camera FIX: put in a check whether config file exists!
00107     manager.loadConfig("camconfig.pmap");
00108   }
00109 
00110   manager.start();
00111 
00112   //Test with a circle
00113   rutz::shared_ptr<ShapeModel> shape;
00114 
00115   Image< PixRGB<byte> > Img;
00116 
00117   double* p;
00118 
00119 
00120   //Set up shape to be matched
00121     if(!strcmp(shapeArg, "Rectangle")){
00122       //rectangle
00123       p = (double*)calloc(6, sizeof(double));
00124       p[1] = 150.0; //Xcenter
00125       p[2] = 120.0; //Ycenter
00126       p[4] = 80.0f; // Width
00127       p[5] = 80.0f; // Height
00128       p[3] = (3.14159/4.0); //alpha
00129       shape.reset(new RectangleShape(120.0, p, true));
00130     }
00131     else if(!strcmp(shapeArg, "Square")){
00132       //square
00133       p = (double*)calloc(5, sizeof(double));
00134       p[1] = 150.0; //Xcenter
00135       p[2] = 120.0; //Ycenter
00136       p[3] = 100.0; // Height
00137       p[4] = (3.14159/4.0); // alpha
00138       shape.reset(new SquareShape(100.0, p, true));
00139     }
00140     else if(!strcmp(shapeArg, "Octagon")){
00141       //octagon
00142       p = (double*)calloc(5, sizeof(double));
00143       p[1] = 150.0; //Xcenter
00144       p[2] = 120.0; //Ycenter
00145       p[3] = 60.0f; // Height
00146       p[4] = (3.14159/4.0); // alpha
00147       shape.reset(new OctagonShape(80.0, p, true));
00148     }
00149     else if(!strcmp(shapeArg, "Circle")){
00150       //circle
00151       p = (double*)calloc(4, sizeof(double));
00152       p[1] = 150.0; //Xcenter
00153       p[2] = 120.0; //Ycenter
00154       p[3] = 50.0; // Radius
00155       shape.reset(new CircleShape(40.0, p, true));
00156     }
00157     else if(!strcmp(shapeArg, "Parallel")){
00158       //Parallel lines
00159       p = (double*)calloc(6, sizeof(double));
00160       p[1] = 150.0; //Xcenter
00161       p[2] = 120.0; //Ycenter
00162       p[4] = 120.0f; // Width
00163       p[5] = 50.0f; // Height
00164       p[3] = (3.14159/4.0); //alpha
00165       shape.reset(new ParallelShape(120.0, p, true));
00166     }
00167     else{
00168       printf("Cannot run shape recognition without a shape to recognize! Returning...\n");
00169       p = (double*)calloc(1, sizeof(double));
00170       shape.reset(new CircleShape(9999.0, p, false));
00171       return(false);
00172     }
00173 
00174 
00175 
00176   while(1){
00177     //Get image to be matched
00178     //TO TEST FROM CAMERA
00179     if(!strcmp(infilename, "none")){
00180       Img = gb->readRGB();
00181     }
00182     else{
00183       //TO TEST FROM FILE (shouldn't really be in loop):
00184       Img = Raster::ReadRGB(infilename);
00185     }
00186 
00187     shape->setDimensions(p);
00188 
00189     //run the matching code
00190     test->setupCanny(colorArg, Img, true);
00191 
00192     //Middle
00193     //p[1] = 150.0;
00194     //p[2] = 120.0;
00195     //shape->setDimensions(p);
00196     bool shapeFound = test->runCanny(shape);
00197 
00198     if(!shapeFound){
00199       //stupid compiler, breaking on stupid warnings
00200     }
00201 
00202     //NOTE: Uncomment the following code to test using multiple starting points
00203 
00204     if(!shapeFound){ //Upper left
00205       p[1] = 60.0; //Xcenter
00206       p[2] = 180.0; //Ycenter
00207       shape->setDimensions(p);
00208       shapeFound = test->runCanny(shape);
00209     }
00210     if(!shapeFound){ //Upper right
00211       p[1] = 260.0; //Xcenter
00212       p[2] = 180.0; //Ycenter
00213       shape->setDimensions(p);
00214       shapeFound = test->runCanny(shape);
00215     }
00216     if(!shapeFound){ //Lower left
00217       p[1] = 60.0; //Xcenter
00218       p[2] = 60.0; //Ycenter
00219       shape->setDimensions(p);
00220       shapeFound = test->runCanny(shape);
00221     }
00222     if(!shapeFound){ //Lower right
00223       p[1] = 260.0; //Xcenter
00224       p[2] = 60.0; //Ycenter
00225       shape->setDimensions(p);
00226       shapeFound = test->runCanny(shape);
00227     }
00228 
00229   }
00230   return 0;
00231 }
00232 
00233 #endif
00234 // ######################################################################
00235 /* So things look consistent in everyone's emacs... */
00236 /* Local Variables: */
00237 /* indent-tabs-mode: nil */
00238 /* End: */
Generated on Sun May 8 08:40:20 2011 for iLab Neuromorphic Vision Toolkit by  doxygen 1.6.3