00001 /*!@file BeoSub/test-BeoSubPipe.C find pipe */ 00002 // //////////////////////////////////////////////////////////////////// // 00003 // The iLab Neuromorphic Vision C++ Toolkit - Copyright (C) 2001 by the // 00004 // University of Southern California (USC) and the iLab at USC. // 00005 // See http://iLab.usc.edu for information about this project. // 00006 // //////////////////////////////////////////////////////////////////// // 00007 // Major portions of the iLab Neuromorphic Vision Toolkit are protected // 00008 // under the U.S. patent ``Computation of Intrinsic Perceptual Saliency // 00009 // in Visual Environments, and Applications'' by Christof Koch and // 00010 // Laurent Itti, California Institute of Technology, 2001 (patent // 00011 // pending; application number 09/912,225 filed July 23, 2001; see // 00012 // http://pair.uspto.gov/cgi-bin/final/home.pl for current status). // 00013 // //////////////////////////////////////////////////////////////////// // 00014 // This file is part of the iLab Neuromorphic Vision C++ Toolkit. // 00015 // // 00016 // The iLab Neuromorphic Vision C++ Toolkit is free software; you can // 00017 // redistribute it and/or modify it under the terms of the GNU General // 00018 // Public License as published by the Free Software Foundation; either // 00019 // version 2 of the License, or (at your option) any later version. // 00020 // // 00021 // The iLab Neuromorphic Vision C++ Toolkit is distributed in the hope // 00022 // that it will be useful, but WITHOUT ANY WARRANTY; without even the // 00023 // implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR // 00024 // PURPOSE. See the GNU General Public License for more details. // 00025 // // 00026 // You should have received a copy of the GNU General Public License // 00027 // along with the iLab Neuromorphic Vision C++ Toolkit; if not, write // 00028 // to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, // 00029 // Boston, MA 02111-1307 USA. // 00030 // //////////////////////////////////////////////////////////////////// // 00031 // 00032 // Primary maintainer for this file: Michael Montalbo <montalbo@usc.edu> 00033 // $HeadURL: svn://isvn.usc.edu/software/invt/trunk/saliency/src/BeoSub/test-BeoSubPipe.C $ 00034 // $Id: test-BeoSubPipe.C 8542 2007-07-07 21:20:07Z beobot $ 00035 00036 #include "Component/ModelManager.H" 00037 00038 #include "Media/FrameSeries.H" 00039 #include "Transport/FrameIstream.H" 00040 #include "Media/MediaOpts.H" 00041 00042 #include "Image/Image.H" 00043 #include "Image/Pixels.H" 00044 #include "Raster/Raster.H" 00045 00046 #include "GUI/XWinManaged.H" 00047 00048 #include "BeoSub/BeoSubPipe.H" 00049 00050 00051 //END CAMERA STUFF 00052 //canny 00053 #define BOOSTBLURFACTOR 90.0 00054 #define FREE_ARG char* 00055 //#define PI 3.14159 00056 #define FILLBLEED 4 00057 #define INITIAL_TEMPERATURE 30.0 00058 #define FINAL_TEMPERATURE 0.5 00059 #define ALPHA 0.98 00060 #define STEPS_PER_CHANGE 1000 00061 00062 #define BIN_ANGLE 0.588001425 00063 00064 int main(int argc, char* argv[]) 00065 { 00066 00067 MYLOGVERB = LOG_INFO; 00068 00069 ModelManager manager("ComplexObject Tester"); 00070 00071 nub::soft_ref<InputFrameSeries> ifs(new InputFrameSeries(manager)); 00072 manager.addSubComponent(ifs); 00073 00074 manager.exportOptions(MC_RECURSE); 00075 00076 // Parse command-line: 00077 if (manager.parseCommandLine(argc, argv, 00078 "[image {*.ppm}]", 00079 0, 1) 00080 == false) return(1); 00081 00082 // do post-command-line configs: 00083 00084 std::string infilename; //Name of the input image 00085 bool hasCompIma = false; 00086 Image<PixRGB<byte> > compIma; 00087 if(manager.numExtraArgs() > 0) 00088 { 00089 infilename = manager.getExtraArgAs<std::string>(0); 00090 compIma = Raster::ReadRGB(infilename); 00091 hasCompIma = true; 00092 } 00093 00094 int w = ifs->getWidth(), h = ifs->getHeight(); 00095 std::string dims = convertToString(Dims(w, h)); 00096 LINFO("image size: [%dx%d]", w, h); 00097 manager.setOptionValString(&OPT_InputFrameDims, dims); 00098 00099 manager.setModelParamVal("InputFrameDims", Dims(w, h), 00100 MC_RECURSE | MC_IGNORE_MISSING); 00101 00102 manager.start(); 00103 bool goforever = true; 00104 00105 rutz::shared_ptr<XWinManaged> inWin;//, resWin; 00106 inWin.reset(new XWinManaged(Dims(w,h), 0, 0, "Camera Input")); 00107 //resWin.reset(new XWinManaged(Dims(w,h), w+10, 0, "Pipe Direction Output")); 00108 00109 // input and output image 00110 Image< PixRGB<byte> > ima; 00111 Image< PixRGB<byte> > outputIma; 00112 00113 rutz::shared_ptr<BeoSubPipe> pipeRecognizer(new BeoSubPipe()); 00114 //(infilename, showMatches, objectname); 00115 00116 // need an initial image if no comparison image is found 00117 if(!hasCompIma) 00118 { 00119 // ifs->updateNext(); ima = ifs->readRGB(); 00120 // if(!ima.initialized()) goforever = false; 00121 // else compIma = ima; 00122 compIma.resize(w,h,NO_INIT); 00123 } 00124 00125 std::vector < Image< PixRGB<byte> > > imageList; 00126 00127 int cycle = 0; 00128 while(goforever) 00129 { 00130 LINFO("CYCLE %d\n", ++cycle); 00131 00132 // for(int i = 0; i < 15; i++) 00133 // { 00134 // ifs->updateNext(); 00135 // imageList.push_back(ifs->readRGB()); 00136 // if(!(imageList[i]).initialized()) break; 00137 // } 00138 00139 // for(uint i = 0; i < imageList.size(); i++) 00140 // { 00141 // float angle = pipeRecognizer->pipeOrientation(imageList[i], compIma); 00142 // LINFO("Pipe Direction: %f", angle); 00143 // inWin->drawImage(imageList[i],0,0); 00144 // //resWin->drawImage(outputImg); 00145 00146 // if(!hasCompIma) compIma = imageList[i]; 00147 // } 00148 00149 // imageList.clear(); 00150 00151 ifs->updateNext(); ima = ifs->readRGB(); 00152 if(!ima.initialized()) {Raster::waitForKey(); break; } 00153 inWin->drawImage(ima,0,0); 00154 00155 float angle = pipeRecognizer->pipeOrientation(ima, compIma); 00156 LINFO("Pipe Direction: %f", angle); 00157 //resWin->drawImage(outputImg); 00158 00159 // if(!hasCompIma) compIma = ima; 00160 00161 00162 } 00163 00164 // get ready to terminate: 00165 manager.stop(); 00166 return 0; 00167 } 00168 00169 // ###################################################################### 00170 /* So things look consistent in everyone's emacs... */ 00171 /* Local Variables: */ 00172 /* indent-tabs-mode: nil */ 00173 /* End: */