00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042 #include <iostream>
00043 #include <sstream>
00044 #include <cfloat>
00045 #include <map>
00046 #include <utility>
00047
00048 #include <cvd/image_io.h>
00049 #include <cvd/random.h>
00050 #include <cvd/image_interpolate.h>
00051 #include <tag/printf.h>
00052 #include <tag/stdpp.h>
00053
00054
00055 #include "gvars_vector.h"
00056 #include "load_data.h"
00057 #include "detectors.h"
00058 #include "utility.h"
00059
00060 using namespace std;
00061 using namespace CVD;
00062 using namespace tag;
00063 using namespace GVars3;
00064 using namespace TooN;
00065
00066
00067
00068
00069
00070
00071
00072
00073
00074
00075
00076 double compute_repeatability_exact(const vector<vector<Image<array<float,2> > > >& warps, const vector<vector<ImageRef> >& corners, double r)
00077 {
00078 unsigned int n = corners.size();
00079
00080 int repeatable_corners = 0;
00081 int repeated_corners = 0;
00082
00083 r *= r;
00084
00085 for(unsigned int i=0; i < n; i++)
00086 for(unsigned int j=0; j < n; j++)
00087 {
00088 if(i==j)
00089 continue;
00090
00091 for(unsigned int k=0; k < corners[i].size(); k++)
00092 {
00093 const array<float, 2>& p = warps[i][j][corners[i][k]];
00094
00095 if(p[0] != -1)
00096 {
00097
00098 repeatable_corners++;
00099
00100 for(unsigned int l=0; l < corners[j].size(); l++)
00101 {
00102 Vector<2> d = Vec(p) - vec(corners[j][l]);
00103
00104 if(d*d < r)
00105 {
00106 repeated_corners++;
00107 break;
00108 }
00109 }
00110 }
00111 }
00112 }
00113
00114 return 1.0 * (repeated_corners) / (repeatable_corners + DBL_EPSILON);
00115 }
00116
00117
00118
00119
00120
00121
00122
00123
00124
00125
00126 void compute_repeatability_all(const vector<Image<byte> >& images, const vector<vector<Image<array<float, 2> > > >& warps, const DetectN& detector, const vector<int>& cpf, double fuzz)
00127 {
00128
00129 for(unsigned int i=0; i < cpf.size(); i++)
00130 {
00131
00132 vector<vector<ImageRef> > corners;
00133 double num_corners = 0;
00134
00135 for(unsigned int j=0; j < images.size(); j++)
00136 {
00137 vector<ImageRef> c;
00138 detector(images[j], c, cpf[i]);
00139 corners.push_back(c);
00140
00141 num_corners += c.size();
00142 }
00143
00144
00145 cout << print << num_corners / images.size() << compute_repeatability_exact(warps, corners, fuzz);
00146 }
00147 }
00148
00149
00150
00151
00152
00153
00154
00155
00156
00157
00158
00159
00160
00161 void compute_repeatability_noise(const vector<Image<byte> >& images, const vector<vector<Image<array<float, 2> > > >& warps, const DetectN& detector, int cpf, float n, double fuzz)
00162 {
00163
00164 for(float s=0; s <= n; s++)
00165 {
00166
00167
00168
00169 vector<vector<ImageRef> > corners;
00170 double num_corners = 0;
00171
00172 for(unsigned int j=0; j < images.size(); j++)
00173 {
00174 Image<byte> ni = images[j].copy_from_me();
00175
00176
00177 for(Image<byte>::iterator i=ni.begin(); i != ni.end(); i++)
00178 *i = max(0, min(255, (int)floor(*i + rand_g() * s + .5)));
00179
00180 vector<ImageRef> c;
00181 detector(ni, c, cpf);
00182 corners.push_back(c);
00183
00184 num_corners += c.size();
00185 }
00186
00187
00188 cout << print << s << compute_repeatability_exact(warps, corners, fuzz) << num_corners / images.size();
00189 }
00190 }
00191
00192
00193
00194
00195
00196
00197
00198
00199 void mmain(int argc, char** argv)
00200 {
00201 GUI.LoadFile("test_repeatability.cfg");
00202 GUI.parseArguments(argc, argv);
00203
00204 vector<Image<byte> > images;
00205 vector<vector<Image<array<float, 2> > > > warps;
00206
00207
00208 int n = GV3::get<int>("num", 2, 1);
00209 string dir = GV3::get<string>("dir", "./", 1);
00210 string format = GV3::get<string>("type", "cambridge", 1);
00211 double fuzz = GV3::get<double>("r", 5, 1);
00212 vector<int> cpf = GV3::get<vector<int> >("cpf", "0 10 20 30 40 50 60 70 80 90 100 150 200 250 300 350 400 450 500 550 600 650 700 750 800 850 900 950 1000 1100 1200 1300 1400 1500 1600 1700 1800 1900 2000 2200", 1);
00213 int ncpf = GV3::get<int>("ncpf", 500, 1);
00214 float nmax = GV3::get<int>("nmax", 50, 1);
00215 string test = GV3::get<string>("test", "normal", 1);
00216
00217 auto_ptr<DetectN> detector = get_detector();
00218
00219 rpair(images, warps) = load_data(dir, n, format);
00220
00221 if(test == "noise")
00222 compute_repeatability_noise(images, warps, *detector, ncpf, nmax, fuzz);
00223 else
00224 compute_repeatability_all(images, warps, *detector, cpf, fuzz);
00225
00226 }
00227
00228
00229
00230
00231 int main(int argc, char** argv)
00232 {
00233 try
00234 {
00235 mmain(argc, argv);
00236 }
00237 catch(Exceptions::All e)
00238 {
00239 cerr << "Error: " << e.what << endl;
00240 }
00241 }