00001 /*!@file AppPsycho/psycho-search.C Psychophysics display for a search for a 00002 target that is presented to the observer prior to the search */ 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-search.C $ 00036 // $Id: psycho-search.C 9412 2008-03-10 23:10:15Z farhan $ 00037 // 00038 00039 #include "Component/ModelManager.H" 00040 #include "Image/ColorOps.H" // for makeRGB() 00041 #include "Image/CutPaste.H" // for inplacePaste() 00042 #include "Image/Image.H" 00043 #include "Image/MathOps.H" // for inplaceSpeckleNoise() 00044 #include "Psycho/PsychoDisplay.H" 00045 #include "Psycho/EyeTrackerConfigurator.H" 00046 #include "Psycho/EyeTracker.H" 00047 #include "Psycho/PsychoOpts.H" 00048 #include "Component/EventLog.H" 00049 #include "Component/ComponentOpts.H" 00050 #include "Raster/Raster.H" 00051 #include "Util/MathFunctions.H" 00052 00053 #include <ctype.h> 00054 #include <vector> 00055 00056 //! number of frames in the mask 00057 #define NMASK 10 00058 00059 // ###################################################################### 00060 extern "C" int main(const int argc, char** argv) 00061 { 00062 MYLOGVERB = LOG_INFO; // suppress debug messages 00063 00064 // Instantiate a ModelManager: 00065 ModelManager manager("Psycho Search"); 00066 00067 // Instantiate our various ModelComponents: 00068 nub::soft_ref<PsychoDisplay> d(new PsychoDisplay(manager)); 00069 manager.addSubComponent(d); 00070 00071 nub::soft_ref<EyeTrackerConfigurator> 00072 etc(new EyeTrackerConfigurator(manager)); 00073 manager.addSubComponent(etc); 00074 00075 nub::soft_ref<EventLog> el(new EventLog(manager)); 00076 manager.addSubComponent(el); 00077 00078 manager.setOptionValString(&OPT_EventLogFileName, "psychodata.psy"); 00079 manager.setOptionValString(&OPT_EyeTrackerType, "ISCAN"); 00080 00081 // Parse command-line: 00082 if (manager.parseCommandLine(argc, argv, "<imagelist.txt>", 1, 1) == false) 00083 return(1); 00084 00085 // hook our various babies up and do post-command-line configs: 00086 nub::soft_ref<EyeTracker> et = etc->getET(); 00087 d->setEyeTracker(et); 00088 d->setEventLog(el); 00089 et->setEventLog(el); 00090 00091 // let's get all our ModelComponent instances started: 00092 manager.start(); 00093 00094 // let's prepare the mask images: 00095 SDL_Surface *mask[NMASK]; int mindex[NMASK]; Dims ddims = d->getDims(); 00096 00097 for (int i = 0; i < NMASK; i ++) { 00098 Image<byte> r(ddims, ZEROS), g(ddims, ZEROS), b(ddims, ZEROS); 00099 inplaceSpeckleNoise(r, 1.0F, i+1, 255, true); 00100 inplaceSpeckleNoise(g, 1.0F, i+1, 255, true); 00101 inplaceSpeckleNoise(b, 1.0F, i+1, 255, true); 00102 mask[i] = d->makeBlittableSurface(makeRGB(r, g, b), false); 00103 00104 // keep an array of indices that we will later randomize: 00105 mindex[i] = i; 00106 } 00107 00108 // let's pre-load all the image names so that we can randomize them later: 00109 FILE *f = fopen(manager.getExtraArg(0).c_str(), "r"); 00110 if (f == NULL) LFATAL("Cannot read stimulus file"); 00111 char line[1024]; 00112 std::vector<std::string> ilist, tlist; 00113 while(fgets(line, 1024, f)) 00114 { 00115 // each line has two filenames: first the imagelet that contains 00116 // only the target, second the image that contains the target in 00117 // its environment: 00118 char *line2 = line; while(*line2 != '\0' && !isspace(*line2)) line2 ++; 00119 *line2++ = '\0'; line2[strlen(line2) - 1] = '\0'; 00120 // now line is at the imagelet, line2 at the image 00121 tlist.push_back(std::string(line)); 00122 ilist.push_back(std::string(line2)); 00123 } 00124 fclose(f); 00125 00126 // randomize stimulus presentation order: 00127 int nimg = ilist.size(); int imindex[nimg]; 00128 for (int i = 0; i < nimg; i ++) imindex[i] = i; 00129 randShuffle(imindex, nimg); 00130 00131 // let's display an ISCAN calibration grid: 00132 d->clearScreen(); 00133 d->displayISCANcalib(); 00134 d->waitForKey(); 00135 00136 // let's do an eye tracker calibration: 00137 d->displayText("<SPACE> to calibrate; other key to skip"); 00138 int c = d->waitForKey(); 00139 if (c == ' ') d->displayEyeTrackerCalibration(3, 3); 00140 00141 // we are ready to start: 00142 d->clearScreen(); 00143 d->displayText("<SPACE> to start experiment"); 00144 d->waitForKey(); 00145 00146 // main loop: 00147 for (int im = 0; im < nimg; im ++) { 00148 int imnum = imindex[im]; 00149 00150 // load up the images and show a fixation cross on a blank screen: 00151 d->clearScreen(); 00152 LINFO("Loading '%s' / '%s'...", ilist[imnum].c_str(),tlist[imnum].c_str()); 00153 00154 // get the imagelet and place it at a random position: 00155 Image< PixRGB<byte> > img = Raster::ReadRGB(tlist[imnum]); 00156 Image< PixRGB<byte> > rndimg(d->getDims(), NO_INIT); 00157 rndimg.clear(d->getGrey()); 00158 int rndx = 40 + randomUpToNotIncluding(d->getDims().w() - img.getWidth() - 80); 00159 int rndy = 30 + randomUpToNotIncluding(d->getDims().h() - img.getHeight() - 60); 00160 inplacePaste(rndimg, img, Point2D<int>(rndx, rndy)); 00161 SDL_Surface *surf1 = d->makeBlittableSurface(rndimg, false); 00162 char buf[256]; 00163 sprintf(buf, "===== Showing imagelet: %s at (%d, %d) =====", 00164 tlist[imnum].c_str(), rndx, rndy); 00165 00166 // compute coords of fixation cross centered on imagelet: 00167 int fixx = rndx + img.getWidth() / 2; 00168 int fixy = rndy + img.getHeight() / 2; 00169 00170 // load up the full-scene image: 00171 img = Raster::ReadRGB(ilist[imnum]); 00172 SDL_Surface *surf2 = d->makeBlittableSurface(img, false); 00173 00174 // randomize presentation order of mask frames: 00175 randShuffle(mindex, NMASK); 00176 00177 // give a chance to other processes if single-CPU: 00178 usleep(200000); 00179 00180 // ready to go whenever the user is ready: 00181 d->displayText("Ready"); 00182 d->waitForKey(); 00183 d->waitNextRequestedVsync(false, true); 00184 d->pushEvent(buf); 00185 00186 // show the imagelet: 00187 d->displaySurface(surf1, 0, true); 00188 00189 // wait for a bit (but for a reliable amount of time, so no usleep here): 00190 for (int i = 0; i < 80; i ++) d->waitNextRequestedVsync(); 00191 00192 // show the masks: 00193 d->pushEvent("===== Showing mask ====="); 00194 for (int j = 0; j < NMASK; j ++) 00195 d->displaySurface(mask[mindex[j]], j+1, true); 00196 00197 // show a fixation at center of where imagelet was shown: 00198 d->clearScreen(); 00199 d->displayFixation(fixx, fixy); 00200 for (int i = 0; i < 40; i ++) d->waitNextRequestedVsync(); 00201 00202 // start the eye tracker: 00203 et->track(true); 00204 00205 // show the fixation some more: 00206 for (int i = 0; i < 20; i ++) d->waitNextRequestedVsync(); 00207 00208 // show the image: 00209 d->pushEvent(std::string("===== Showing search image: ") + ilist[imnum] + 00210 std::string(" =====")); 00211 d->displaySurface(surf2, 0, true); 00212 00213 // wait for key; it will record reaction time in the logs: 00214 d->waitForKey(); 00215 00216 // free the imagelet and image: 00217 SDL_FreeSurface(surf1); SDL_FreeSurface(surf2); 00218 00219 // stop the eye tracker: 00220 usleep(150000); 00221 et->track(false); 00222 00223 // let's do a quickie eye tracker calibration once in a while: 00224 if (im > 0 && im % 20 == 0) { 00225 d->displayText("Ready for quick recalibration"); 00226 d->waitForKey(); 00227 d->displayEyeTrackerCalibration(3, 3); 00228 d->clearScreen(); 00229 d->displayText("Ready to continue with the images"); 00230 d->waitForKey(); 00231 } 00232 } 00233 00234 d->clearScreen(); 00235 d->displayText("Experiment complete. Thank you!"); 00236 d->waitForKey(); 00237 00238 // stop all our ModelComponents 00239 manager.stop(); 00240 00241 // free mask images: 00242 for (int i = 0; i < NMASK; i++) SDL_FreeSurface(mask[i]); 00243 00244 // all done! 00245 return 0; 00246 } 00247 00248 // ###################################################################### 00249 /* So things look consistent in everyone's emacs... */ 00250 /* Local Variables: */ 00251 /* indent-tabs-mode: nil */ 00252 /* End: */