surf.h

00001 
00002 /***************************************************************************
00003  *  feature.h - Feature-based classifier using OpenCV structures
00004  *
00005  *  Created: Mon Mar 15 15:47:11 2008
00006  *  Copyright 2008 Stefan Schiffer [stefanschiffer.de]
00007  *
00008  ****************************************************************************/
00009 
00010 /*  This program is free software; you can redistribute it and/or modify
00011  *  it under the terms of the GNU General Public License as published by
00012  *  the Free Software Foundation; either version 2 of the License, or
00013  *  (at your option) any later version. A runtime exception applies to
00014  *  this software (see LICENSE.GPL_WRE file mentioned below for details).
00015  *
00016  *  This program is distributed in the hope that it will be useful,
00017  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00018  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00019  *  GNU Library General Public License for more details.
00020  *
00021  *  Read the full text in the LICENSE.GPL_WRE file in the doc directory.
00022  */
00023 
00024 #ifndef __FIREVISION_CLASSIFIERS_SURF_H_
00025 #define __FIREVISION_CLASSIFIERS_SURF_H_
00026 
00027 #ifndef HAVE_SURF
00028 #  error SURF not available, you may not use the SurfClassifier
00029 #endif
00030 
00031 #include <vector>
00032 
00033 #include <classifiers/classifier.h>
00034 
00035 // FIXME replace with forward declarations
00036 #include <surf/ipoint.h>
00037 #include <surf/image.h>
00038 //class surf::Ipoint;
00039 //class surf::Image;
00040 #include <utils/time/clock.h>
00041 #include <utils/time/tracker.h>
00042 
00043 //#define NUM_OBJ 13
00044 #define OFFLINE_SURF true  // offline reading - reading from descriptors folder
00045 #define MIN_MATCH_RATIO 0.05
00046 
00047 //#ifdef SURF_TIMETRACKER
00048 namespace fawkes {
00049     class TimeTracker;
00050 }
00051 //#endif
00052 
00053 //struct CvMemStorage;
00054 //typedef struct _IplImage IplImage;
00055 
00056 namespace firevision {
00057 #if 0 /* just to make Emacs auto-indent happy */
00058 }
00059 #endif
00060 
00061 void saveIpoints(std::string sFileName, const std::vector< surf::Ipoint >& ipts, bool bVerbose, bool bLaplacian, int VLength);
00062 
00063 void loadIpoints(std::string sFileName, std::vector< surf::Ipoint >& ipts, bool bVerbose, int&);
00064 
00065 class SurfClassifier : public Classifier
00066 {
00067  public:
00068          //instantiating using descriptor files
00069   SurfClassifier( std::string keypoints_descriptor_txt_file,
00070                   unsigned int min_match = 5,
00071                   float min_match_ratio = MIN_MATCH_RATIO,
00072                   int samplingStep = 2,
00073                   int octaves = 4,
00074                   double thres = 4.0,
00075                   bool doubleImageSize = false,
00076                   int initLobe = 3,
00077                   bool upright = false,
00078                   bool extended = false,
00079                   int indexSize = 4);
00080 
00081         //instantiating using a directory containing the png images
00082   SurfClassifier(const char * image_directory_png_files,
00083                  unsigned int min_match = 5,
00084                  float min_match_ratio = MIN_MATCH_RATIO,
00085                  int samplingStep = 2,
00086                  int octaves = 4,
00087                  double thres = 4.0,
00088                  bool doubleImageSize = false,
00089                  int initLobe = 3,
00090                  bool upright = false,
00091                  bool extended = false,
00092                  int indexSize = 4);
00093 
00094   virtual ~SurfClassifier();
00095 
00096   virtual std::list< ROI > * classify();
00097 
00098  private:
00099 
00100   unsigned int __num_obj; // number of objects
00101 
00102   // Find closest interest point in a list, given one interest point
00103   int findMatch(const surf::Ipoint& ip1, const std::vector< surf::Ipoint >& ipts);
00104 
00105   // Calculate square distance of two vectors
00106   double distSquare(double *v1, double *v2, int n);
00107 
00108   // Object objects
00109   surf::Image *__obj_img;
00110   std::vector<std::vector< surf::Ipoint > > __obj_features;
00111   std::vector<std::string> __obj_names;
00112   int __obj_num_features;
00113 
00114   // Image objects
00115   surf::Image *__image;
00116   std::vector< surf::Ipoint > __img_features;
00117   int __img_num_features;
00118 
00119   // minimum (absolute) number of features that have to be matched per ROI
00120   unsigned int __min_match;
00121   // minimum ratio of features per total object-features that have to be matched per ROI
00122   float __min_match_ratio;
00123 
00124   // Initial sampling step (default 2)
00125   int __samplingStep;
00126   // Number of analysed octaves (default 4)
00127   int __octaves;
00128   // Blob response treshold
00129   double __thres;
00130   // Set this flag "true" to double the image size
00131   bool __doubleImageSize;
00132   // Initial lobe size, default 3 and 5 (with double image size)
00133   int __initLobe;
00134   // Upright SURF or rotation invaraiant
00135   bool __upright;
00136   // If the extended flag is turned on, SURF 128 is used
00137   bool __extended;
00138   // Spatial size of the descriptor window (default 4)
00139   int __indexSize;
00140 
00141   // Length of descriptor vector
00142   int __vlen;
00143 
00144   //#ifdef SURF_TIMETRACKER
00145   fawkes::TimeTracker *__tt;
00146   unsigned int __loop_count;
00147   unsigned int __ttc_objconv;
00148   unsigned int __ttc_objfeat;
00149   unsigned int __ttc_imgconv;
00150   unsigned int __ttc_imgfeat;
00151   unsigned int __ttc_matchin;
00152   unsigned int __ttc_roimerg;
00153   //#endif
00154 
00155 };
00156 
00157 } // end namespace firevision
00158 
00159 #endif