extractframes.C

00001 /*!@file INVT/neovision2.C CUDA-accelerated Neovision2 integrated demo */
00002 
00003 // //////////////////////////////////////////////////////////////////// //
00004 // The iLab Neuromorphic Vision C++ Toolkit - Copyright (C) 2000-2005   //
00005 // by the 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: Rob Peters <rjpeters at usc dot edu>
00034 // $HeadURL: svn://isvn.usc.edu/software/invt/trunk/saliency/src/INVT/neovision2-cuda.C $
00035 // $Id: neovision2-cuda.C 13232 2010-04-15 02:15:06Z dparks $
00036 //
00037 
00038 #include "Component/ModelManager.H"
00039 #include "Image/ColorOps.H"
00040 #include "Image/CutPaste.H"
00041 #include "Image/DrawOps.H"
00042 #include "Image/FilterOps.H"
00043 #include "Image/Image.H"
00044 #include "Image/ImageSet.H"
00045 #include "Image/Layout.H"
00046 #include "Image/MathOps.H"
00047 #include "Image/Pixels.H"
00048 #include "Image/PyramidOps.H"
00049 #include "Image/ShapeOps.H"
00050 #include "Image/Transforms.H"
00051 #include "Media/FrameSeries.H"
00052 #include "Media/MediaOpts.H"
00053 #include "Raster/GenericFrame.H"
00054 #include "Raster/Raster.H"
00055 #include "Transport/FrameInfo.H"
00056 #include "Transport/TransportOpts.H"
00057 #include "Util/csignals.H"
00058 #include "rutz/shared_ptr.h"
00059 #include "rutz/trace.h"
00060 #include "rutz/rand.h"
00061 
00062 #include "CUDA/CudaSaliency.H"
00063 
00064 #include <ctype.h>
00065 #include <deque>
00066 #include <iterator>
00067 #include <limits>
00068 #include <stdlib.h> // for atoi(), malloc(), free()
00069 #include <string.h>
00070 #include <sys/resource.h>
00071 #include <signal.h>
00072 #include <time.h>
00073 #include <vector>
00074 
00075 
00076 
00077 // ######################################################################
00078 int submain(int argc, const char** argv)
00079 {
00080   volatile int signum = 0;
00081   signal(SIGPIPE, SIG_IGN);
00082   catchsignals(&signum);
00083 
00084   // Instantiate our various ModelComponents:
00085 
00086   ModelManager manager("Nv2");
00087 
00088   nub::ref<InputFrameSeries> ifs(new InputFrameSeries(manager));
00089   manager.addSubComponent(ifs);
00090 
00091 
00092   if (manager.parseCommandLine((const int)argc, (const char**)argv, "<sampleimagesdir>", 1, 1) == false)
00093     return 1;
00094 
00095   manager.exportOptions(MC_RECURSE);
00096 
00097   manager.start();
00098 
00099   std::string sampleImagesDir;
00100 
00101   sampleImagesDir = manager.getExtraArg(0);
00102 
00103 
00104   int retval = 0;
00105   ifs->startStream();
00106   const GenericFrameSpec fspec = ifs->peekFrameSpec();
00107   // Randomize the seed
00108   //rutz::urand r(time((time_t*)0) + getpid());
00109   // Don't randomize the seed, i want the same frames each time
00110   rutz::urand r(0);
00111 
00112   int curPickedFrame=0;
00113 
00114   while (true)
00115     {
00116       if (signum != 0) {
00117         LINFO("quitting because %s was caught", signame(signum));
00118         retval = -1;
00119         break;
00120       }
00121 
00122       //
00123       // get the next frame from our input source
00124       //
00125       const FrameState is = ifs->updateNext();
00126       if (is == FRAME_COMPLETE) break;
00127 
00128       // Sub sample video, randomly pick roughly every N frames
00129       int willPick = r.idraw(100);
00130 
00131       if(willPick==0)
00132         {
00133 
00134           GenericFrame input = ifs->readFrame();
00135           if (!input.initialized()) break;
00136 
00137           const Image<PixRGB<byte> > rgbin = input.asRgb();
00138 
00139           char fname[200];
00140           sprintf(fname,"%s/Frame-%d.png",sampleImagesDir.c_str(),curPickedFrame);
00141           Raster::WriteRGB(rgbin,fname);
00142           curPickedFrame++;
00143         }
00144     }
00145 
00146   manager.stop();
00147   return retval;
00148 }
00149 
00150 // ######################################################################
00151 int main(int argc, const char** argv)
00152 {
00153   try {
00154     return submain(argc, argv);
00155   } catch (...) {
00156     REPORT_CURRENT_EXCEPTION;
00157   }
00158 }
00159 
00160 // ######################################################################
00161 /* So things look consistent in everyone's emacs... */
00162 /* Local Variables: */
00163 /* mode: c++ */
00164 /* indent-tabs-mode: nil */
00165 /* End: */
Generated on Sun May 8 08:40:57 2011 for iLab Neuromorphic Vision Toolkit by  doxygen 1.6.3