00001 // -*- C++ -*- $Id: KeypointFilter.h,v 1.15 2014/01/16 15:17:38 jorma Exp $ 00002 // 00003 // Copyright 2009-2014 PicSOM Development Group <picsom@cis.hut.fi> 00004 // Aalto University School of Science and Technology 00005 // Department of Information and Computer Science 00006 // P.O.BOX 15400, FI-00076 Aalto, FINLAND 00007 // 00008 00009 #ifndef _KeypointFilter_h_ 00010 #define _KeypointFilter_h_ 00011 00012 // pre-2.2 OpenCV: 00013 //#include <opencv/cv.h> 00014 //#include <opencv/highgui.h> 00015 00016 // 2.2 and beyond OpenCV: 00017 #include <opencv2/core/core.hpp> 00018 #include <opencv2/highgui/highgui.hpp> 00019 #include <opencv2/features2d/features2d.hpp> 00020 00021 #include <ctype.h> 00022 #include <stdio.h> 00023 #include <stdlib.h> 00024 00025 #include <iostream> 00026 #include <string> 00027 #include <fstream> 00028 #include <vector> 00029 #include <iterator> 00030 00031 #include "od_defs.h" 00032 00033 #ifdef USE_LIBSVM 00034 #include <svm.h> 00035 #endif 00036 00037 using namespace std; 00038 00040 class KeypointFilter { 00041 00042 public: 00043 00045 KeypointFilter() { 00046 name = ""; 00047 namestring = "XXX"; 00048 threshold = 0; 00049 } 00050 00052 void SetDebug(size_t d) { debug = d; } 00053 00055 void SetFilter(const string &f, size_t t) { 00056 name = f; 00057 threshold = t; 00058 } 00059 00061 void SetNameString(const string &s) { 00062 namestring = s; 00063 } 00064 00066 virtual bool LoadFilter(int size=0) = 0; 00067 00069 virtual void FilterDescriptors(const vector<cv::KeyPoint> &keyps, 00070 const cv::Mat &descs) = 0; 00071 00074 bool IsInUse() const { return name != ""; } 00075 00077 virtual bool IsLoaded() const = 0; 00078 00080 string NameString() { return namestring; } 00081 00084 vector<bool> keypoint_ok; 00085 00086 protected: 00087 00089 size_t debug; 00090 00092 string name; 00093 00095 string namestring; 00096 00098 size_t threshold; 00099 00100 }; // class KeypointFilter 00101 00103 class ClusterFilter : public KeypointFilter { 00104 00105 public: 00106 00108 ClusterFilter() { 00109 codebook = NULL; 00110 namestring = "filt"; 00111 } 00112 00114 bool IsLoaded() const { return codebook != NULL; } 00115 00117 bool LoadFilter(int size=0); 00118 00122 void FilterDescriptors(const vector<cv::KeyPoint> &keyps, 00123 const cv::Mat &descs); 00124 00125 protected: 00126 00128 cv::Mat *codebook; 00129 00130 }; // class ClusterFilter 00131 00132 #ifdef USE_LIBSVM 00133 00135 class SVMFilter : public KeypointFilter { 00136 00137 public: 00138 00140 SVMFilter() { 00141 model = NULL; 00142 namestring = "svmfilt"; 00143 } 00144 00146 bool IsLoaded() const { return model != NULL; } 00147 00149 bool LoadFilter(int size=0); 00150 00154 void FilterDescriptors(const vector<cv::KeyPoint> &keyps, 00155 const cv::Mat &descs); 00156 00157 protected: 00158 00160 struct svm_model* model; 00161 00163 int svm_type; 00164 00166 int nr_class; 00167 00169 double svmthreshold; 00170 00172 struct svm_node* ConvertVector(const cv::Mat &v); 00173 00174 }; // class SVMFilter 00175 00176 #endif 00177 00179 class RandomFilter : public KeypointFilter { 00180 00181 public: 00182 00184 RandomFilter() { 00185 namestring = "rndfilt"; 00186 } 00187 00189 bool IsLoaded() const { return true; } 00190 00192 bool LoadFilter(int size=0); 00193 00197 void FilterDescriptors(const vector<cv::KeyPoint> &keyps, 00198 const cv::Mat &descs); 00199 00200 }; // class RandomFilter 00201 00203 class HessianFilter : public KeypointFilter { 00204 00205 public: 00206 00208 HessianFilter() { 00209 namestring = "hessfilt"; 00210 } 00211 00213 bool IsLoaded() const { return true; } 00214 00216 bool LoadFilter(int size=0); 00217 00223 void FilterDescriptors(const vector<cv::KeyPoint> &keyps, 00224 const cv::Mat &descs); 00225 00226 }; // class HessianFilter 00227 00228 00229 #endif // _KeypointFilter_h_