00001 /*!@file Psycho/testGetPos2.C test if we can get the instanteous eye position from the eyeTracker */ 00002 00003 // //////////////////////////////////////////////////////////////////// // 00004 // The iLab Neuromorphic Vision C++ Toolkit - Copyright (C) 2001 by the // 00005 // University of Southern California (USC) and the iLab at USC. // 00006 // See http://iLab.usc.edu for information about this project. // 00007 // //////////////////////////////////////////////////////////////////// // 00008 // Major portions of the iLab Neuromorphic Vision Toolkit are protected // 00009 // under the U.S. patent ``Computation of Intrinsic Perceptual Saliency // 00010 // in Visual Environments, and Applications'' by Christof Koch and // 00011 // Laurent Itti, California Institute of Technology, 2001 (patent // 00012 // pending; application number 09/912,225 filed July 23, 2001; see // 00013 // http://pair.uspto.gov/cgi-bin/final/home.pl for current status). // 00014 // //////////////////////////////////////////////////////////////////// // 00015 // This file is part of the iLab Neuromorphic Vision C++ Toolkit. // 00016 // // 00017 // The iLab Neuromorphic Vision C++ Toolkit is free software; you can // 00018 // redistribute it and/or modify it under the terms of the GNU General // 00019 // Public License as published by the Free Software Foundation; either // 00020 // version 2 of the License, or (at your option) any later version. // 00021 // // 00022 // The iLab Neuromorphic Vision C++ Toolkit is distributed in the hope // 00023 // that it will be useful, but WITHOUT ANY WARRANTY; without even the // 00024 // implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR // 00025 // PURPOSE. See the GNU General Public License for more details. // 00026 // // 00027 // You should have received a copy of the GNU General Public License // 00028 // along with the iLab Neuromorphic Vision C++ Toolkit; if not, write // 00029 // to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, // 00030 // Boston, MA 02111-1307 USA. // 00031 // //////////////////////////////////////////////////////////////////// // 00032 // 00033 // Primary maintainer for this file: Farhan Baluch <fbaluch@usc.edu> 00034 // $HeadURL: svn://isvn.usc.edu/software/invt/trunk/saliency/src/Psycho/testGetPos2.C $ 00035 // $Id: 00036 // 00037 00038 #include "Component/ModelManager.H" 00039 #include "Image/Image.H" 00040 #include "Psycho/PsychoDisplay.H" 00041 #include "Psycho/EyeTrackerConfigurator.H" 00042 #include "Psycho/EyeTracker.H" 00043 #include "Psycho/PsychoOpts.H" 00044 #include "Component/EventLog.H" 00045 #include "Component/ComponentOpts.H" 00046 #include "Raster/Raster.H" 00047 #include "Util/MathFunctions.H" 00048 #include "Util/Types.H" 00049 #include "Image/DrawOps.H" 00050 #include "Image/CalibrationTransform.H" 00051 #include "Image/AffineTransform.H" 00052 #include "Image/IO.H" 00053 // ###################################################################### 00054 static int submain(const int argc, char** argv) 00055 { 00056 00057 MYLOGVERB = LOG_INFO; // suppress debug messages 00058 00059 00060 00061 // Instantiate a ModelManager: 00062 ModelManager manager("test get eye position"); 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 nub::soft_ref<PsychoDisplay> d(new PsychoDisplay(manager)); 00072 manager.addSubComponent(d); 00073 00074 00075 manager.setOptionValString(&OPT_EventLogFileName, "psychodata.psy"); 00076 manager.setOptionValString(&OPT_EyeTrackerType, "ISCAN"); 00077 00078 // Parse command-line: 00079 if (manager.parseCommandLine(argc, argv, "", 0, 0) == false) 00080 return(1); 00081 00082 00083 // hook our various babies up and do post-command-line configs: 00084 nub::soft_ref<EyeTracker> et = etc->getET(); 00085 et->setEventLog(el); 00086 et->requestQuickEyeS(); 00087 00088 // let's get all our ModelComponent instances started: 00089 manager.start(); 00090 00091 d->setEyeTracker(et); 00092 d->setEventLog(el); 00093 00094 el->pushEvent(std::string("===== Trial 1: =====")); 00095 00096 //lets time stamp event log and start the eyetracker 00097 00098 //here we will start testing the get pos 00099 00100 LINFO("eyescanner started going to start reading stuff"); 00101 // int i=0; 00102 00103 d->clearScreen(); 00104 d->displayISCANcalib(); 00105 d->waitForKey(); 00106 00107 Image< PixRGB<byte> > displayImage (1920,1080, ZEROS); 00108 drawCircle(displayImage, Point2D<int>(1920/2,1080/2), 5, PixRGB<byte>(255,0,0)); 00109 00110 SDL_Surface *surf = d->makeBlittableSurface(displayImage, true); 00111 d->displaySurface(surf, -2); 00112 et->calibrateOnline(d); 00113 Image<double> txf; 00114 Point2D<int> testpoint; 00115 Point2D<int> testpointCalib,testpointD; 00116 00117 /*pts = et->getCalibrationSet(d); 00118 txf = a.computeTransform(pts); 00119 LINFO("transform is..."); 00120 std::cerr << txf << std::endl; 00121 testpoint = et->getEyePos(); 00122 testpointD = Point2D<double>(testpoint); 00123 LINFO("\n testpoint %d,%d",testpoint.i,testpoint.j); 00124 testpointCalib = a.getCalibrated(testpointD);*/ 00125 testpoint = et->getEyePos(); 00126 testpointCalib = et->getCalibEyePos(); 00127 LINFO("\n testpoint %d,%d, calibrated %d,%d",testpoint.i,testpoint.j,testpointCalib.i,testpointCalib.j); 00128 00129 d->clearScreen(); 00130 char tmp[40]; 00131 SDL_Surface *surf2; 00132 LINFO("ready to set tracker to true"); 00133 et->track(true); 00134 while(d->checkForKey() < 0) 00135 { 00136 displayImage.clear(); 00137 testpointCalib = et->getCalibEyePos(); 00138 LINFO("\n testpoint %d,%d, calibrated %d,%d",testpoint.i,testpoint.j,testpointCalib.i,testpointCalib.j); 00139 00140 if(displayImage.coordsOk(testpointCalib)) 00141 { 00142 drawCircle(displayImage, Point2D<int>(testpointCalib), 2, PixRGB<byte>(255,0,0)); 00143 sprintf(tmp,"(%d,%d)",(int)testpointCalib.i,(int)testpointCalib.j); 00144 writeText(displayImage,Point2D<int>(testpointCalib),tmp,PixRGB<byte>(255,0,0),PixRGB<byte>(0,0,0),SimpleFont::FIXED(8)); 00145 surf2 = d->makeBlittableSurface(displayImage, true); 00146 d->displaySurface(surf2, -2); 00147 SDL_FreeSurface(surf2); 00148 } 00149 // i++; 00150 00151 } 00152 00153 00154 // stop the eye tracker: 00155 usleep(50000); 00156 et->track(false); 00157 // stop all our ModelComponents 00158 manager.stop(); 00159 00160 // all done! 00161 return 0; 00162 00163 00164 } 00165 00166 extern "C" int main(const int argc, char** argv) 00167 { 00168 //incase we abort dont want X to die 00169 try 00170 { 00171 return submain(argc,argv); 00172 } 00173 catch (...) 00174 { 00175 REPORT_CURRENT_EXCEPTION; 00176 } 00177 return 1; 00178 } 00179 00180 00181 // ###################################################################### 00182 /* So things look consistent in everyone's emacs... */ 00183 /* Local Variables: */ 00184 /* indent-tabs-mode: nil */ 00185 /* End: */ 00186 00187