00001 /*!@file CUDA/test-RegSaliency.C tests the reg saliency code */ 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 00034 // $HeadURL: svn://dparks@isvn.usc.edu/software/invt/trunk/saliency/src/CUDA/test-RegSaliency.C $ 00035 // $Id: test-RegSaliency.C 12962 2010-03-06 02:13:53Z irock $ 00036 // 00037 00038 00039 #include "Component/ModelManager.H" 00040 #include "Image/Image.H" 00041 #include "Image/Pixels.H" 00042 #include "Image/ColorOps.H" 00043 #include "Image/ShapeOps.H" 00044 #include "Image/Transforms.H" 00045 00046 #include "Neuro/NeuroOpts.H" 00047 #include "Raster/Raster.H" 00048 #include "Raster/GenericFrame.H" 00049 #include "Media/FrameSeries.H" 00050 #include "Transport/FrameIstream.H" 00051 #include "Transport/FrameInfo.H" 00052 #include "Transport/FrameOstream.H" 00053 #include "Util/Timer.H" 00054 00055 #include <signal.h> 00056 #include <stdlib.h> 00057 #include <unistd.h> 00058 #include <rutz/rand.h> 00059 00060 00061 // ###################################################################### 00062 int main(const int argc, const char **argv) 00063 { 00064 00065 // instantiate a model manager (for camera input): 00066 ModelManager manager("Exhaustive video scan"); 00067 00068 nub::ref<InputFrameSeries> ifs(new InputFrameSeries(manager)); 00069 manager.addSubComponent(ifs); 00070 00071 // Parse command-line: 00072 if (manager.parseCommandLine(argc, argv, "<outputdir>", 1, 1) == false) return(1); 00073 00074 // ###################################################################### 00075 // let's do it! 00076 manager.start(); 00077 std::string sampleImagesDir; 00078 00079 sampleImagesDir = manager.getExtraArg(0); 00080 00081 00082 ifs->startStream(); 00083 int patchSize=72; 00084 bool quit=false; 00085 // Randomize the seed 00086 //rutz::urand r(time((time_t*)0) + getpid()); 00087 // Don't randomize the seed 00088 int curPickedFrame=0; 00089 rutz::urand r(0); 00090 while(!quit) 00091 { 00092 const FrameState is = ifs->updateNext(); 00093 if (is == FRAME_COMPLETE) 00094 break; 00095 00096 // Sub sample video, randomly pick roughly every N frames 00097 int willPick = r.idraw(100); 00098 00099 if(willPick==0) 00100 { 00101 GenericFrame input = ifs->readFrame(); 00102 if (!input.initialized()) 00103 break; 00104 00105 const Image<PixRGB<byte> > inimg = input.asRgb(); 00106 // Go through image in an exhaustive scan and extract images 00107 Dims pSize = Dims(patchSize,patchSize); 00108 int halfSize = patchSize/2; 00109 int wspan = (inimg.getWidth() / (halfSize*2))*2 - 1; 00110 int hspan = (inimg.getHeight() / (halfSize*2))*2 - 1; 00111 for(int i=0;i<wspan&&!quit;i++) 00112 { 00113 for(int j=0;j<hspan&&!quit;j++) 00114 { 00115 Image<PixRGB<byte> > patch = crop(inimg,Point2D<int>(i*halfSize,j*halfSize),pSize); 00116 Image<PixRGB<byte> > patchResize = rescale(patch, 256, 256); 00117 char fname[200]; 00118 sprintf(fname,"%s/Sample-%d-%d.png",sampleImagesDir.c_str(),curPickedFrame,i*wspan+j); 00119 Raster::WriteRGB(patchResize,fname); 00120 } 00121 } 00122 printf("input frame number %d\n",ifs->frame()); 00123 curPickedFrame++; 00124 } 00125 // // Just randomly pick a location 00126 // int ri = r.idraw(inimg.getWidth()-patchSize); 00127 // int rj = r.idraw(inimg.getHeight()-patchSize); 00128 // const FrameState os = ofs->updateNext(); 00129 // Image<PixRGB<byte> > out = crop(inimg,Point2D<int>(ri,rj),pSize); 00130 // //out = rescaleBilinear(out,inimg.getDims()); 00131 // GenericFrame output = GenericFrame(out); 00132 // ofs->writeFrame(output, "test", 00133 // FrameInfo("exhaustive scan", SRC_POS)); 00134 // if (os == FRAME_FINAL) 00135 // { 00136 // quit=true; 00137 // } 00138 00139 00140 00141 00142 //status = seq->evolve(); 00143 } 00144 00145 // get ready to terminate: 00146 manager.stop(); 00147 00148 return 0; 00149 } 00150 00151 00152 // ###################################################################### 00153 /* So things look consistent in everyone's emacs... */ 00154 /* Local Variables: */ 00155 /* indent-tabs-mode: nil */ 00156 /* End: */