app-train-need-for-speed.C

00001 /*!@file AppMedia/app-train-need-for-speed.C */
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/Vgames/app-train-need-for-speed.C $
00035 // $Id: app-train-need-for-speed.C 9412 2008-03-10 23:10:15Z farhan $
00036 //
00037 
00038 #ifndef APPMEDIA_APP_TRAIN_NEED_FOR_SPEED_C_DEFINED
00039 #define APPMEDIA_APP_TRAIN_NEED_FOR_SPEED_C_DEFINED
00040 
00041 #include "GUI/XWinManaged.H"
00042 #include "Image/ColorOps.H"
00043 #include "Image/CutPaste.H"
00044 #include "Image/Image.H"
00045 #include "Image/Pixels.H"
00046 #include "Image/Point2D.H"
00047 #include "Image/ShapeOps.H"
00048 #include "Raster/Raster.H"
00049 #include "Util/log.H"
00050 #include "Util/sformat.H"
00051 #include "Video/VideoFrame.H"
00052 #include "rutz/rand.h"
00053 
00054 #include <fstream>
00055 #include <iostream>
00056 #include <limits>
00057 #include <sstream>
00058 #include <sys/types.h>
00059 #include <unistd.h>
00060 #include <vector>
00061 
00062 int main(const int argc, const char** argv)
00063 {
00064   if (argc != 3)
00065     {
00066       LFATAL("usage: %s <imagelist> <dataout>", argv[0]);
00067     }
00068 
00069   std::vector<std::string> fnames;
00070   std::vector<unsigned char> done;
00071 
00072   {
00073     std::ifstream ifs(argv[1]);
00074 
00075     std::string fname;
00076     while (ifs >> fname)
00077       fnames.push_back(fname);
00078 
00079     ifs.close();
00080   }
00081 
00082   done.resize(fnames.size(), (unsigned char)0);
00083 
00084   rutz::urand_irange rnd(0, int(fnames.size()), int(getpid()));
00085 
00086   const Dims zoomdims(121,69);
00087 
00088   XWinManaged fullwin(Dims(640,480), -1, -1, "full");
00089   XWinManaged zoomwin(zoomdims * 2, -1, -1, "zoom");
00090 
00091   std::ofstream ofs(argv[2], std::ios::app);
00092 
00093   while (1)
00094     {
00095       int p = 0;
00096       do {
00097         p = rnd.draw();
00098       } while (done[p]);
00099 
00100       const char* imname = fnames[p].c_str();
00101       done[p] = 1;
00102 
00103       const VideoFrame vf = VideoFrame::fromFile(imname, Dims(640,480),
00104                                                  VIDFMT_UYVY, false);
00105 
00106       const int bottom = rnd.draw() % 2;
00107 
00108       const VideoFrame vf2 = vf.makeBobDeinterlaced(bottom);
00109 
00110       const Image<PixRGB<byte> > rgb = vf2.toRgb();
00111 
00112       const std::string rgbname = sformat("%s-%d.png", imname, bottom);
00113 
00114       if (Raster::fileExists(rgbname))
00115         {
00116           std::cout << "already exists: " << rgbname << std::endl;
00117           continue;
00118         }
00119 
00120       const Image<PixRGB<byte> > im2 = crop(rgb, Point2D<int>(453, 86), zoomdims);
00121 
00122       fullwin.drawImage(rgb, 0, 0);
00123       zoomwin.drawImage(intXY(im2, true), 0, 0);
00124 
00125       std::cout << imname << "? " << std::flush;
00126 
00127       std::string line;
00128       std::getline(std::cin, line);
00129 
00130       if (line == "end")
00131         break;
00132 
00133       if (line.size() > 0)
00134         {
00135           std::istringstream iss(line);
00136 
00137           std::string s[4];
00138 
00139           iss >> s[0] >> s[1] >> s[2] >> s[3];
00140 
00141           bool ok = true;
00142           bool gotilab = false;
00143 
00144           for (size_t i = 0; i < 4; ++i)
00145             {
00146               if (s[i].length() == 0) ok = false;
00147               else if (s[i] == "ilab") gotilab = true;
00148             }
00149 
00150           if (ok && gotilab)
00151             {
00152               for (size_t i = 0; i < 4; ++i)
00153                 std::cout << s[i] << std::endl;
00154 
00155               ofs << sformat("%-50s\t%8s\t%8s\t%8s\t%8s",
00156                              rgbname.c_str(),
00157                              s[0].c_str(), s[1].c_str(),
00158                              s[2].c_str(), s[3].c_str())
00159                   << std::endl;
00160 
00161               Raster::WriteRGB(rgb, rgbname);
00162             }
00163           else
00164             {
00165               std::cout << "skipped" << std::endl;
00166             }
00167         }
00168     }
00169 
00170 }
00171 
00172 // ######################################################################
00173 /* So things look consistent in everyone's emacs... */
00174 /* Local Variables: */
00175 /* mode: c++ */
00176 /* indent-tabs-mode: nil */
00177 /* End: */
00178 
00179 #endif // APPMEDIA_APP_TRAIN_NEED_FOR_SPEED_C_DEFINED
Generated on Sun May 8 08:07:05 2011 for iLab Neuromorphic Vision Toolkit by  doxygen 1.6.3