test-motion.C

Go to the documentation of this file.
00001 /*!@file RCBot/Motion/test-motion.C test the motion energy alg */
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: Lior Elazary <lelazary@yahoo.com>
00034 // $HeadURL: svn://isvn.usc.edu/software/invt/trunk/saliency/src/RCBot/Motion/test-motion.C $
00035 // $Id: test-motion.C 13756 2010-08-04 21:57:32Z siagian $
00036 //
00037 
00038 #include "Component/ModelManager.H"
00039 #include "Component/OptionManager.H"
00040 #include "Devices/FrameGrabberConfigurator.H"
00041 #include "Image/ColorOps.H"
00042 #include "Image/CutPaste.H"
00043 #include "Image/DrawOps.H"
00044 #include "Image/FilterOps.H"
00045 #include "Image/Image.H"
00046 #include "Image/Layout.H"
00047 #include "Image/MathOps.H"
00048 #include "Image/Pixels.H"
00049 #include "Image/ShapeOps.H"
00050 #include "Image/SimpleFont.H"
00051 #include "Media/FrameSeries.H"
00052 #include "RCBot/Motion/MotionEnergy.H"
00053 #include "Raster/Raster.H"
00054 #include "Transport/FrameInfo.H"
00055 #include "Util/Pause.H"
00056 #include "Util/Timer.H"
00057 #include "Util/Types.H"
00058 #include "Util/csignals.H"
00059 #include "Util/log.H"
00060 #include <math.h>
00061 
00062 // ######################################################################
00063 int main(const int argc, const char **argv)
00064 {
00065   MYLOGVERB = LOG_INFO;  // suppress debug messages
00066 
00067   volatile int signum = 0;
00068   catchsignals(&signum);
00069 
00070   ModelManager manager("Test Motion Energy");
00071 
00072   nub::ref<InputFrameSeries> ifs(new InputFrameSeries(manager));
00073   manager.addSubComponent(ifs);
00074 
00075   nub::ref<OutputFrameSeries> ofs(new OutputFrameSeries(manager));
00076   manager.addSubComponent(ofs);
00077 
00078   if (manager.parseCommandLine((const int)argc, (const char**)argv,
00079                                "?pyrlevel=0? ?magthresh=1500?", 0, 2) == false)
00080     return(1);
00081 
00082   const int pyrlevel =
00083     manager.numExtraArgs() > 0
00084     ? manager.getExtraArgAs<int>(0)
00085     : 0;
00086 
00087   const float magthresh =
00088     manager.numExtraArgs() > 1
00089     ? manager.getExtraArgAs<float>(1)    
00090     : 1500.0f;
00091 
00092   manager.start();
00093 
00094   Timer timer(1000000);
00095   timer.reset();  // reset the timer
00096   int frame = 0;
00097 
00098   MotionEnergyPyrBuilder<byte> motionPyr(Gaussian5, 0.0f, 10.0f, 5,
00099                                          magthresh);
00100 
00101   PauseWaiter p;
00102 
00103   while (1)
00104     {
00105       if (signum != 0)
00106         {
00107           LINFO("quitting because %s was caught", signame(signum));
00108           break;
00109         }
00110 
00111       if (ofs->becameVoid())
00112         {
00113           LINFO("quitting because output stream was closed or became void");
00114           break;
00115         }
00116 
00117       if (p.checkPause())
00118         continue;
00119 
00120       const FrameState is = ifs->updateNext();
00121       if (is == FRAME_COMPLETE) break; // done receiving frames
00122 
00123       Image< PixRGB<byte> > input = ifs->readRGB();
00124       // empty image signifies end-of-stream
00125       if (!input.initialized()) break;
00126       Image<byte> lum = luminance(input);
00127 
00128       motionPyr.updateMotion(lum, pyrlevel+1);
00129 
00130       Image<float> vMotion = motionPyr.buildVerticalMotionLevel(pyrlevel);
00131       Image<float> hMotion = motionPyr.buildHorizontalMotionLevel(pyrlevel);
00132 
00133       Image<float> quad = median3(quadEnergy(vMotion, hMotion));
00134       inplaceNormalize(quad, 0.0F, 255.0F);
00135 
00136       inplaceNormalize(vMotion, 0.0F, 255.0F);
00137       inplaceNormalize(hMotion, 0.0F, 255.0F);
00138 
00139       Image<byte> vimg = vMotion;
00140       writeText(vimg, Point2D<int>(1,1), "Vertical Motion", byte(0), byte(255),
00141                 SimpleFont::fixedMaxWidth(8));
00142 
00143       Image<byte> himg = hMotion;
00144       writeText(himg, Point2D<int>(1,1), "Horizontal Motion", byte(0), byte(255),
00145                 SimpleFont::fixedMaxWidth(8));
00146 
00147       const FrameState os = ofs->updateNext();
00148 
00149       const Layout<byte> disp = vcat(hcat(lum, Image<byte>(quad)), hcat(himg, vimg));
00150 
00151       ofs->writeGrayLayout(disp, "motion-energy",
00152                            FrameInfo("motion energy output images", SRC_POS));
00153 
00154       if (os == FRAME_FINAL)
00155         break;
00156 
00157       frame++;
00158     }
00159 
00160   LINFO("%d frames in %gs (%.2ffps)\n", frame, timer.getSecs(), frame / timer.getSecs());
00161 
00162   // stop all our ModelComponents
00163   manager.stop();
00164 
00165   // all done!
00166   return 0;
00167 
00168 }
00169 
00170 // ######################################################################
00171 /* So things look consistent in everyone's emacs... */
00172 /* Local Variables: */
00173 /* indent-tabs-mode: nil */
00174 /* End: */
Generated on Sun May 8 08:05:35 2011 for iLab Neuromorphic Vision Toolkit by  doxygen 1.6.3