LandmarkDB.H

Go to the documentation of this file.
00001 /*!@file Beobot/LandmarkDB.H manages groups of landmarks, which includes
00002   spatial,geographical, temporal and episodic information               */
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: Christian Siagian <siagian@usc.edu>
00034 // $HeadURL: svn://isvn.usc.edu/software/invt/trunk/saliency/src/Beobot/LandmarkDB.H $
00035 // $Id: LandmarkDB.H 10794 2009-02-08 06:21:09Z itti $
00036 //
00037 //////////////////////////////////////////////////////////////////////////
00038 /* LandmarkDB manages groups of landmarks, which includes
00039    spatial, geographical, temporal, and episodic information
00040 */
00041 #ifndef BEOBOT_LANDMARKDB_H_DEFINED
00042 #define BEOBOT_LANDMARKDB_H_DEFINED
00043 
00044 #include "Beobot/Landmark.H"
00045 
00046 //! difference in frame number before landmark is considered inactive
00047 #define NFDIFF 20
00048 
00049 //! LandmarkDB class
00050 class LandmarkDB
00051 {
00052 public:
00053 
00054   // ######################################################################
00055   /*! @name Constructors, assignment, and Destructors */
00056   //
00057 
00058   //! Constructor
00059   LandmarkDB(uint nSegment = 0);
00060 
00061   //! Destructor
00062   ~LandmarkDB();
00063 
00064   //! set the window to debug
00065   inline void setWindow(rutz::shared_ptr<XWinManaged> win);
00066 
00067   //! clear and resize the DB to the passed in number
00068   inline void resize(uint nSegment);
00069 
00070   //! add landmark to segment snum
00071   inline void addLandmark(uint snum, rutz::shared_ptr<Landmark> lmk);
00072 
00073   //@}
00074 
00075   // ######################################################################
00076   /*! @name access functions */
00077   //@{
00078 
00079   //! get the number of segments
00080   inline uint getNumSegment();
00081 
00082   //! get the number of landmark in segNum
00083   inline uint getNumSegLandmark(uint segNum);
00084 
00085   //! get the requested landmark
00086   inline rutz::shared_ptr<Landmark> getLandmark(uint segNum, uint lmkNum);
00087 
00088   //! get the length traveled given the object index in the database
00089   float getLenTrav(uint snum, uint lnum, uint index);
00090 
00091   //! get the location range of a landmark
00092   inline std::pair<float,float> getLocationRange(uint snum, uint lnum);
00093 
00094   //! get the session length (in frame numbers) of a session
00095   //uint getSessionLength(std::string sname);
00096 
00097   //! print and display the database
00098   void display();
00099 
00100   //@}
00101 
00102   // ######################################################################
00103   /*! @name member functions */
00104   //@{
00105 
00106   /*! build and finishBuild are 2 functions that needs to be called
00107     to create landmarks.
00108     build is called repeatedly every time new evidence comes in.
00109     finishBuild is called at the end to wrap up the process.
00110     It prunes all the ephemeral landmarks.
00111 
00112     Usually build and actual use are done on seperate session.
00113 
00114     Before use, need to call setSession function to get the landmarks
00115     sorted and all the session related info reset
00116   */
00117 
00118   //! build the landmarkDB by inputting the Visual Object, etc information
00119   void build
00120   ( std::vector<rutz::shared_ptr<VisualObject> > &inputVO,
00121     std::vector<Point2D<int> > &objOffset, uint fNum, uint currSegNum,
00122     rutz::shared_ptr<VisualObject> scene);
00123 
00124   //! wrap up the building process by pruning small landmarks
00125   void finishBuild(uint rframe);
00126 
00127   //! set the session information
00128   //! must call this after finished building a landmark db
00129   //! to sort and then set session related information
00130   void setSession(std::string sessionFName, bool sort = true);
00131 
00132   //! sort landmarks according to the session names order
00133   void sortLandmarks();
00134 
00135   //@}
00136 
00137 private:
00138 
00139   //! its input full image scenes
00140   std::vector<rutz::shared_ptr<VisualObject> > itsScenes;
00141 
00142   //! its landmark array
00143   std::vector<std::vector<rutz::shared_ptr<Landmark> > > itsLandmarks;
00144 
00145   //! store the information if the landmark is currently being built
00146   std::vector<std::vector<bool> > itsActiveLmkList;
00147 
00148   //! all the visual objects skipped in building process
00149   std::vector<rutz::shared_ptr<VisualObject> > itsSkipList;
00150 
00151   //! session information
00152   std::vector<std::string> itsSessionNames;
00153   std::vector<uint> itsSessionLength;
00154 
00155   //! the landmark database for each sessions
00156   //! NOTE: this information is current as of the last setSessionInfo
00157   std::vector<std::vector<std::vector<rutz::shared_ptr<Landmark> > > >
00158   itsSessionLandmarks;
00159 
00160   std::vector<std::vector<std::pair<float,float> > >
00161   itsLandmarkLocationRange;
00162 
00163   //! display window to debug
00164   rutz::shared_ptr<XWinManaged> itsWin;
00165 
00166   // ######################################################################
00167   //! @name Compute functions (all the inner-working functions)
00168   //@{
00169 
00170   //! filter out visual objects that have 5 keypoints or less
00171   void kpFilter
00172   ( std::vector<rutz::shared_ptr<VisualObject> > &inputVO,
00173     std::vector<Point2D<int> > &objOffset);
00174 
00175   //! get the offset distance score
00176   float getOffsetDistScore
00177   ( rutz::shared_ptr<Landmark> landmark, int indb, int intdb, int tindex,
00178     rutz::shared_ptr<VisualObject> vo, Point2D<int> offset, Dims sDims,
00179     rutz::shared_ptr<VisualObjectMatch> cmatch);
00180 
00181   //! get the overlap score
00182   float getOverlapScore(rutz::shared_ptr<VisualObjectMatch> cmatch);
00183 
00184   //! print scores used in processing input
00185   void printScores
00186   ( std::vector<rutz::shared_ptr<VisualObject> > inputVO,
00187     int currSegNum, std::vector<std::vector<float> > inscores);
00188 
00189   //! calculate the best/2ndbest match ratio between landmarks
00190   //! find the best inputVO to Landmark match using the passed in ratio
00191   void findBestMatch
00192   (std::vector<std::vector<float> > scores, std::vector<float> &ratio,
00193    std::vector<bool> &inserted, std::vector<bool> &lmatched,
00194    float &mratio, int &mind, std::vector<int> &mlist);
00195 
00196   //! classify which landmark is no longer active
00197   //! once a landmark is inactive, it can be re-activate
00198   void classifyInactiveLandmarks(uint fNum, uint nfDiff, bool print = false);
00199 
00200   //! prune landmarks that have less that minimal number of objects
00201   void pruneLandmarks();
00202 
00203   //! display all the images that have small number of keypoints
00204   void printSkiplist();
00205 
00206   //! set the landmark range for each session
00207   void setSessionInfo();
00208 
00209   //! create a session based landmark access
00210   void setSessionLandmarks();
00211 
00212   // set the location range for each landmark
00213   void setLocationRange();
00214 
00215   //@}
00216 
00217 };
00218 
00219 // ######################################################################
00220 // Implementation for LandmarkDB inline functions
00221 // ######################################################################
00222 
00223 inline void LandmarkDB::setWindow(rutz::shared_ptr<XWinManaged> win)
00224 {
00225   itsWin = win;
00226 
00227   // set window for each landmark as well
00228   for(uint i = 0; i < itsLandmarks.size(); i++)
00229     for(uint j = 0; j < itsLandmarks[i].size(); j++)
00230     itsLandmarks[i][j]->setMatchWin(win);
00231 }
00232 
00233 inline void LandmarkDB::resize(uint nSegment)
00234 {
00235   itsLandmarks.clear();
00236   itsLandmarks.resize(nSegment);
00237   itsActiveLmkList.clear();
00238   itsActiveLmkList.resize(nSegment);
00239   itsSkipList.clear();
00240 }
00241 
00242 inline void LandmarkDB::addLandmark(uint snum, rutz::shared_ptr<Landmark> lmk)
00243 {
00244   ASSERT(snum < itsLandmarks.size());
00245   itsLandmarks[snum].push_back(lmk);
00246   itsActiveLmkList[snum].push_back(true);
00247 }
00248 
00249 inline uint LandmarkDB::getNumSegment()
00250 {
00251   return itsLandmarks.size();
00252 }
00253 
00254 inline uint LandmarkDB::getNumSegLandmark(uint segNum)
00255 {
00256   ASSERT(segNum < itsLandmarks.size());
00257   return itsLandmarks[segNum].size();
00258 }
00259 
00260 inline rutz::shared_ptr<Landmark>
00261 LandmarkDB::getLandmark(uint segNum, uint lmkNum)
00262 {
00263   ASSERT(segNum < itsLandmarks.size() &&
00264          lmkNum < itsLandmarks[segNum].size());
00265   return itsLandmarks[segNum][lmkNum];
00266 }
00267 
00268 inline std::pair<float,float>
00269 LandmarkDB::getLocationRange(uint snum, uint lnum)
00270 {
00271   ASSERT(snum < itsLandmarks.size());
00272   ASSERT(lnum < itsLandmarks[snum].size());
00273 
00274   return itsLandmarkLocationRange[snum][lnum];
00275 }
00276 
00277 #endif
00278 
00279 // ######################################################################
00280 /* So things look consistent in everyone's emacs... */
00281 /* Local Variables: */
00282 /* indent-tabs-mode: nil */
00283 /* End: */
Generated on Sun May 8 08:40:12 2011 for iLab Neuromorphic Vision Toolkit by  doxygen 1.6.3