psycho-noCheat.C

Go to the documentation of this file.
00001 /*!@file AppPsycho/psycho-noCheat.C Psychophysics display of still images and
00002   check response to prevent cheating*/
00003 
00004 // //////////////////////////////////////////////////////////////////// //
00005 // The iLab Neuromorphic Vision C++ Toolkit - Copyright (C) 2001 by the //
00006 // University of Southern California (USC) and the iLab at USC.         //
00007 // See http://iLab.usc.edu for information about this project.          //
00008 // //////////////////////////////////////////////////////////////////// //
00009 // Major portions of the iLab Neuromorphic Vision Toolkit are protected //
00010 // under the U.S. patent ``Computation of Intrinsic Perceptual Saliency //
00011 // in Visual Environments, and Applications'' by Christof Koch and      //
00012 // Laurent Itti, California Institute of Technology, 2001 (patent       //
00013 // pending; application number 09/912,225 filed July 23, 2001; see      //
00014 // http://pair.uspto.gov/cgi-bin/final/home.pl for current status).     //
00015 // //////////////////////////////////////////////////////////////////// //
00016 // This file is part of the iLab Neuromorphic Vision C++ Toolkit.       //
00017 //                                                                      //
00018 // The iLab Neuromorphic Vision C++ Toolkit is free software; you can   //
00019 // redistribute it and/or modify it under the terms of the GNU General  //
00020 // Public License as published by the Free Software Foundation; either  //
00021 // version 2 of the License, or (at your option) any later version.     //
00022 //                                                                      //
00023 // The iLab Neuromorphic Vision C++ Toolkit is distributed in the hope  //
00024 // that it will be useful, but WITHOUT ANY WARRANTY; without even the   //
00025 // implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR      //
00026 // PURPOSE.  See the GNU General Public License for more details.       //
00027 //                                                                      //
00028 // You should have received a copy of the GNU General Public License    //
00029 // along with the iLab Neuromorphic Vision C++ Toolkit; if not, write   //
00030 // to the Free Software Foundation, Inc., 59 Temple Place, Suite 330,   //
00031 // Boston, MA 02111-1307 USA.                                           //
00032 // //////////////////////////////////////////////////////////////////// //
00033 //
00034 // Primary maintainer for this file: Laurent Itti <itti@usc.edu>
00035 // $HeadURL: svn://isvn.usc.edu/software/invt/trunk/saliency/src/AppPsycho/psycho-noCheat.C $
00036 // $Id: psycho-noCheat.C 8426 2007-05-24 06:57:57Z itti $
00037 //
00038 
00039 #include "Component/ModelManager.H"
00040 #include "Image/Image.H"
00041 #include "Psycho/PsychoDisplay.H"
00042 #include "GUI/GUIOpts.H"
00043 #include "Psycho/EyeTrackerConfigurator.H"
00044 #include "Psycho/EyeTracker.H"
00045 #include "Psycho/PsychoOpts.H"
00046 #include "Component/EventLog.H"
00047 #include "Component/ComponentOpts.H"
00048 #include "Raster/Raster.H"
00049 #include "Util/Types.H"
00050 #include <fstream>
00051 
00052 // ######################################################################
00053 extern "C" int main(const int argc, char** argv)
00054 {
00055   MYLOGVERB = LOG_INFO;  // suppress debug messages
00056 
00057   // Instantiate a ModelManager:
00058   ModelManager manager("Psycho no Cheating");
00059 
00060   // Instantiate our various ModelComponents:
00061   nub::soft_ref<PsychoDisplay> d(new PsychoDisplay(manager));
00062   manager.addSubComponent(d);
00063 
00064   nub::soft_ref<EyeTrackerConfigurator>
00065     etc(new EyeTrackerConfigurator(manager));
00066   manager.addSubComponent(etc);
00067 
00068   nub::soft_ref<EventLog> el(new EventLog(manager));
00069   manager.addSubComponent(el);
00070 
00071   // set some display params
00072   //manager.setOptionValString(&OPT_SDLdisplayDims, "1280x1024");
00073   manager.setOptionValString(&OPT_SDLdisplayDims, "1024x768");
00074   d->setModelParamVal("PsychoDisplayBackgroundColor", PixRGB<byte>(0));
00075   d->setModelParamVal("PsychoDisplayTextColor", PixRGB<byte>(255));
00076   d->setModelParamVal("PsychoDisplayBlack", PixRGB<byte>(255));
00077   d->setModelParamVal("PsychoDisplayWhite", PixRGB<byte>(128));
00078   d->setModelParamVal("PsychoDisplayFixSiz", 5);
00079   d->setModelParamVal("PsychoDisplayFixThick", 5);
00080   manager.setOptionValString(&OPT_EventLogFileName, "psychodata.psy");
00081   manager.setOptionValString(&OPT_EyeTrackerType, "ISCAN");
00082 
00083   // Parse command-line:
00084   if (manager.parseCommandLine(argc, argv, "<fileList>", 1, -1)==false)
00085     return(1);
00086 
00087   // hook our various babies up and do post-command-line configs:
00088   nub::soft_ref<EyeTracker> et = etc->getET();
00089   d->setEyeTracker(et);
00090   d->setEventLog(el);
00091   et->setEventLog(el);
00092 
00093   // let's get all our ModelComponent instances started:
00094   manager.start();
00095 
00096   // let's display an ISCAN calibration grid:
00097   d->clearScreen();
00098   d->displayISCANcalib();
00099   d->waitForKey();
00100 
00101   // let's do an eye tracker calibration:
00102   d->displayText("<SPACE> to calibrate; other key to skip");
00103   int c = d->waitForKey();
00104   if (c == ' ') d->displayEyeTrackerCalibration(3, 3);
00105 
00106   d->clearScreen();
00107 
00108   // setup array of movie indices:
00109   std::ifstream file(manager.getExtraArg(0).c_str());
00110   if (file == 0) LFATAL("Couldn't open object file: '%s'",
00111                         manager.getExtraArg(0).c_str());
00112 
00113   std::string line; int correct = 0, accuracy = 100, total = 0;
00114   while(getline(file, line))
00115     {
00116       // parse the line to get the file names
00117       // format: <image> <noCheat> <checkResponse> <reco>
00118       std::string::size_type end = line.find_first_of(" ");
00119       std::string::size_type start = 0;
00120       int i = 0; std::string imageName, noCheatName, checkName, recoName;
00121       while (end != std::string::npos) {
00122         std::string token = line.substr(start, end-start);
00123         switch(i)
00124           {
00125           case 0:
00126             imageName = token;
00127             break;
00128           case 1:
00129             noCheatName = token;
00130             break;
00131           case 2:
00132             checkName = token;
00133             break;
00134           }
00135         start = end + 1;
00136         end = line.find_first_of(" ", start);
00137         i ++;
00138       }
00139       // last token
00140       recoName = line.substr(start);
00141 
00142       // load up the frame and show a fixation cross on a blank screen:
00143       d->clearScreen();
00144       LINFO("Loading '%s'...", imageName.c_str());
00145       Image< PixRGB<byte> > image =
00146         Raster::ReadRGB(imageName);
00147 
00148       SDL_Surface *surf = d->makeBlittableSurface(image, true);
00149 
00150       LINFO("'%s' ready.", imageName.c_str());
00151 
00152       // ready to go whenever the user is ready:
00153       d->displayText("hit any key when ready");
00154       d->waitForKey();
00155       d->waitNextRequestedVsync(false, true);
00156 
00157       // start the eye tracker:
00158       et->track(true);
00159       d->pushEvent(std::string("===== Showing image: ") +imageName + " =====");
00160 
00161       // blink the fixation:
00162       d->displayFixationBlink();
00163 
00164       // show the image:
00165       d->displaySurface(surf, -2, true);
00166 
00167       // wait for key:
00168       c = d->waitForKey();
00169 
00170       // free the image:
00171       SDL_FreeSurface(surf);
00172 
00173       // stop the eye tracker:
00174       usleep(50000);
00175       et->track(false);
00176 
00177       // flash a random grid of numbers and check response to prevent
00178       // cheating
00179       LINFO("Loading '%s'...", noCheatName.c_str());
00180       Image< PixRGB<byte> > noCheat =
00181         Raster::ReadRGB(noCheatName);
00182 
00183       surf = d->makeBlittableSurface(noCheat, true);
00184 
00185       LINFO("'%s' ready.", noCheatName.c_str());
00186       d->pushEvent(std::string("===== Showing noCheat: ") + noCheatName
00187                    + " =====");
00188 
00189       // flash the image for 99ms:
00190       d->displaySurface(surf, -2, true);
00191       for (int j = 0; j < 3; j ++) d->waitNextRequestedVsync();
00192 
00193        // free the image:
00194       SDL_FreeSurface(surf);
00195 
00196       // wait for response:
00197       d->displayText("Enter the number at the target location");
00198       c = d->waitForKey();
00199       int c2 = d->waitForKey();
00200       std::ifstream check (checkName.c_str());
00201       if (check == 0) LFATAL("Couldn't open check file: '%s'",
00202                              checkName.c_str());
00203       std::string response;
00204       total ++;
00205       while (getline(check, response))
00206         {
00207           LINFO (" reading from %s", checkName.c_str());
00208           LINFO (" subject entered %d%d", c, c2);
00209           LINFO (" reading %c%c from %s", response[0], response[1],
00210                  checkName.c_str());
00211           // check the response
00212           char tmp[40];
00213           if (((int)response[0] == c) && ((int)response[1] == c2))
00214             {
00215               correct ++;
00216               accuracy = correct * 100 / total;
00217               sprintf(tmp, "Correct! Accuracy is %d%%", accuracy);
00218               d->displayText(tmp);
00219               d->pushEvent(std::string("===== Correct ====="));
00220             }
00221           else
00222             {
00223               accuracy = correct * 100 / total;
00224               sprintf(tmp, "Wrong! Accuracy is %d%%", accuracy);
00225               d->displayText(tmp);
00226               d->pushEvent(std::string("===== Wrong ====="));
00227             }
00228 
00229           // maintain display
00230           for (int j = 0; j < 30; j ++) d->waitNextRequestedVsync();
00231         }
00232 
00233     }
00234 
00235   d->clearScreen();
00236   d->displayText("Experiment complete. Thank you!");
00237   d->waitForKey();
00238 
00239   // stop all our ModelComponents
00240   manager.stop();
00241 
00242   // all done!
00243   return 0;
00244 }
00245 
00246 // ######################################################################
00247 /* So things look consistent in everyone's emacs... */
00248 /* Local Variables: */
00249 /* indent-tabs-mode: nil */
00250 /* End: */
Generated on Sun May 8 08:40:09 2011 for iLab Neuromorphic Vision Toolkit by  doxygen 1.6.3