Fawkes API  Fawkes Development Version
surf.h
1 
2 /***************************************************************************
3  * feature.h - Feature-based classifier using OpenCV structures
4  *
5  * Created: Mon Mar 15 15:47:11 2008
6  * Copyright 2008 Stefan Schiffer [stefanschiffer.de]
7  *
8  ****************************************************************************/
9 
10 /* This program is free software; you can redistribute it and/or modify
11  * it under the terms of the GNU General Public License as published by
12  * the Free Software Foundation; either version 2 of the License, or
13  * (at your option) any later version. A runtime exception applies to
14  * this software (see LICENSE.GPL_WRE file mentioned below for details).
15  *
16  * This program is distributed in the hope that it will be useful,
17  * but WITHOUT ANY WARRANTY; without even the implied warranty of
18  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19  * GNU Library General Public License for more details.
20  *
21  * Read the full text in the LICENSE.GPL_WRE file in the doc directory.
22  */
23 
24 #ifndef __FIREVISION_CLASSIFIERS_SURF_H_
25 #define __FIREVISION_CLASSIFIERS_SURF_H_
26 
27 #ifndef HAVE_SURF
28 # error SURF not available, you may not use the SurfClassifier
29 #endif
30 
31 #include <vector>
32 
33 #include <fvclassifiers/classifier.h>
34 
35 // FIXME replace with forward declarations
36 #include <surf/ipoint.h>
37 #include <surf/image.h>
38 //class surf::Ipoint;
39 //class surf::Image;
40 #include <utils/time/clock.h>
41 #include <utils/time/tracker.h>
42 
43 //#define NUM_OBJ 13
44 #define OFFLINE_SURF true // offline reading - reading from descriptors folder
45 #define MIN_MATCH_RATIO 0.05
46 
47 //#ifdef SURF_TIMETRACKER
48 namespace fawkes {
49  class TimeTracker;
50 }
51 //#endif
52 
53 //struct CvMemStorage;
54 //typedef struct _IplImage IplImage;
55 
56 namespace firevision {
57 #if 0 /* just to make Emacs auto-indent happy */
58 }
59 #endif
60 
61 void saveIpoints(std::string sFileName, const std::vector< surf::Ipoint >& ipts, bool bVerbose, bool bLaplacian, int VLength);
62 
63 void loadIpoints(std::string sFileName, std::vector< surf::Ipoint >& ipts, bool bVerbose, int&);
64 
65 class SurfClassifier : public Classifier
66 {
67  public:
68  //instantiating using descriptor files
69  SurfClassifier( std::string keypoints_descriptor_txt_file,
70  unsigned int min_match = 5,
71  float min_match_ratio = MIN_MATCH_RATIO,
72  int samplingStep = 2,
73  int octaves = 4,
74  double thres = 4.0,
75  bool doubleImageSize = false,
76  int initLobe = 3,
77  bool upright = false,
78  bool extended = false,
79  int indexSize = 4);
80 
81  //instantiating using a directory containing the png images
82  SurfClassifier(const char * image_directory_png_files,
83  unsigned int min_match = 5,
84  float min_match_ratio = MIN_MATCH_RATIO,
85  int samplingStep = 2,
86  int octaves = 4,
87  double thres = 4.0,
88  bool doubleImageSize = false,
89  int initLobe = 3,
90  bool upright = false,
91  bool extended = false,
92  int indexSize = 4);
93 
94  virtual ~SurfClassifier();
95 
96  virtual std::list< ROI > * classify();
97 
98  private:
99 
100  unsigned int __num_obj; // number of objects
101 
102  // Find closest interest point in a list, given one interest point
103  int findMatch(const surf::Ipoint& ip1, const std::vector< surf::Ipoint >& ipts);
104 
105  // Calculate square distance of two vectors
106  double distSquare(double *v1, double *v2, int n);
107 
108  // Object objects
109  surf::Image *__obj_img;
110  std::vector<std::vector< surf::Ipoint > > __obj_features;
111  std::vector<std::string> __obj_names;
112  int __obj_num_features;
113 
114  // Image objects
115  surf::Image *__image;
116  std::vector< surf::Ipoint > __img_features;
117  int __img_num_features;
118 
119  // minimum (absolute) number of features that have to be matched per ROI
120  unsigned int __min_match;
121  // minimum ratio of features per total object-features that have to be matched per ROI
122  float __min_match_ratio;
123 
124  // Initial sampling step (default 2)
125  int __samplingStep;
126  // Number of analysed octaves (default 4)
127  int __octaves;
128  // Blob response treshold
129  double __thres;
130  // Set this flag "true" to double the image size
131  bool __doubleImageSize;
132  // Initial lobe size, default 3 and 5 (with double image size)
133  int __initLobe;
134  // Upright SURF or rotation invaraiant
135  bool __upright;
136  // If the extended flag is turned on, SURF 128 is used
137  bool __extended;
138  // Spatial size of the descriptor window (default 4)
139  int __indexSize;
140 
141  // Length of descriptor vector
142  int __vlen;
143 
144  //#ifdef SURF_TIMETRACKER
145  fawkes::TimeTracker *__tt;
146  unsigned int __loop_count;
147  unsigned int __ttc_objconv;
148  unsigned int __ttc_objfeat;
149  unsigned int __ttc_imgconv;
150  unsigned int __ttc_imgfeat;
151  unsigned int __ttc_matchin;
152  unsigned int __ttc_roimerg;
153  //#endif
154 
155 };
156 
157 } // end namespace firevision
158 
159 #endif
SURF classifier.
Definition: surf.h:65
Fawkes library namespace.
Time tracking utility.
Definition: tracker.h:38
Classifier to extract regions of interest.
Definition: classifier.h:37