00001 /*!@file SceneUnderstanding/IT.H */ 00002 00003 // //////////////////////////////////////////////////////////////////// // 00004 // The iLab Neuromorphic Vision C++ Toolkit - Copyright (C) 2000-2005 // 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/plugins/SceneUnderstanding/IT.H $ 00035 // $Id: IT.H 13413 2010-05-15 21:00:11Z itti $ 00036 // 00037 00038 #ifndef IT_H_DEFINED 00039 #define IT_H_DEFINED 00040 00041 #include "Util/Types.H" 00042 #include "Image/Image.H" 00043 #include "Image/ImageSet.H" 00044 #include "Image/Pixels.H" 00045 #include "Image/Layout.H" 00046 #include "Image/Point3D.H" 00047 #include "plugins/SceneUnderstanding/Camera.H" 00048 #include "plugins/SceneUnderstanding/V4.H" 00049 #include "plugins/SceneUnderstanding/V4d.H" 00050 #include "plugins/SceneUnderstanding/V1.H" 00051 #include "Simulation/SimEvents.H" 00052 #include "Simulation/SimModule.H" 00053 #include <vector> 00054 #include <string> 00055 #include <google/dense_hash_map> 00056 using google::dense_hash_map; 00057 00058 class IT : public SimModule 00059 { 00060 public: 00061 00062 enum OBJECT_TYPE {HOUSE, WOMAN, HAT, MAN}; 00063 00064 struct ObjectState 00065 { 00066 Point3D<float> pos; 00067 float rot; 00068 double prob; 00069 double weight; 00070 OBJECT_TYPE objectType; 00071 }; 00072 00073 struct RTableEntry 00074 { 00075 Point2D<int> loc; 00076 float rot; 00077 V4::GEON_TYPE geonType; 00078 }; 00079 00080 struct Object 00081 { 00082 std::vector<V4::GeonState> geons; 00083 OBJECT_TYPE objectType; 00084 std::vector<RTableEntry> rTable; 00085 }; 00086 00087 00088 struct GHTAcc 00089 { 00090 Point2D<int> pos; 00091 int ang; 00092 int scale; 00093 OBJECT_TYPE objectType; 00094 float sum; 00095 00096 bool operator<(const GHTAcc& acc) const 00097 { 00098 return sum < acc.sum; 00099 } 00100 00101 }; 00102 00103 00104 IT(OptionManager& mgr, const std::string& descrName = "IT", 00105 const std::string& tagName = "IT"); 00106 00107 //! Destructor 00108 ~IT(); 00109 00110 void buildRTables(); 00111 void init(Dims dims); 00112 00113 void setInput(const std::vector<V4::GeonState> &geonsState); 00114 00115 void evolve(); 00116 00117 Layout<PixRGB<byte> > getDebugImage(); 00118 00119 void getObjectLikelihood(ObjectState& objectState); 00120 00121 V4::GeonState findNearestGeon(const V4::GeonState& geonState); 00122 double getGeonDistance(const V4::GeonState& g1, const V4::GeonState& g2); 00123 void fixAngle(float& ang); 00124 00125 00126 void resampleParticles(std::vector<ObjectState>& objectParticles); 00127 void proposeParticles(std::vector<ObjectState>& objectParticles, const double Neff); 00128 00129 float evaluateObjectParticles(std::vector<ObjectState>& objectParticles); 00130 00131 //void GHT(Image<float>& acc); 00132 void GHT(std::vector<GHTAcc>& accRet, OBJECT_TYPE objectType); 00133 void voteForFeature(Image<float>& acc, int angIdx, std::vector<RTableEntry>& rTable); 00134 void normalizeAcc(std::vector<GHTAcc>& acc); 00135 00136 Image<float> showParticles(const std::vector<ObjectState>& objectParticles); 00137 00138 void showObject(Image<PixRGB<byte> > &img, Object& object, Point3D<float>& pos, float rot); 00139 00140 protected: 00141 //! Callback for when a new ganglion output is ready 00142 SIMCALLBACK_DECLARE(IT, SimEventV4Output); 00143 00144 //! Callback for every time we should save our outputs 00145 SIMCALLBACK_DECLARE(IT, SimEventSaveOutput); 00146 00147 //! Should we show our debug info 00148 OModelParam<bool> itsShowDebug; 00149 00150 00151 private: 00152 00153 dense_hash_map<int, V4::GeonState> itsHashedGeonsState; 00154 std::vector<V4::GeonState> itsGeonsState; 00155 00156 Camera itsCamera; 00157 00158 std::vector<ObjectState> itsObjectsParticles; 00159 00160 float itsObjectsDist; 00161 00162 std::vector<Point2D<int> > rTable; 00163 00164 Image<float> itsHoughSpace; 00165 00166 std::vector<Object> itsObjects; 00167 00168 }; 00169 00170 // ###################################################################### 00171 /* So things look consistent in everyone's emacs... */ 00172 /* Local Variables: */ 00173 /* indent-tabs-mode: nil */ 00174 /* End: */ 00175 00176 #endif //