GeometricHashing.H

00001 /*!@file SceneUnderstanding/GeometricHashing.H  Shape from shading */
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/FeatureMatching/GeometricHashing.H $
00035 // $Id: GeometricHashing.H 12962 2010-03-06 02:13:53Z irock $
00036 //
00037 
00038 #ifndef GeometricHashing_H_DEFINED
00039 #define GeometricHashing_H_DEFINED
00040 
00041 #include "Util/Types.H"
00042 #include "Image/Image.H"
00043 #include "Image/Pixels.H"
00044 #include "Image/ImageSet.H"
00045 #include "Image/Point2D.H"
00046 #include "Image/Point3D.H"
00047 
00048 #include <vector>
00049 
00050 class GeometricHashing
00051 {
00052 public:
00053 
00054   struct Model
00055   {
00056     int id;
00057     std::vector<Point2D<int> > v;
00058     Point3D<float> rot;
00059   };
00060 
00061   struct ModelTableEntry
00062   {
00063     int modelId;
00064     Point3D<float> rot;
00065     Point2D<float> featureLoc;
00066     uint basisP1;
00067     uint basisP2;
00068   };
00069 
00070   struct Acc
00071   {
00072     uint P1;
00073     uint P2;
00074     uint inputP1;
00075     uint inputP2;
00076     int modelId;
00077     Point3D<float> rot;
00078     Point2D<float> center;
00079     int votes;
00080   };
00081 
00082   struct AccCmp
00083   {
00084     bool operator()(const Acc& c1, const Acc& c2)
00085     {
00086       return c1.votes > c2.votes;
00087     }
00088   };
00089 
00090 
00091   struct TableEntry
00092   {
00093     std::vector<ModelTableEntry> modelEntries;
00094   };
00095 
00096 
00097 
00098   GeometricHashing();
00099 
00100   //! Destructor
00101   virtual ~GeometricHashing();
00102 
00103   //! Add a model to search for
00104   void addModel(const Model& model);
00105 
00106   //! Change basis based on p1 and p2
00107   //First scale and rotate the model to p1p2
00108   //the center the model to the cetner of p1p2
00109   std::vector<Point2D<float> > changeBasis(
00110       const std::vector<Point2D<int> >& featureLoc,
00111       int p1, int p2);
00112 
00113   std::vector<Point2D<float> > changeBasis(
00114       const std::vector<Point2D<int> >& featureLoc,
00115       Point2D<int> tl, Point2D<int> br);
00116 
00117   //! Add a feature to hash table
00118   void insertToHashTable(const Point2D<float> loc,
00119       int p1, int p2, int modelId, Point3D<float> rot);
00120 
00121   //! Find features in the hash table
00122   Image<TableEntry>::iterator findInHash(const Point2D<float>& loc);
00123 
00124   //! Get votes for a given input
00125   std::vector<Acc> getVotes(std::vector<Point2D<int> >& input);
00126 
00127 
00128   //!Show the hash table
00129   Image<PixRGB<byte> > getHashTableImage();
00130 
00131   //! Write hash table to disk
00132   void writeTable(const char* filename);
00133 
00134   //! Read table from disk
00135   void readTable(const char* filename);
00136 
00137 private:
00138   std::vector<Model> itsModels; //A list of models
00139   Image<TableEntry> itsHashTable;
00140   float itsTableWidth;
00141   int itsNumFeatures;
00142   int itsNumBinEntries;
00143 
00144 
00145 };
00146 
00147 
00148 // ######################################################################
00149 /* So things look consistent in everyone's emacs... */
00150 /* Local Variables: */
00151 /* indent-tabs-mode: nil */
00152 /* End: */
00153 
00154 #endif //
Generated on Sun May 8 08:04:46 2011 for iLab Neuromorphic Vision Toolkit by  doxygen 1.6.3