00001 /*!@file BeoSub/BeeBrain/test-ForwardCameraGrab.C grab images from 00002 forward camera */ 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: Michael Montalbo <montalbo@usc.edu> 00034 // $HeadURL: svn://isvn.usc.edu/software/invt/trunk/saliency/src/BeoSub/BeeBrain/test-ForwardCameraGrab.C $ 00035 // $Id: test-ForwardCameraGrab.C 9601 2008-04-09 23:25:01Z beobot $ 00036 // 00037 ////////////////////////////////////////////////////////////////////////// 00038 00039 #include "Component/ModelManager.H" 00040 #include "Media/FrameSeries.H" 00041 #include "Transport/FrameIstream.H" 00042 #include "Raster/Raster.H" 00043 #include "Image/Image.H" 00044 #include "Image/Pixels.H" 00045 #include "GUI/XWinManaged.H" 00046 00047 #include "Media/MediaOpts.H" 00048 #include "Devices/DeviceOpts.H" 00049 #include "Raster/GenericFrame.H" 00050 00051 #include "Image/CutPaste.H" 00052 #include "Image/ShapeOps.H" 00053 00054 #include "Util/Timer.H" 00055 #include <signal.h> 00056 00057 #define NAVG 20 00058 00059 bool goforever = false; 00060 00061 // ###################################################################### 00062 //! Signal handler (e.g., for control-C) 00063 void terminate(int s) 00064 { LERROR("*** INTERRUPT ***"); goforever = false; exit(1); } 00065 00066 // ###################################################################### 00067 int main( int argc, const char* argv[] ) 00068 { 00069 MYLOGVERB = LOG_INFO; 00070 00071 // instantiate a model manager: 00072 ModelManager manager("seabee 2007 competition"); 00073 00074 // Instantiate our various ModelComponents: 00075 nub::soft_ref<InputFrameSeries> ifs(new InputFrameSeries(manager)); 00076 manager.addSubComponent(ifs); 00077 00078 manager.exportOptions(MC_RECURSE); 00079 00080 manager.setOptionValString(&OPT_InputFrameSource, "V4L2"); 00081 manager.setOptionValString(&OPT_FrameGrabberMode, "YUYV"); 00082 manager.setOptionValString(&OPT_FrameGrabberDims, "1024x576"); 00083 manager.setOptionValString(&OPT_FrameGrabberByteSwap, "no"); 00084 manager.setOptionValString(&OPT_FrameGrabberFPS, "30"); 00085 00086 // Parse command-line: 00087 if (manager.parseCommandLine(argc, argv, "", 0, 0) == false) return(1); 00088 00089 int w = ifs->getWidth(), h = ifs->getHeight(); 00090 //int w = 320, h = 240; 00091 std::string dims = convertToString(Dims(w, h)); 00092 LINFO("image size: [%dx%d]", w, h); 00093 manager.setOptionValString(&OPT_InputFrameDims, dims); 00094 00095 manager.setModelParamVal("InputFrameDims", Dims(w, h), 00096 MC_RECURSE | MC_IGNORE_MISSING); 00097 00098 // catch signals and redirect them to terminate for clean exit: 00099 signal(SIGHUP, terminate); signal(SIGINT, terminate); 00100 signal(SIGQUIT, terminate); signal(SIGTERM, terminate); 00101 signal(SIGALRM, terminate); 00102 00103 // let's do it! 00104 manager.start(); 00105 00106 //start streaming 00107 ifs->startStream(); 00108 00109 rutz::shared_ptr<XWinManaged> fwin 00110 (new XWinManaged(Dims(w,h), 20, 20, "Forward Vision Window")); 00111 00112 Timer tim(1000000); uint64 t[NAVG]; float frate = 0.0f; tim.reset(); 00113 goforever = true; uint fNum = 0; 00114 while(goforever) 00115 { 00116 // get and store image 00117 // ifs->updateNext(); 00118 00119 Image<PixRGB<byte> > ima;// = ifs->readRGB(); 00120 00121 const FrameState is = ifs->updateNext(); 00122 if (is == FRAME_COMPLETE) 00123 break; 00124 00125 // grab the images 00126 GenericFrame input = ifs->readFrame(); 00127 if (!input.initialized()) break; 00128 ima = rescale(input.asRgb(), 320,240); 00129 00130 // display the image 00131 //if((fNum % 15) ==0) 00132 fwin->drawImage(ima,0,0); 00133 00134 // compute and show framerate over the last NAVG frames: 00135 t[fNum % NAVG] = tim.get(); tim.reset(); 00136 if (fNum % NAVG == 0 && fNum > 0) 00137 { 00138 uint64 avg = 0ULL; 00139 for(int i = 0; i < NAVG; i ++) avg += t[i]; 00140 frate = 1000000.0F / float(avg) * float(NAVG); 00141 LINFO("[%6d] Frame rate: %6.3f fps -> %8.3f ms/frame", 00142 fNum,frate, 1000.0/frate); 00143 } 00144 00145 std::string saveFNameFwd = sformat("cross_FWD_%07d.ppm", fNum); 00146 LINFO("saving: %s",saveFNameFwd.c_str()); 00147 Raster::WriteRGB(bImg,saveFNameFwd); 00148 00149 fNum++; 00150 } 00151 00152 // we are done 00153 manager.stop(); 00154 return 0; 00155 } 00156 00157 // ###################################################################### 00158 /* So things look consistent in everyone's emacs... */ 00159 /* Local Variables: */ 00160 /* indent-tabs-mode: nil */ 00161 /* End: */