00001 /*!@file CMapDemo/SaliencyCMapMT.H A class for quick-and-dirty 00002 saliency mapping integrated with Cmap corba object */ 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: Zack Gossman <gossman@usc.edu> 00034 // $HeadURL: svn://isvn.usc.edu/software/invt/trunk/saliency/src/CMapDemo/SaliencyCMapMT.H $ 00035 // $Id: SaliencyCMapMT.H 13993 2010-09-20 04:54:23Z itti $ 00036 // 00037 00038 #ifndef SALIENCYMT_H_DEFINED 00039 #define SALIENCYMT_H_DEFINED 00040 00041 #include "Image/OpenCVUtil.H" 00042 #include "Component/ModelComponent.H" 00043 #include "Component/ModelParam.H" 00044 #include "Image/ColorOps.H" 00045 #include "Image/Image.H" 00046 #include "Image/ImageSet.H" 00047 #include "Image/MathOps.H" 00048 #include "Image/DrawOps.H" 00049 #include "Image/FilterOps.H" 00050 #include "Image/Pixels.H" 00051 #include "Image/PyramidOps.H" 00052 #include "Image/ShapeOps.H" 00053 #include "Image/Transforms.H" 00054 #include "Image/fancynorm.H" 00055 #include "Util/Types.H" 00056 #include "Image/colorDefs.H" 00057 #include "Corba/Objects/CMapSK.hh" 00058 #include "Corba/ImageOrbUtil.H" 00059 00060 #include <pthread.h> 00061 #include <cstdlib> 00062 #include <unistd.h> 00063 #include <list> 00064 00065 // are we using a local linked cmap server or a remote 00066 // set this if we are running on only one computer 00067 #ifndef LocalCMapServer 00068 //#define LocalCMapServer // use a local linked CMapServer instead of remote 00069 #endif 00070 00071 // ###################################################################### 00072 struct jobData 00073 { 00074 jobData() { }; 00075 00076 jobData(const int jt, const PyramidType pt, const float w, 00077 const float ori = 0.0F) : 00078 jobType(jt), ptyp(pt), weight(w), orientation(ori) { } 00079 00080 int jobType; 00081 PyramidType ptyp; 00082 float weight; 00083 float orientation; 00084 }; 00085 00086 struct biasData 00087 { 00088 CMap::BiasSeq redgreen; 00089 CMap::BiasSeq blueyellow; 00090 CMap::BiasSeq skinhue; 00091 CMap::BiasSeq ori0; 00092 CMap::BiasSeq ori45; 00093 CMap::BiasSeq ori90; 00094 CMap::BiasSeq ori135; 00095 CMap::BiasSeq intensity; 00096 CMap::BiasSeq flicker; 00097 }; 00098 00099 00100 // ###################################################################### 00101 class SaliencyMT : public ModelComponent 00102 { 00103 public: 00104 00105 // action definitions CHANGE TO ENUM? FIX? 00106 #define RETINA 1 00107 #define WINNER 2 00108 #define LUMINANCE 3 00109 #define REDGREEN 4 00110 #define BLUEYELLOW 5 00111 #define ORI0 6 00112 #define ORI45 7 00113 #define ORI90 8 00114 #define ORI135 9 00115 #define CMAP 10 00116 #define FLICKER 11 00117 #define INTENSITY 12 00118 #define SKINHUE 13 00119 00120 // ###################################################################### 00121 /*! @name Constructors and Destructors */ 00122 //@{ 00123 00124 //! Constructor 00125 SaliencyMT(OptionManager& mgr, CORBA::ORB_ptr orb, short saliencyMapLevel, 00126 const std::string& descrName = "SaliencyMT", 00127 const std::string& tagName = "SaliencyMT"); 00128 00129 //! Destructor 00130 ~SaliencyMT(); 00131 00132 //@} 00133 00134 // ###################################################################### 00135 /*! @name member functions */ 00136 //@{ 00137 00138 //! Setup up with image to be processed and build the job queue 00139 void newInput(const Image< PixRGB<byte> > img); 00140 00141 //! Is the last given input done processing? 00142 bool outputReady(); 00143 00144 //! Get last computed output 00145 Image<float> getOutput(); 00146 00147 //! blocking call for getting the saliency map 00148 Image<float> getSMap(Image< PixRGB<byte> > img); 00149 00150 //! For internal thread use: Compute a conspicuity map from an image 00151 void computeCMAP(); 00152 //@} 00153 00154 //! Set the bias values for the given cmap type 00155 void setBias(int type, std::vector<float> &bias); 00156 00157 //! do we bias the saliency map or not 00158 void setBiasSM(bool val); 00159 00160 //! get the bias values for the given cmap type at the specified location 00161 void getBias(Image<PixRGB<byte> > &img, std::vector<float> &bias, int type, Point2D<int> &loc); 00162 00163 //!Number of cmap objects that we have running 00164 int nCmapObj; 00165 //TODO: watch for overflow 00166 CORBA::Object_ptr CMap_ref[100]; //100 is the limit for now 00167 00168 //set the saliency Map Level 00169 void setSaliencyMapLevel(const short saliencyMapLevel); 00170 00171 Image<float> cmaps[14]; //hold the cmaps in memory 00172 00173 void setSMBias(ImageSet<float> &bias); 00174 00175 protected: 00176 OModelParam<uint> itsNumThreads; //!< Number of worker threads to use 00177 00178 void start1(); //!< get started 00179 void stop2(); //!< get stopped 00180 00181 //!The current cmap object to send the request to 00182 CMap_ptr getCmapRef(); 00183 00184 private: 00185 Image< PixRGB<byte> > colima; // current color image 00186 Image<float> lum; //curent luminance image 00187 Image<byte> r, g, b, y; //curent RGBY images 00188 Image<float> prev; // previous float image 00189 Image<float> outmap; // output saliency map 00190 Image<float> skinima; //skin hue map 00191 bool gotLum, gotRGBY, gotSkin; 00192 00193 std::list<jobData> jobQueue; 00194 uint jobsTodo; 00195 00196 // thread stuff 00197 pthread_t *worker; 00198 pthread_mutex_t jobLock, mapLock, jobStatusLock; 00199 pthread_cond_t jobCond; 00200 pthread_cond_t jobDone; 00201 uint numWorkers; 00202 00203 // bias stuff 00204 biasData cmapBias; 00205 bool biasSM; // do we bias the saliency map 00206 ImageSet<float> SMBias; 00207 00208 }; 00209 00210 #endif 00211 00212 // ###################################################################### 00213 /* So things look consistent in everyone's emacs... */ 00214 /* Local Variables: */ 00215 /* indent-tabs-mode: nil */ 00216 /* End: */