00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #include "detectors.h"
00021 #include "harrislike.h"
00022 #include "dog.h"
00023 #ifdef USESUSAN
00024 #include "susan.h"
00025 #endif
00026 #include "cvd_fast.h"
00027
00028 #include "faster_detector.h"
00029
00030 #include <memory>
00031 #include <cstdlib>
00032 #include <gvars3/instances.h>
00033
00034 using namespace std;
00035 using namespace CVD;
00036 using namespace GVars3;
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047 int binary_search_threshold(const Image<byte>& i, vector<ImageRef>& c, unsigned int N, const DetectT& detector)
00048 {
00049
00050 vector<ImageRef> ch, cl, cm;
00051
00052
00053 unsigned int t_high = 256;
00054 unsigned int t_low = 0;
00055
00056
00057 detector(i, ch, t_high);
00058 detector(i, cl, t_low);
00059
00060 while(t_high > t_low + 1)
00061 {
00062
00063 cm.clear();
00064 unsigned int t = (t_high + t_low ) / 2;
00065 detector(i, cm, t);
00066
00067 if(cm.size() == N)
00068 {
00069 c = cm;
00070 return t;
00071 }
00072 else if(cm.size() < N)
00073 {
00074 t_high = t;
00075 ch = cm;
00076 }
00077 else
00078 {
00079 t_low = t;
00080 cl = cm;
00081 }
00082 }
00083
00084
00085
00086
00087
00088 if( N - ch.size() >= cl.size() - N)
00089 {
00090 c = cl;
00091 return t_low;
00092 }
00093 else
00094 {
00095 c = ch;
00096 return t_high;
00097 }
00098 }
00099
00100
00101
00102
00103 struct SearchThreshold:public DetectN
00104 {
00105
00106 SearchThreshold(DetectT* d)
00107 :detector(d)
00108 {
00109 }
00110
00111
00112
00113
00114
00115 virtual void operator()(const Image<byte>& im, vector<ImageRef>& corners, unsigned int N)const
00116 {
00117 int t = binary_search_threshold(im, corners, N, *detector);
00118 }
00119
00120 private:
00121
00122 auto_ptr<DetectT> detector;
00123 };
00124
00125
00126
00127 struct Random:public DetectN
00128 {
00129
00130
00131
00132
00133 virtual void operator()(const Image<byte>& im, vector<ImageRef>& corners, unsigned int N)const
00134 {
00135 for(unsigned int i=0; i < N; i++)
00136 corners.push_back(ImageRef(rand() % im.size().x, rand() % im.size().y));
00137 }
00138 };
00139
00140
00141
00142
00143
00144
00145
00146
00147
00148
00149
00150
00151
00152
00153
00154
00155
00156 auto_ptr<DetectN> get_detector()
00157 {
00158
00159 string d = GV3::get<string>("detector", "fast9", 1);
00160
00161 if(d == "random")
00162 return auto_ptr<DetectN>(new Random);
00163 else if(d == "dog")
00164 return auto_ptr<DetectN>(new dog);
00165 else if(d == "harrisdog")
00166 return auto_ptr<DetectN>(new harrisdog);
00167 else if(d == "shitomasi")
00168 return auto_ptr<DetectN>(new ShiTomasiDetect);
00169 else if(d == "harris")
00170 return auto_ptr<DetectN>(new HarrisDetect);
00171 #ifdef USESUSAN
00172 else if(d == "susan")
00173 return auto_ptr<DetectN>(new SearchThreshold(new SUSAN));
00174 #endif
00175 else if(d == "fast9")
00176 return auto_ptr<DetectN>(new SearchThreshold(new fast_9));
00177 else if(d == "fast9old")
00178 return auto_ptr<DetectN>(new SearchThreshold(new fast_9_old));
00179 else if(d == "fast12")
00180 return auto_ptr<DetectN>(new SearchThreshold(new fast_12));
00181 else if(d == "faster2")
00182 return auto_ptr<DetectN>(new SearchThreshold(new faster_learn(GV3::get<string>("faster2"))));
00183 else
00184 {
00185 cerr << "Unknown detector: " << d << endl;
00186 exit(1);
00187 }
00188 }