33 #include <Base/Common/BIASpragma.hh>
35 #include "ExampleRANSAC_double.hh"
37 #include <Base/Math/Random.hh>
53 void GenerateRANSAC_doubleData(
unsigned int count,
double mean,
double sigma,
54 double inlier_fraction, vector<double>& data,
57 if (data.size() != count) data.resize(count);
59 for (
unsigned int i = 0; i < count; i++) {
61 if (outlier_prob > inlier_fraction) {
73 int main(
int argc,
char *argv[])
77 vector<vector<double> > data_array;
79 double min = -100.0, max = 100.0;
80 double minsigma = 0.0, maxsigma = 5.0;
83 double inlier_fraction = 0.7;
84 vector<double> expected_inlier_fraction;
85 unsigned int sample_size = 2;
86 bool refine_solution =
true;
87 double inlier_distance_threshold;
92 double mean_error = 0.0;
93 double solution_error_threshold;
101 unsigned int count = argc > 1 ? atoi(argv[1]) : 1000;
102 unsigned int data_length = argc > 2 ? atoi(argv[2]) : 1000;
103 cout << endl <<
"Running " << argv[0] <<
" " << count <<
" times with "
104 << data_length <<
" samples per test : " << endl
105 <<
"(call " << argv[0] <<
" <num_tests> <num_samples> to change "
106 <<
"parameters)" << endl << endl;
110 data_array.resize(count);
113 expected_inlier_fraction.resize(count);
114 for (
unsigned int i = 0; i < count; i++)
118 expected_inlier_fraction[i] = inlier_fraction +
120 if (expected_inlier_fraction[i] > 1.0)
121 expected_inlier_fraction[i] = 1.0;
122 GenerateRANSAC_doubleData(data_length, mean[i], sigma[i], inlier_fraction,
123 data_array[i], randomizer);
127 for (
unsigned int i = 0; i < count; i++)
129 inlier_distance_threshold = 3.0*sigma[i];
130 solution_error_threshold = 1.5*sigma[i];
133 for (
unsigned int j = 0; j < data_length; j++)
134 cout << data_array[i][j] <<
" ";
136 cout <<setw(5)<<i<<
":\tmean: "<<mean[i]<<
"\tsigma: "<<sigma[i]<<endl;
137 cout <<
"inlier_distance_threshold = "<<inlier_distance_threshold<<endl;
138 cout <<
"solution_error_threshold = "<<solution_error_threshold<<endl;
139 cout <<
"expected_inlier_fraction " << expected_inlier_fraction[i]<<endl;
142 ransac.
Init(data_array[i], sample_size, inlier_distance_threshold,
143 refine_solution, expected_inlier_fraction[i],
144 solution_error_threshold);
146 if (ransac.
SolveMaster(expected_inlier_fraction[i], solution, inliers) < 0)
148 BIASERR(
"Error running RANSAC_double::SolveMaster()!");
149 cerr <<
"- true solution \t" << mean[i] <<
" \t"
150 <<
"sigma: "<<sigma[i]<<
" \t"
151 <<
"expected_inlier_fraction: "<<expected_inlier_fraction[i]<<endl;
153 cerr <<
"- true solution \t" << mean[i] <<
" \t"
154 <<
"sigma: "<<sigma[i]<<
" \t"
155 <<
"expected_inlier_fraction: "<<expected_inlier_fraction[i]<<endl
156 <<
" estimated solution \t" << solution <<
" \t"
157 <<
"error: "<<fabs(solution-mean[i])<<
" \t"
158 <<
"expected_inlier_fraction: "<<expected_inlier_fraction[i]<<endl;
159 mean_error += (sigma[i]!=0.0) ? (fabs(solution-mean[i])/sigma[i]) :
160 (fabs(solution-mean[i]) / DBL_MIN);
163 mean_error /= (double)count;
165 cerr <<
"\n mean error of all tests : " << mean_error << endl << endl;
void AddDebugLevel(const long int lv)
virtual int SolveMaster(double inlying_data_fraction, SolutionType &solution, std::vector< bool > &inliers)
Main computation function called by user.
Robust mean computation for double values using RANSAC.
double GetUniformDistributed(const double min, const double max)
on succesive calls return uniform distributed random variable between min and max ...
void Init(std::vector< double > &data, unsigned int sample_size, double inlier_distance_threshold, bool refine_solution, double expected_inlier_fraction, double solution_error_threshold)
double GetNormalDistributed(const double mean, const double sigma)
on succesive calls return normal distributed random variable with mean and standard deviation sigma ...
class for producing random numbers from different distributions