00001 /*!@file BeoSub/test-BeoSubTaskDecoder.C */ 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: Laurent Itti <itti@usc.edu> 00034 // $HeadURL: svn://isvn.usc.edu/software/invt/trunk/saliency/src/BeoSub/test-BeoSubTaskDecoder.C $ 00035 // $Id: test-BeoSubTaskDecoder.C 8521 2007-06-28 17:45:49Z rjpeters $ 00036 // 00037 00038 #ifndef TESTBEOSUBTASKDECODER_H_DEFINED 00039 #define TESTBEOSUBTASKDECODER_H_DEFINED 00040 00041 00042 #include "Component/ModelManager.H" 00043 00044 #include "Media/FrameSeries.H" 00045 #include "Transport/FrameIstream.H" 00046 #include "Media/MediaOpts.H" 00047 00048 #include "Image/Image.H" 00049 #include "Image/Pixels.H" 00050 #include "Raster/Raster.H" 00051 00052 #include "GUI/XWinManaged.H" 00053 00054 #include "BeoSub/BeoSubTaskDecoder.H" 00055 00056 #include "Image/ImageSet.H" 00057 #include "Util/Timer.H" 00058 #include "Util/Types.H" 00059 #include "Util/log.H" 00060 00061 #include <string> 00062 00063 #define NAVG 20 00064 00065 int main(int argc, char **argv) 00066 { 00067 00068 ModelManager manager("Frame Grabber Tester"); 00069 00070 // Instantiate our various ModelComponents: 00071 nub::soft_ref<InputFrameSeries> ifs(new InputFrameSeries(manager)); 00072 manager.addSubComponent(ifs); 00073 00074 nub::soft_ref<BeoSubTaskDecoder> test(new BeoSubTaskDecoder(manager)); 00075 manager.addSubComponent(test); 00076 00077 manager.exportOptions(MC_RECURSE); 00078 00079 // Parse command-line: 00080 if (manager.parseCommandLine(argc, argv, "", 0, 0) == false) return(1); 00081 00082 // do post-command-line configs: 00083 int w = ifs->getWidth(), h = ifs->getHeight(); 00084 std::string dims = convertToString(Dims(w, h)); 00085 LINFO("image size: [%dx%d]", w, h); 00086 manager.setOptionValString(&OPT_InputFrameDims, dims); 00087 manager.setModelParamVal("InputFrameDims", Dims(w, h), 00088 MC_RECURSE | MC_IGNORE_MISSING); 00089 00090 // let's get all our ModelComponent instances started: 00091 manager.start(); 00092 00093 // get ready for main loop: 00094 rutz::shared_ptr<XWinManaged> win(new XWinManaged(Dims(w,h), 200, 200, "input window")); 00095 Timer tim; uint64 t[NAVG]; int frame = 0; 00096 00097 // get the frame grabber to start streaming: 00098 00099 00100 //Parse the command line options 00101 // char *colorArg = NULL; //Color for tracking 00102 00103 //if(argc < 2){ 00104 // fprintf(stderr,"\n<USAGE> %s color \n",argv[0]); 00105 // fprintf(stderr," color: Color to track\n"); 00106 // fprintf(stderr," Candidates: Green, Red\n"); 00107 // exit(1); 00108 //} 00109 //colorArg = argv[1]; 00110 //printf("READ: 1: %s\n", colorArg); 00111 00112 00113 00114 00115 00116 //Load in config file for camera FIX: put in a check whether config file exists! 00117 //mgr.loadConfig("camconfig.pmap"); 00118 00119 00120 00121 00122 //mgr.start(); 00123 00124 00125 float avg2 = 0.0; 00126 00127 Image< PixRGB<byte> > img; 00128 00129 bool goforever = true; 00130 while(goforever){ 00131 00132 ImageSet< PixRGB<byte> > input; 00133 for(int i = 0; i < 100; i++){ 00134 tim.reset(); 00135 00136 ifs->updateNext(); img = ifs->readRGB(); 00137 if(!img.initialized()) break; 00138 win->drawImage(img,0,0); 00139 input.push_back(img); 00140 00141 char buf[32]; 00142 sprintf(buf, "image%d.ppm", i); 00143 Raster::WriteRGB(img, buf); 00144 00145 uint64 t0 = tim.get(); // to measure display time 00146 t[frame % NAVG] = tim.get(); 00147 t0 = t[frame % NAVG] - t0; 00148 // compute and show framerate over the last NAVG frames: 00149 if (frame % NAVG == 0 && frame > 0) 00150 { 00151 uint64 avg = 0ULL; for (int i = 0; i < NAVG; i ++) avg += t[i]; 00152 avg2 = 1000.0F / float(avg) * float(NAVG); 00153 } 00154 frame ++; 00155 } 00156 00157 LINFO("fps: %f", avg2); 00158 test->setupDecoder("Red", true); 00159 test->runDecoder(input, avg2); 00160 float hertz = test->calculateHz(); 00161 00162 printf("\n\nFinal hertz calculated is: %f\n\n", hertz); 00163 Raster::waitForKey(); 00164 } 00165 00166 manager.stop(); 00167 return 0; 00168 } 00169 00170 #endif 00171 // ###################################################################### 00172 /* So things look consistent in everyone's emacs... */ 00173 /* Local Variables: */ 00174 /* indent-tabs-mode: nil */ 00175 /* End: */