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 void saveIpoints(std::string sFileName, const std::vector< surf::Ipoint >& ipts, bool bVerbose, bool bLaplacian, int VLength);
00057
00058 void loadIpoints(std::string sFileName, std::vector< surf::Ipoint >& ipts, bool bVerbose, int&);
00059
00060 class SurfClassifier : public Classifier
00061 {
00062  public:
00063          //instantiating using descriptor files
00064   SurfClassifier( std::string keypoints_descriptor_txt_file,
00065                   unsigned int min_match = 5,
00066                   float min_match_ratio = MIN_MATCH_RATIO,
00067                   int samplingStep = 2,
00068                   int octaves = 4,
00069                   double thres = 4.0,
00070                   bool doubleImageSize = false,
00071                   int initLobe = 3,
00072                   bool upright = false,
00073                   bool extended = false,
00074                   int indexSize = 4);
00075
00076         //instantiating using a directory containing the png images
00077   SurfClassifier(const char * image_directory_png_files,
00078                  unsigned int min_match = 5,
00079                  float min_match_ratio = MIN_MATCH_RATIO,
00080                  int samplingStep = 2,
00081                  int octaves = 4,
00082                  double thres = 4.0,
00083                  bool doubleImageSize = false,
00084                  int initLobe = 3,
00085                  bool upright = false,
00086                  bool extended = false,
00087                  int indexSize = 4);
00088
00089   virtual ~SurfClassifier();
00090
00091   virtual std::list< ROI > * classify();
00092
00093  private:
00094
00095   unsigned int __num_obj; // number of objects
00096
00097   // Find closest interest point in a list, given one interest point
00098   int findMatch(const surf::Ipoint& ip1, const std::vector< surf::Ipoint >& ipts);
00099
00100   // Calculate square distance of two vectors
00101   double distSquare(double *v1, double *v2, int n);
00102
00103   // Object objects
00104   surf::Image *__obj_img;
00105   std::vector<std::vector< surf::Ipoint > > __obj_features;
00106   std::vector<std::string> __obj_names;
00107   int __obj_num_features;
00108
00109   // Image objects
00110   surf::Image *__image;
00111   std::vector< surf::Ipoint > __img_features;
00112   int __img_num_features;
00113
00114   // minimum (absolute) number of features that have to be matched per ROI
00115   unsigned int __min_match;
00116   // minimum ratio of features per total object-features that have to be matched per ROI
00117   float __min_match_ratio;
00118
00119   // Initial sampling step (default 2)
00120   int __samplingStep;
00121   // Number of analysed octaves (default 4)
00122   int __octaves;
00123   // Blob response treshold
00124   double __thres;
00125   // Set this flag "true" to double the image size
00126   bool __doubleImageSize;
00127   // Initial lobe size, default 3 and 5 (with double image size)
00128   int __initLobe;
00129   // Upright SURF or rotation invaraiant
00130   bool __upright;
00131   // If the extended flag is turned on, SURF 128 is used
00132   bool __extended;
00133   // Spatial size of the descriptor window (default 4)
00134   int __indexSize;
00135
00136   // Length of descriptor vector
00137   int __vlen;
00138
00139   //#ifdef SURF_TIMETRACKER
00140   fawkes::TimeTracker *__tt;
00141   unsigned int __loop_count;
00142   unsigned int __ttc_objconv;
00143   unsigned int __ttc_objfeat;
00144   unsigned int __ttc_imgconv;
00145   unsigned int __ttc_imgfeat;
00146   unsigned int __ttc_matchin;
00147   unsigned int __ttc_roimerg;
00148   //#endif
00149
00150 };
00151
00152 #endif