00001
00002
00003
00004
00005
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
00035 nub::ref<InputMPEGStream> ifs(new InputMPEGStream(*mgr));
00036 mgr->addSubComponent(ifs);
00037 mgr->exportOptions(MC_RECURSE);
00038
00039
00040 std::string eyesalFile = argv[1];
00041 std::string moviePath = argv[2];
00042 const float fdur = fromStr<float>(argv[3]);
00043
00044 EyesalData ed(eyesalFile);
00045
00046
00047 if (mgr->parseCommandLine(argc, argv, "", 3, 3) == false) return(1);
00048
00049
00050 mgr->start();
00051
00052
00053 Dims screen(800,600);
00054 XWindow win(screen, 0, 0, "Eyesal2patch");
00055
00056 std::string mname = "";
00057 std::string fname = "";
00058
00059
00060
00061 for (size_t ii = 0; ii < ed.size(); ii++){
00062
00063
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
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
00081 int fnum = (int)ceil((ed.getTime(ii) / fdur) - 1.0F);
00082 if (!ifs->setFrameNumber(fnum))
00083 break;
00084
00085
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
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)){
00106
00107
00108 Image< PixRGB<byte> > output = crop(bg,rwin);
00109 PngWriter::writeRGB(output,outname);
00110
00111 drawRect(bg,rwin,PixRGB<byte>(0,255,0),2);
00112
00113 }
00114 else {
00115 LINFO ("Rectangle out of bounds");
00116 drawDisk(bg,cp,5,PixRGB<byte>(0,255,0));
00117 }
00118
00119
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
00127
00128 }
00129
00130 mgr->stop();
00131
00132 return 0;
00133 }
00134
00135
00136
00137
00138
00139
00140
00141
00142
00143
00144
00145