25 namespace perception {
33 return inlierprob > 0.0
35 ILog(1.0 -
IPow(inlierprob, sample_size))))
36 : std::numeric_limits<int>::max();
41 template <
typename T,
int l,
int lp,
int k,
int s,
42 void (*HypogenFunc)(
const T* x,
const T* xp, T* model),
43 void (*CostFunc)(
const T* model,
const T* x,
const T* xp,
int n,
44 int* nr_liner,
int* inliers, T* cost, T error_tol),
45 void (*RefitFunc)(T* x, T* xp,
int* inliers, T* model,
int n,
48 int* inliers, T error_tol,
49 bool re_est_model_w_inliers =
false,
50 bool adaptive_trial_count =
false,
51 double confidence = 0.99,
double inlierprob = 0.5,
52 int min_nr_inliers = s,
53 bool random_shuffle_inputs =
false) {
55 const int kLength = l;
59 T samples_x[kLength * kSize];
60 T samples_xp[kLp * kSize];
62 T cost = std::numeric_limits<T>::max();
63 T best_cost = std::numeric_limits<T>::max();
65 if (n < min_nr_inliers) {
69 double actual_inlierprob = 0.0, tmp_inlierprob;
75 int i, idxl, idxlp, il, ilp;
79 if (random_shuffle_inputs) {
83 while (nr_trials > sample_count) {
87 for (i = 0; i < s; ++i) {
88 idxl = indices[i] * l;
89 idxlp = indices[i] * lp;
92 ICopy(x + idxl, samples_x + il, l);
93 ICopy(xp + idxlp, samples_xp + ilp, lp);
97 HypogenFunc(samples_x, samples_xp, tmp_model);
100 CostFunc(tmp_model, x, xp, n, &nr_inliers, inliers + n, &cost, error_tol);
101 if ((nr_inliers > *consensus_size) ||
102 (nr_inliers == *consensus_size && cost < best_cost)) {
103 *consensus_size = nr_inliers;
105 ICopy(tmp_model, model, k);
106 ICopy(inliers + n, inliers, *consensus_size);
107 if (adaptive_trial_count) {
108 tmp_inlierprob =
IDiv(static_cast<double>(*consensus_size), n);
109 if (tmp_inlierprob > actual_inlierprob) {
110 actual_inlierprob = tmp_inlierprob;
117 bool succeeded = *consensus_size >= min_nr_inliers;
119 if (succeeded && re_est_model_w_inliers && RefitFunc !=
nullptr) {
120 RefitFunc(x, xp, inliers, model, n, *consensus_size);
void ICopy(const T *src, T *dst, int n)
Definition: i_blas.h:27
int IRound(int a)
Definition: i_basic.h:197
float IPow(float a, float b)
Definition: i_basic.h:142
float ILog(float x)
Definition: i_basic.h:126
void IRandomizedShuffle(T *A, int n, int l, int *s)
Definition: i_rand.h:78
float IDiv(float a, float b)
Definition: i_basic.h:35
int IRansacTrials(int sample_size, double confidence, double inlierprob)
Definition: i_ransac.h:31
const int I_DEFAULT_SEED
Definition: i_rand.h:24
void IRandomSample(int *sample, int n, int pool_size, int *s)
Definition: i_rand.h:47
void IZero(T *a, int n)
Definition: i_blas.h:320
bool RobustBinaryFitRansac(T *x, T *xp, int n, T *model, int *consensus_size, int *inliers, T error_tol, bool re_est_model_w_inliers=false, bool adaptive_trial_count=false, double confidence=0.99, double inlierprob=0.5, int min_nr_inliers=s, bool random_shuffle_inputs=false)
Definition: i_ransac.h:47