00001 /*!@file 00002 Robots/Beobot2/Navigation/FOE_Navigation/test-FOE_PopulationHeadingMap.C 00003 find the FOE using Lappe & Rauschecker 1993's Population Heading Map 00004 algorithm */ 00005 // //////////////////////////////////////////////////////////////////// // 00006 // The iLab Neuromorphic Vision C++ Toolkit - Copyright (C) 2001 by the // 00007 // University of Southern California (USC) and the iLab at USC. // 00008 // See http://iLab.usc.edu for information about this project. // 00009 // //////////////////////////////////////////////////////////////////// // 00010 // Major portions of the iLab Neuromorphic Vision Toolkit are protected // 00011 // under the U.S. patent ``Computation of Intrinsic Perceptual Saliency // 00012 // in Visual Environments, and Applications'' by Christof Koch and // 00013 // Laurent Itti, California Institute of Technology, 2001 (patent // 00014 // pending; application number 09/912,225 filed July 23, 2001; see // 00015 // http://pair.uspto.gov/cgi-bin/final/home.pl for current status). // 00016 // //////////////////////////////////////////////////////////////////// // 00017 // This file is part of the iLab Neuromorphic Vision C++ Toolkit. // 00018 // // 00019 // The iLab Neuromorphic Vision C++ Toolkit is free software; you can // 00020 // redistribute it and/or modify it under the terms of the GNU General // 00021 // Public License as published by the Free Software Foundation; either // 00022 // version 2 of the License, or (at your option) any later version. // 00023 // // 00024 // The iLab Neuromorphic Vision C++ Toolkit is distributed in the hope // 00025 // that it will be useful, but WITHOUT ANY WARRANTY; without even the // 00026 // implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR // 00027 // PURPOSE. See the GNU General Public License for more details. // 00028 // // 00029 // You should have received a copy of the GNU General Public License // 00030 // along with the iLab Neuromorphic Vision C++ Toolkit; if not, write // 00031 // to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, // 00032 // Boston, MA 02111-1307 USA. // 00033 // //////////////////////////////////////////////////////////////////// // 00034 // 00035 // Primary maintainer for this file: Christian Siagian <siagian@usc.edu> 00036 // $HeadURL: $ 00037 // $Id: $ 00038 00039 00040 #include "Component/ModelManager.H" 00041 #include "Media/FrameSeries.H" 00042 00043 #include "Image/Image.H" 00044 #include "Image/Pixels.H" 00045 #include "Raster/Raster.H" 00046 #include "Image/ColorOps.H" 00047 00048 #include "Util/Timer.H" 00049 00050 #include "Robots/Beobot2/Navigation/FOE_Navigation/PopulationHeadingMap.H" 00051 00052 // ###################################################################### 00053 // Function declarations 00054 00055 // ###################################################################### 00056 int main(const int argc, const char **argv) 00057 { 00058 MYLOGVERB = LOG_INFO; // suppress debug messages 00059 00060 // instantiate a model manager: 00061 ModelManager manager("Test Optic Flow"); 00062 00063 nub::ref<InputFrameSeries> ifs(new InputFrameSeries(manager)); 00064 manager.addSubComponent(ifs); 00065 00066 nub::ref<OutputFrameSeries> ofs(new OutputFrameSeries(manager)); 00067 manager.addSubComponent(ofs); 00068 00069 //nub::ref<PopulationHeadingMap> phm(new PopulationHeadingMap(manager)); 00070 rutz::shared_ptr<PopulationHeadingMap> 00071 phm(new PopulationHeadingMap(400.0)); 00072 00073 manager.exportOptions(MC_RECURSE); 00074 00075 if (manager.parseCommandLine((const int)argc, (const char**)argv, 00076 "", 0, 0) == false) 00077 return(1); 00078 00079 // get some options 00080 // if(manager.numExtraArgs() > 0) 00081 // { 00082 // outFilename = manager.getExtraArg(0); 00083 // LINFO("save to: %s", outFilename.c_str()); 00084 // } 00085 00086 // let's do it! 00087 manager.start(); 00088 00089 Timer timer(1000000); 00090 timer.reset(); // reset the timer 00091 int frame = 0; 00092 bool keepGoing = true; 00093 00094 const FrameState is = ifs->updateNext(); 00095 ifs->updateNext(); 00096 Image<PixRGB<byte> > img1 = ifs->readRGB(); ifs->updateNext(); 00097 Image<PixRGB<byte> > img2 = ifs->readRGB(); 00098 Image<PixRGB<byte> > image; 00099 Image<float> stim; 00100 if (is == FRAME_COMPLETE) keepGoing = false; 00101 00102 float flen = 400; 00103 while (keepGoing) 00104 { 00105 if (ofs->becameVoid()) 00106 { 00107 LINFO("quitting because output stream was closed or became void"); 00108 break; 00109 } 00110 00111 // get the frame 00112 const FrameState is = ifs->updateNext(); 00113 if (is == FRAME_COMPLETE) break; // done receiving frames 00114 image = ifs->readRGB(); 00115 00116 // compute the Focus of Expansion 00117 phm->setFocalLength(flen); //flen += 5.0; 00118 phm->getFOE(Image<byte>(luminance(img1)),Image<byte>(luminance(img2))); 00119 //phm->getFOE(Image<byte>(luminance(image))); 00120 00121 ofs->writeRGB(image, "Optic Flow"); 00122 const FrameState os = ofs->updateNext(); 00123 Raster::waitForKey(); 00124 00125 //Raster::WriteRGB(currImage, sformat("image%d.ppm",frame)); 00126 00127 if (os == FRAME_FINAL) break; 00128 00129 frame++; 00130 } 00131 00132 // stop all our ModelComponents 00133 manager.stop(); 00134 00135 // all done! 00136 return 0; 00137 } 00138 00139 // ###################################################################### 00140 /* So things look consistent in everyone's emacs... */ 00141 /* Local Variables: */ 00142 /* indent-tabs-mode: nil */ 00143 /* End: */