psycho-movie-rating.C
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038 #include "Component/ModelManager.H"
00039 #include "Image/Image.H"
00040 #include "GUI/GUIOpts.H"
00041 #include "Media/MrawvInputStream.H"
00042 #include "Media/MediaOpts.H"
00043 #include "Psycho/PsychoDisplay.H"
00044 #include "Psycho/EyeTrackerConfigurator.H"
00045 #include "Psycho/EyeTracker.H"
00046 #include "Psycho/PsychoOpts.H"
00047 #include "Component/EventLog.H"
00048 #include "Component/ComponentOpts.H"
00049 #include "Util/MathFunctions.H"
00050 #include "Util/Types.H"
00051 #include "Video/VideoFrame.H"
00052 #include "rutz/time.h"
00053 #include "Util/sformat.H"
00054
00055 #include <deque>
00056
00057 #define CACHELEN 350
00058
00059
00060
00061
00062 static bool cacheFrame(nub::soft_ref<MrawvInputStream>& mp,
00063 std::deque<VideoFrame>& cache)
00064 {
00065 const VideoFrame frame = mp->readFrame().asVideo();
00066 if (!frame.initialized()) return false;
00067
00068 cache.push_front(frame);
00069 return true;
00070 }
00071
00072
00073 static int submain(const int argc, char** argv)
00074 {
00075 MYLOGVERB = LOG_INFO;
00076
00077
00078 ModelManager manager("Psycho Movie");
00079
00080
00081 nub::soft_ref<MrawvInputStream> mp
00082 (new MrawvInputStream(manager, "Input Raw Video Stream",
00083 "MrawvInputStream"));
00084 manager.addSubComponent(mp);
00085
00086 nub::soft_ref<EventLog> el(new EventLog(manager));
00087 manager.addSubComponent(el);
00088
00089 nub::soft_ref<EyeTrackerConfigurator>
00090 etc(new EyeTrackerConfigurator(manager));
00091 manager.addSubComponent(etc);
00092
00093 nub::soft_ref<PsychoDisplay> d(new PsychoDisplay(manager));
00094 manager.addSubComponent(d);
00095
00096
00097 manager.setOptionValString(&OPT_EventLogFileName, "psychodata.psy");
00098 manager.setOptionValString(&OPT_EyeTrackerType, "None");
00099 manager.setOptionValString(&OPT_SDLdisplayDims, "1280x1024");
00100
00101
00102 if (manager.parseCommandLine(argc, argv,
00103 "<movie1.mraw> ... <movieN.mraw>",
00104 1, -1) == false)
00105 return(1);
00106
00107
00108 nub::soft_ref<EyeTracker> et = etc->getET();
00109 d->setEyeTracker(et);
00110 d->setEventLog(el);
00111 et->setEventLog(el);
00112
00113
00114 if (etc->getModelParamString("EyeTrackerType").compare("EL") == 0)
00115 d->setModelParamVal("SDLslaveMode", true);
00116
00117
00118 manager.start();
00119
00120
00121 et->calibrate(d);
00122
00123
00124 d->clearScreen();
00125 d->displayText("<SPACE> for random play; other key for ordered");
00126 int c = d->waitForKey();
00127
00128
00129 uint nbmovies = manager.numExtraArgs(); int index[nbmovies];
00130 for (uint i = 0; i < nbmovies; i ++) index[i] = i;
00131 if (c == ' ') { LINFO("Randomizing movies..."); randShuffle(index,nbmovies);}
00132
00133
00134 for (uint i = 0; i < nbmovies; i ++)
00135 {
00136
00137 d->clearScreen();
00138 bool streaming = true;
00139 LINFO("Buffering '%s'...", manager.getExtraArg(index[i]).c_str());
00140 mp->setFileName(manager.getExtraArg(index[i]));
00141
00142 std::deque<VideoFrame> cache;
00143 for (uint j = 0; j < CACHELEN; j ++)
00144 {
00145 streaming = cacheFrame(mp, cache);
00146 if (streaming == false) break;
00147 }
00148 LINFO("'%s' ready.", manager.getExtraArg(index[i]).c_str());
00149
00150
00151 sleep(1); if (system("/bin/sync")) LERROR("error in sync");
00152
00153
00154 d->displayFixation();
00155
00156
00157 d->waitForKey(); int frame = 0;
00158 d->waitNextRequestedVsync(false, true);
00159 d->pushEvent(std::string("===== Playing movie: ") +
00160 manager.getExtraArg(index[i]) + " =====");
00161
00162
00163 et->track(true);
00164
00165
00166 d->displayFixationBlink();
00167
00168
00169 if (cache.size() == 0) LFATAL("Zero-frame movie?");
00170 const int ovw = cache[0].getDims().w();
00171 const int ovh = cache[0].getDims().h();
00172 d->createVideoOverlay(VIDFMT_YUV420P, ovw, ovh);
00173 const int ovx = (d->getWidth() - ovw) / 2;
00174 const int ovy = (d->getHeight() - ovh) / 2;
00175
00176
00177 rutz::time start = rutz::time::wall_clock_now();
00178 while(cache.size())
00179 {
00180
00181 if (streaming) streaming = cacheFrame(mp, cache);
00182
00183
00184 VideoFrame vidframe = cache.back();
00185 d->displayVideoOverlay_pos(vidframe, frame,
00186 SDLdisplay::NEXT_VSYNC,
00187 ovx, ovy, ovw, ovh);
00188 cache.pop_back();
00189
00190 ++frame;
00191 }
00192 rutz::time stop = rutz::time::wall_clock_now();
00193 const double secs = (stop-start).sec();
00194 LINFO("%d frames in %.02f sec (~%.02f fps)", frame, secs, frame/secs);
00195
00196
00197
00198
00199
00200 d->destroyYUVoverlay();
00201 d->clearScreen();
00202
00203
00204 usleep(50000);
00205 et->track(false);
00206
00207
00208 d->displayText("Please score this movie (1=bad .. 5=excellent)");
00209 do { c = d->waitForKey(); } while (c < '1' || c > '5');
00210 d->pushEvent(sformat("== Rating for %s = %d ==",
00211 manager.getExtraArg(index[i]).c_str(), c - '0'));
00212
00213
00214 et->recalibrate(d);
00215 }
00216
00217 d->clearScreen();
00218 d->displayText("Experiment complete. Thank you!");
00219 d->waitForKey();
00220
00221
00222 manager.stop();
00223
00224
00225 return 0;
00226 }
00227
00228
00229 extern "C" int main(const int argc, char** argv)
00230 {
00231
00232
00233
00234
00235 try
00236 {
00237 return submain(argc, argv);
00238 }
00239 catch (...)
00240 {
00241 REPORT_CURRENT_EXCEPTION;
00242 }
00243
00244 return 1;
00245 }
00246
00247
00248
00249
00250
00251