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 <fvclassifiers/classifier.h>
32 
33 #include <vector>
34 
35 // FIXME replace with forward declarations
36 #include <surf/image.h>
37 #include <surf/ipoint.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 
58 void saveIpoints(std::string sFileName,
59  const std::vector<surf::Ipoint> &ipts,
60  bool bVerbose,
61  bool bLaplacian,
62  int VLength);
63 
64 void loadIpoints(std::string sFileName, std::vector<surf::Ipoint> &ipts, bool bVerbose, int &);
65 
66 class SurfClassifier : public Classifier
67 {
68 public:
69  //instantiating using descriptor files
70  SurfClassifier(std::string keypoints_descriptor_txt_file,
71  unsigned int min_match = 5,
72  float min_match_ratio = MIN_MATCH_RATIO,
73  int samplingStep = 2,
74  int octaves = 4,
75  double thres = 4.0,
76  bool doubleImageSize = false,
77  int initLobe = 3,
78  bool upright = false,
79  bool extended = false,
80  int indexSize = 4);
81 
82  //instantiating using a directory containing the png images
83  SurfClassifier(const char * image_directory_png_files,
84  unsigned int min_match = 5,
85  float min_match_ratio = MIN_MATCH_RATIO,
86  int samplingStep = 2,
87  int octaves = 4,
88  double thres = 4.0,
89  bool doubleImageSize = false,
90  int initLobe = 3,
91  bool upright = false,
92  bool extended = false,
93  int indexSize = 4);
94 
95  virtual ~SurfClassifier();
96 
97  virtual std::list<ROI> *classify();
98 
99 private:
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 } // end namespace firevision
157 
158 #endif
SURF classifier.
Definition: surf.h:66
virtual std::list< ROI > * classify()
Classify image.
Definition: surf.cpp:521
Fawkes library namespace.
Time tracking utility.
Definition: tracker.h:36
Classifier to extract regions of interest.
Definition: classifier.h:35
SurfClassifier(std::string keypoints_descriptor_txt_file, unsigned int min_match=5, float min_match_ratio=MIN_MATCH_RATIO, int samplingStep=2, int octaves=4, double thres=4.0, bool doubleImageSize=false, int initLobe=3, bool upright=false, bool extended=false, int indexSize=4)
Constructor.
Definition: surf.cpp:216
virtual ~SurfClassifier()
Destructor.
Definition: surf.cpp:515