00001 /*!@file Psycho/testGetPos.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/testGetPos.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 00087 // let's get all our ModelComponent instances started: 00088 manager.start(); 00089 00090 d->setEyeTracker(et); 00091 d->setEventLog(el); 00092 00093 el->pushEvent(std::string("===== Trial 1: =====")); 00094 00095 //lets time stamp event log and start the eyetracker 00096 //et->track(true); 00097 //here we will start testing the get pos 00098 00099 LINFO("eyescanner started going to start reading stuff"); 00100 // int i=0; 00101 00102 d->clearScreen(); 00103 d->displayISCANcalib(); 00104 d->waitForKey(); 00105 00106 Image< PixRGB<byte> > displayImage (1920,1080, ZEROS); 00107 drawCircle(displayImage, Point2D<int>(1920/2,1080/2), 5, PixRGB<byte>(255,0,0)); 00108 00109 SDL_Surface *surf = d->makeBlittableSurface(displayImage, true); 00110 d->displaySurface(surf, -2); 00111 00112 CalibrationTransform::Data pts; 00113 AffineTransform a; 00114 Image<double> txf; 00115 Point2D<int> testpoint; 00116 Point2D<double> testpointCalib,testpointD; 00117 00118 LINFO("precalib"); 00119 pts = et->getCalibrationSet(d); 00120 LINFO("postcalib"); 00121 txf = a.computeTransform(pts); 00122 LINFO("transform is..."); 00123 std::cerr << txf << std::endl; 00124 testpoint = et->getEyePos(); 00125 testpointD = Point2D<double>(testpoint); 00126 LINFO("\n testpoint %d,%d",testpoint.i,testpoint.j); 00127 testpointCalib = a.getCalibrated(testpointD); 00128 LINFO("\n testpoint %d,%d, calibrated %f,%f",testpoint.i,testpoint.j,testpointCalib.i,testpointCalib.j); 00129 d->clearScreen(); 00130 00131 //now for a live demo of real time eyetracking 00132 char tmp[40]; 00133 00134 //SDL_Surface *surf2; 00135 00136 while(d->checkForKey() < 0) 00137 { 00138 displayImage.clear(); 00139 testpoint = et->getEyePos(); 00140 testpointD = Point2D<double>(testpoint); 00141 testpointCalib = a.getCalibrated(testpointD); 00142 LINFO("\n testpoint %d,%d, calibrated %f,%f",testpoint.i,testpoint.j,testpointCalib.i,testpointCalib.j); 00143 drawCircle(displayImage, Point2D<int>(testpointCalib), 2, PixRGB<byte>(255,0,0)); 00144 sprintf(tmp,"(%d,%d)",(int)testpointCalib.i,(int)testpointCalib.j); 00145 writeText(displayImage,Point2D<int>(testpointCalib),tmp,PixRGB<byte>(255,0,0),PixRGB<byte>(0,0,0),SimpleFont::FIXED(8)); 00146 // d->displayImage(displayImage, true, PixRGB<byte>(), -2); 00147 SDL_Surface *surf2 = d->makeBlittableSurface(displayImage, true); 00148 d->displaySurface(surf2, -2); 00149 SDL_FreeSurface(surf2); 00150 // i++; 00151 00152 } 00153 00154 // struct EyeposEvent 00155 // { 00156 // uint64; 00157 // float x, y; 00158 // }; 00159 00160 // std::vector<EyeposEvent> evs; 00161 // evs.reserve(100000); 00162 00163 // stop the eye tracker: 00164 usleep(50000); 00165 et->track(false); 00166 // stop all our ModelComponents 00167 manager.stop(); 00168 00169 // all done! 00170 return 0; 00171 00172 00173 } 00174 00175 extern "C" int main(const int argc, char** argv) 00176 { 00177 //incase we abort dont want X to die 00178 try 00179 { 00180 return submain(argc,argv); 00181 } 00182 catch (...) 00183 { 00184 REPORT_CURRENT_EXCEPTION; 00185 } 00186 return 1; 00187 } 00188 00189 00190 // ###################################################################### 00191 /* So things look consistent in everyone's emacs... */ 00192 /* Local Variables: */ 00193 /* indent-tabs-mode: nil */ 00194 /* End: */ 00195 00196