00001 /*!@file Neuro/BeoHeadBrain.H A brain for the beo head */ 00002 00003 // //////////////////////////////////////////////////////////////////// // 00004 // The iLab Neuromorphic Vision C++ Toolkit - Copyright (C) 2000-2003 // 00005 // by the 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: Lior Elazary <elazary@usc.edu> 00034 // $HeadURL: svn://isvn.usc.edu/software/invt/trunk/saliency/src/Neuro/BeoHeadBrain.C $ 00035 // $Id: BeoHeadBrain.C 12782 2010-02-05 22:14:30Z irock $ 00036 // 00037 00038 #include "Image/OpenCVUtil.H" // must be first to avoid conflicting defs of int64, uint64 00039 00040 #include "Neuro/BeoHeadBrain.H" 00041 00042 #include "Transport/FrameInfo.H" 00043 #include "Raster/GenericFrame.H" 00044 #include "Util/JobWithSemaphore.H" 00045 00046 //preformace simple rotines like getting image from eyes and tracking 00047 namespace 00048 { 00049 class preBrainLoop : public JobWithSemaphore 00050 { 00051 public: 00052 preBrainLoop(BeoHeadBrain* neoBrain) 00053 : 00054 itsBeoHeadBrain(neoBrain), 00055 itsPriority(1), 00056 itsJobType("PreBrainLoop") 00057 {} 00058 00059 virtual ~preBrainLoop() {} 00060 00061 virtual void run() 00062 { 00063 ASSERT(itsBeoHeadBrain); 00064 while(1) 00065 { 00066 itsBeoHeadBrain->updateEyesImage(); 00067 itsBeoHeadBrain->trackObjects(); //should be one thread for left and right eyes 00068 usleep(1000); 00069 } 00070 } 00071 00072 virtual const char* jobType() const 00073 { return itsJobType.c_str(); } 00074 00075 virtual int priority() const 00076 { return itsPriority; } 00077 00078 private: 00079 BeoHeadBrain* itsBeoHeadBrain; 00080 const int itsPriority; 00081 const std::string itsJobType; 00082 }; 00083 } 00084 00085 // ###################################################################### 00086 BeoHeadBrain::BeoHeadBrain(OptionManager& mgr, 00087 const std::string& descrName, 00088 const std::string& tagName) 00089 : 00090 NeoBrain(mgr, descrName, tagName) 00091 { 00092 itsLeftEye = nub::ref<InputFrameSeries>(new InputFrameSeries(mgr)); 00093 addSubComponent(itsLeftEye); 00094 } 00095 00096 // ###################################################################### 00097 BeoHeadBrain::~BeoHeadBrain() 00098 {} 00099 00100 // ###################################################################### 00101 void BeoHeadBrain::initHead() 00102 { 00103 //setup pid loop thread 00104 itsThreadServer.reset(new WorkThreadServer("preBrainLoop",1)); //start a single worker thread 00105 itsThreadServer->setFlushBeforeStopping(false); 00106 rutz::shared_ptr<preBrainLoop> j(new preBrainLoop(this)); 00107 itsThreadServer->enqueueJob(j); 00108 00109 Dims imageDims = itsLeftEye->peekDims(); 00110 init(imageDims); 00111 } 00112 00113 void BeoHeadBrain::updateEyesImage() 00114 { 00115 const FrameState is = itsLeftEye->updateNext(); 00116 if (is == FRAME_COMPLETE) 00117 return; 00118 00119 //grab the images 00120 GenericFrame input = itsLeftEye->readFrame(); 00121 if (!input.initialized()) 00122 return; 00123 00124 itsCurrentLeftEyeImg = input.asRgb(); 00125 } 00126 00127 Image<PixRGB<byte> > BeoHeadBrain::getLeftEyeImg() 00128 { 00129 return itsCurrentLeftEyeImg; 00130 } 00131 00132 Image<PixRGB<byte> > BeoHeadBrain::getRightEyeImg() 00133 { 00134 return itsCurrentRightEyeImg; 00135 } 00136 00137 // ###################################################################### 00138 void BeoHeadBrain::setTarget(const Point2D<int> loc) 00139 { 00140 this->NeoBrain::setTarget(loc, luminance(itsCurrentLeftEyeImg), -1, false); 00141 } 00142 00143 // ###################################################################### 00144 void BeoHeadBrain::trackObjects() 00145 { 00146 itsCurrentTargetLoc = this->trackObject(luminance(itsCurrentLeftEyeImg)); 00147 } 00148 00149 // ###################################################################### 00150 Point2D<int> BeoHeadBrain::getTargetLoc() 00151 { 00152 return itsCurrentTargetLoc; 00153 } 00154 00155 // ###################################################################### 00156 /* So things look consistent in everyone's emacs... */ 00157 /* Local Variables: */ 00158 /* indent-tabs-mode: nil */ 00159 /* End: */