00001 /*!@file HMAX/test-hmax5.C Test Hmax class and compare to original 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: John McInerney <jmcinerney6@gmail.com> 00034 // $HeadURL: svn://isvn.usc.edu/software/invt/trunk/saliency/src/CUDASIFT/runcudasiftfl.C $ 00035 // $Id: runcudasiftfl.C 12962 2010-03-06 02:13:53Z irock $ 00036 // 00037 00038 00039 #include "Component/ModelManager.H" 00040 #include "GUI/XWindow.H" 00041 #include "Image/Image.H" 00042 #include "Image/ColorOps.H" 00043 #include "Image/CutPaste.H" 00044 #include "Image/Rectangle.H" 00045 #include "Image/MathOps.H" 00046 #include "Image/MatrixOps.H" 00047 #include "Image/Transforms.H" 00048 #include "Image/Convolutions.H" 00049 #include "Media/FrameSeries.H" 00050 #include "nub/ref.h" 00051 #include "Raster/GenericFrame.H" 00052 #include "Raster/Raster.H" 00053 #include "Util/Types.H" 00054 #include "Util/log.H" 00055 #include "SIFT/ScaleSpace.H" 00056 #include "SIFT/VisualObject.H" 00057 #include "SIFT/Keypoint.H" 00058 #include "SIFT/VisualObjectDB.H" 00059 //#include "CUDASIFT/CUDAVisualObjectDB.H" 00060 #include "CUDASIFT/CUDAVisualObject.H" 00061 00062 #include "CUDASIFT/tpimageutil.h" 00063 #include "CUDASIFT/tpimage.h" 00064 #include "CUDASIFT/cudaImage.h" 00065 #include "CUDASIFT/cudaSift.h" 00066 #include "CUDASIFT/cudaSiftH.h" //This one is an addition and null 00067 00068 #include "Util/log.H" 00069 00070 #include <fstream> 00071 #include <iostream> 00072 #include <iomanip> 00073 #include <string> 00074 #include <unistd.h> 00075 #include <cstdio> 00076 #include <dirent.h> 00077 00078 00079 std::vector<std::string> readDir(std::string inName) 00080 { 00081 DIR *dp = opendir(inName.c_str()); 00082 if(dp == NULL) 00083 { 00084 LFATAL("Directory does not exist %s",inName.c_str()); 00085 } 00086 dirent *dirp; 00087 std::vector<std::string> fList; 00088 while ((dirp = readdir(dp)) != NULL ) { 00089 if (dirp->d_name[0] != '.') 00090 fList.push_back(inName + '/' + std::string(dirp->d_name)); 00091 } 00092 LINFO("%"ZU" files in the directory\n", fList.size()); 00093 LINFO("file list : \n"); 00094 for (unsigned int i=0; i<fList.size(); i++) 00095 LINFO("\t%s", fList[i].c_str()); 00096 std::sort(fList.begin(),fList.end()); 00097 return fList; 00098 } 00099 00100 // ###################################################################### 00101 std::vector<std::string> readList(std::string inName) 00102 { 00103 std::ifstream inFile; 00104 inFile.open(inName.c_str(),std::ios::in); 00105 if(!inFile){ 00106 LFATAL("Unable to open image path list file: %s",inName.c_str()); 00107 } 00108 std::string sLine; 00109 std::vector<std::string> fList; 00110 while (std::getline(inFile, sLine)) { 00111 std::cout << sLine << std::endl; 00112 fList.push_back(sLine); 00113 } 00114 LINFO("%"ZU" paths in the file\n", fList.size()); 00115 LINFO("file list : \n"); 00116 for (unsigned int i=0; i<fList.size(); i++) 00117 LINFO("\t%s", fList[i].c_str()); 00118 inFile.close(); 00119 return fList; 00120 } 00121 00122 00123 int main(const int argc, const char **argv) 00124 { 00125 00126 MYLOGVERB = LOG_INFO; 00127 00128 ModelManager *mgr = new ModelManager("Test SIFT with Feature Learning"); 00129 00130 00131 mgr->exportOptions(MC_RECURSE); 00132 00133 // required arguments 00134 // <c1patchesDir> <dir|list> <id> <outputfile> 00135 00136 if (mgr->parseCommandLine( 00137 (const int)argc, (const char**)argv, 00138 "<cudadev> <dir|list:images> <vdbfile>", 3, 3) == false) 00139 return 1; 00140 00141 std::string images,devArg; 00142 std::string vdbFileName; 00143 00144 std::string trainPosName; // Directory where positive images are 00145 00146 devArg = mgr->getExtraArg(0); 00147 images = mgr->getExtraArg(1); 00148 vdbFileName = mgr->getExtraArg(2); 00149 00150 //MemoryPolicy mp = GLOBAL_DEVICE_MEMORY; 00151 int dev = strtol(devArg.c_str(),NULL,0); 00152 std::cout << "device = " << dev << std::endl; 00153 cudaSetDevice(dev); 00154 00155 LINFO("Loading db from %s\n", vdbFileName.c_str()); 00156 VisualObjectDB vdb; 00157 vdb.loadFrom(vdbFileName,false); 00158 00159 00160 std::string::size_type dirArg=images.find("dir:",0); 00161 std::string::size_type listArg=images.find("list:",0); 00162 std::string imagename; 00163 std::string::size_type spos,dpos; 00164 00165 if((dirArg == std::string::npos && 00166 listArg == std::string::npos) || 00167 (dirArg != 0 && listArg != 0)){ 00168 LFATAL("images argument is in one of the following formats - dir:<DIRNAME> or list:<LISTOFIMAGEPATHSFILE>"); 00169 return EXIT_FAILURE; 00170 } 00171 if(dirArg == 0) 00172 images = images.substr(4); 00173 else 00174 images = images.substr(5); 00175 00176 // Now we run if needed 00177 mgr->start(); 00178 00179 std::vector<std::string> imageFileNames; 00180 if(dirArg == 0) 00181 imageFileNames = readDir(images); 00182 else 00183 imageFileNames = readList(images); 00184 00185 for(unsigned int imgInd=0;imgInd<imageFileNames.size();imgInd++){ 00186 Image<float> inputf = Raster::ReadGray(imageFileNames[imgInd]); 00187 00188 //Pick off image name from full path name 00189 spos = imageFileNames[imgInd].find_last_of('/'); 00190 dpos = imageFileNames[imgInd].find_last_of('.'); 00191 imagename = imageFileNames[imgInd].substr(spos+1,dpos-spos-1); 00192 00193 std::cout << "imageFileNames[" << imgInd << "] = " << imageFileNames[imgInd] << std::endl; 00194 std::cout << "spos = " << spos << " ,dpos = " << dpos << std::endl; 00195 std::cout << "imagename = " << imagename << std::endl; 00196 #ifdef GPUSIFT 00197 rutz::shared_ptr<CUDAVisualObject> 00198 vo(new CUDAVisualObject(imagename, imageFileNames[imgInd], inputf, 00199 Point2D<int>(-1,-1), 00200 std::vector<float>(), 00201 std::vector< rutz::shared_ptr<Keypoint> >(), 00202 false,true)); 00203 00204 #else 00205 rutz::shared_ptr<VisualObject> 00206 vo(new VisualObject(imagename,imageFileNames[imgInd], inputf, 00207 Point2D<int>(-1,-1), 00208 std::vector<float>(), 00209 std::vector< rutz::shared_ptr<Keypoint> >(), 00210 false,true)); 00211 #endif 00212 vdb.addObject(vo); 00213 } 00214 00215 std::cout << "Keypoints computed for all images." << std::endl; 00216 std::cout << "Saving visual objects to database." << std::endl; 00217 vdb.saveTo(vdbFileName); 00218 00219 return 0; 00220 } 00221 00222 // ###################################################################### 00223 /* So things look consistent in everyone's emacs... */ 00224 /* Local Variables: */ 00225 /* indent-tabs-mode: nil */ 00226 /* End: */