1 #include <Base/Common/BIASpragma.hh>
3 #include "Base/Math/Random.hh"
9 #include "ExampleRANSACPlane.hh"
14 void Read3DPointsFromFile(
char *filename, std::vector<HomgPoint3D> &points)
16 ifstream infile(filename);
18 BIASERR(
"Failed to open file " << filename);
24 while (!infile.eof()) {
25 infile >> point[0] >> point[1] >> point[2] >> c;
27 points.push_back(point);
28 cout <<
"- point " << i <<
" : "<< point << endl;
35 void GeneratePlanar3DPoints(std::vector<HomgPoint3D>& points,
36 unsigned int numInliers,
unsigned int numOutliers)
44 for (
unsigned int i = 0; i < (numInliers + numOutliers); i++){
49 if (i >= numInliers) {
53 points.push_back(point3D);
54 cout <<
"- point " << i <<
" : " << point3D <<
" ("
55 << (i >= numInliers ?
"outlier" :
"inlier") <<
")" << endl;
73 int main(
int argc,
char *argv[])
76 const unsigned int numPoints = 20;
82 double inlier_fraction = 0.8;
85 bool refine_solution =
true;
88 double maxsquareddistance = 0.01;
94 vector<HomgPoint3D> points;
101 cout << endl <<
"Generating " << numPoints <<
" random noisy points "
102 <<
"for testing..." << endl;
103 const unsigned int outliers = (int)rint((1.0 - inlier_fraction) * numPoints);
104 GeneratePlanar3DPoints(points, numPoints - outliers, outliers);
106 cout << endl <<
"Reading 3d points for testing from file " << argv[1] <<
"..." << endl;
107 Read3DPointsFromFile(argv[1], points);
117 ransac.
Init(points, maxsquareddistance, refine_solution, inlier_fraction, -1.0);
120 ransac.
SolveMaster(inlier_fraction, solution, inliers);
123 cout << endl <<
"Inlier/outlier points after computation : " << endl;
124 for (
unsigned int i = 0; i < inliers.size(); i++){
125 cout <<
"- point " << i <<
" is " << (inliers[i] ?
"inlier" :
"outlier") << endl;
127 cout << endl <<
"Final solution : " << solution << endl
128 <<
"Ground truth : " << gt_plane << endl
129 <<
"Difference : " << (solution - gt_plane).NormL2() << endl << endl;
void Init(std::vector< HomgPoint3D > &data, double inlier_distance_threshold, bool refine_solution, double expected_inlier_fraction, double solution_error_threshold)
Initializes RANSAC.
void AddDebugLevel(const long int lv)
Robust fitting of 3D plane to 3D point set using RANSAC.
virtual int SolveMaster(double inlying_data_fraction, SolutionType &solution, std::vector< bool > &inliers)
Main computation function called by user.
double GetUniformDistributed(const double min, const double max)
on succesive calls return uniform distributed random variable between min and max ...
class HomgPoint3D describes a point with 3 degrees of freedom in projective coordinates.
class for producing random numbers from different distributions
A homogeneous plane (in P^3) All points X on the plane p fulfill p ' * X = 0.