00001 /*!@file AppMedia/stim-eyesal2patch.C image patches from aneyesal file */ 00002 //takes as input an eyesal file, a movie path and a frame duration 00003 00004 // $HeadURL: svn://isvn.usc.edu/software/invt/trunk/saliency/src/AppEye/app-eyesal2patch.C $ 00005 // $Id: app-eyesal2patch.C 10794 2009-02-08 06:21:09Z itti $ 00006 00007 #include "Component/ModelManager.H" 00008 #include "Image/Image.H" 00009 #include "Util/MathFunctions.H" 00010 #include "Image/Pixels.H" 00011 #include "Image/DrawOps.H" 00012 #include "Raster/Raster.H" 00013 #include "Raster/PngWriter.H" 00014 #include "Transport/FrameIstream.H" 00015 #include "Image/Rectangle.H" 00016 #include "Media/MpegInputStream.H" 00017 #include "Media/MediaOpts.H" 00018 #include "GUI/XWindow.H" 00019 #include "Raster/GenericFrame.H" 00020 #include "Psycho/EyesalData.H" 00021 #include "Util/StringConversions.H" 00022 00023 #include <vector> 00024 #include <fstream> 00025 00026 #define RAD 62 00027 00028 int main(const int argc, const char **argv) 00029 { 00030 00031 00032 ModelManager *mgr = new ModelManager("eyesal2patch"); 00033 00034 //hook up mpeg stream 00035 nub::ref<InputMPEGStream> ifs(new InputMPEGStream(*mgr)); 00036 mgr->addSubComponent(ifs); 00037 mgr->exportOptions(MC_RECURSE); 00038 00039 //get some command line stuff 00040 std::string eyesalFile = argv[1];//filename 00041 std::string moviePath = argv[2];//moviepath 00042 const float fdur = fromStr<float>(argv[3]); 00043 00044 EyesalData ed(eyesalFile);//load our eyesal file 00045 00046 // Parse command-line: 00047 if (mgr->parseCommandLine(argc, argv, "", 3, 3) == false) return(1); 00048 00049 // let's get all our ModelComponent instances started: 00050 mgr->start(); 00051 00052 //set up a preview/demo window 00053 Dims screen(800,600); 00054 XWindow win(screen, 0, 0, "Eyesal2patch");//preview window 00055 00056 std::string mname = ""; 00057 std::string fname = ""; 00058 00059 00060 //ok lets, loop through all our saccades 00061 for (size_t ii = 0; ii < ed.size(); ii++){ 00062 00063 //setup our output file 00064 std::string mtfname = ed.getFileName(ii); 00065 size_t idx = mtfname.rfind('.'); 00066 std::string outname = mtfname.substr(0,idx) + "-" + convertToString(ii) + ".png"; 00067 00068 if (ed.getFileName(ii).compare(mname) != 0) { 00069 LINFO("Movie changed::%s",mname.c_str()); 00070 //set our mpeg source 00071 size_t idp = mtfname.find('-'); 00072 mname = mtfname.substr(idp+1); 00073 idx = mname.rfind('.'); 00074 ifs->setFileName(moviePath+mname.substr(0,idx)+".mpg"); 00075 } 00076 00077 Image< PixRGB<byte> > input; 00078 00079 00080 //go to the frame of the saccade 00081 int fnum = (int)ceil((ed.getTime(ii) / fdur) - 1.0F); 00082 if (!ifs->setFrameNumber(fnum)) 00083 break; 00084 00085 //grab the image 00086 input = ifs->readRGB(); 00087 if (!input.initialized()) 00088 break; 00089 00090 Image< PixRGB<byte> > bg(800,600,ZEROS); 00091 inplacePaste(bg,input,Point2D<int>(79,59)); 00092 00093 00094 LINFO("\nSaccade on Frame %d",fnum); 00095 00096 00097 //display the image with saccade location on screen 00098 Point2D<int> cp = ed.getXYpos(ii); 00099 cp.i+=79; 00100 cp.j+=59; 00101 00102 Rectangle rwin = Rectangle::tlbrO(cp.j-RAD,cp.i-RAD,cp.j+RAD,cp.i+RAD); 00103 00104 00105 if (bg.rectangleOk(rwin)){ //only if the point is valid 00106 00107 //grab our image for output 00108 Image< PixRGB<byte> > output = crop(bg,rwin); 00109 PngWriter::writeRGB(output,outname);//output 00110 00111 drawRect(bg,rwin,PixRGB<byte>(0,255,0),2);//paint it 00112 00113 } 00114 else { 00115 LINFO ("Rectangle out of bounds"); 00116 drawDisk(bg,cp,5,PixRGB<byte>(0,255,0)); //if we arent in range 00117 } 00118 00119 //some notes on screen 00120 char str[25]; 00121 sprintf(str,"Saccade: %d\nTime: %g",(int)ii,ed.getTime(ii)); 00122 writeText(bg,Point2D<int>(2,0),str, 00123 PixRGB<byte>(255,0,0),PixRGB<byte>(0,0,0), SimpleFont::FIXED(9)); 00124 win.drawImage(bg,0,0); 00125 00126 //sleep(1); 00127 00128 } 00129 //stop all our modelcomponents 00130 mgr->stop(); 00131 00132 return 0; 00133 } 00134 00135 // ###################################################################### 00136 /* So things look consistent in everyone's emacs... */ 00137 /* Local Variables: */ 00138 /* indent-tabs-mode: nil */ 00139 /* End: */ 00140 00141 00142 00143 00144 00145