-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathransac.hpp
72 lines (55 loc) · 1.94 KB
/
ransac.hpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
//
// ransac.hpp
// projet
//
// Created by Etienne Dejoie on 11/01/2016.
//
//
#ifndef ransac_h
#define ransac_h
using namespace std;
using namespace cv;
template <typename T>
vector<float> Ransac(Data<T>* data, int iterNb, int estimNb){
int matchNbMin = (int)(data->getVc().size()-estimNb)/3;
vector<float> bestModel = vector<float>();
bestModel.push_back(0.);
bestModel.push_back(0.);
float bestError = INFINITY;
float matchError = 0.3;
for( int it = 0; it<iterNb; it ++){
vector<T> estimPoints = vector<T>();
vector<T> otherPoints = vector<T>(data->getVc());
//put estimNb points in estimPoints (chosen randomly in data)
for( int i = 0; i<estimNb; i++){
int a = rand();
int rand = (a % otherPoints.size());
T randPoint = otherPoints[rand];
otherPoints.erase(otherPoints.begin() + rand);
estimPoints.push_back(randPoint);
}
//cout<< estimPoints.size() <<" + "<< otherPoints.size() << " = "<<data->getVc().size() << endl;
//find model
vector<float> tempModel = data->estimModel(estimPoints);
int matchNb = 0;
//itérateur sur otherPoints
for (int i = 0; i<otherPoints.size(); i ++) {
float localError = data->calculateError1(otherPoints[i], tempModel);
if (localError < matchError) {
matchNb ++;
estimPoints.push_back(otherPoints[i]);
}
}
if (matchNb > matchNbMin ){
vector<float> model = data->estimModel(estimPoints);
float error = data->calculateError2(estimPoints, model);
// calculater error
if ( error< bestError ){
bestModel = model;
bestError = error;
}
}
}
return bestModel;
}
#endif /* ransac_h */