24 namespace perception {
32 return inlierprob > 0.0
34 ILog(1.0 -
IPow(inlierprob, sample_size))))
35 : std::numeric_limits<int>::max();
40 template <
typename T,
int l,
int lp,
int k,
int s,
41 void (*HypogenFunc)(
const T* x,
const T* xp, T* model),
42 void (*CostFunc)(
const T* model,
const T* x,
const T* xp,
int n,
43 int* nr_liner,
int* inliers, T* cost, T error_tol),
44 void (*RefitFunc)(T* x, T* xp,
int* inliers, T* model,
int n,
47 int* inliers, T error_tol,
48 bool re_est_model_w_inliers =
false,
49 bool adaptive_trial_count =
false,
50 double confidence = 0.99,
double inlierprob = 0.5,
51 int min_nr_inliers = s,
52 bool random_shuffle_inputs =
false) {
54 const int kLength = l;
58 T samples_x[kLength * kSize];
59 T samples_xp[kLp * kSize];
61 T cost = std::numeric_limits<T>::max();
62 T best_cost = std::numeric_limits<T>::max();
64 if (n < min_nr_inliers) {
68 double actual_inlierprob = 0.0, tmp_inlierprob;
74 int i, idxl, idxlp, il, ilp;
78 if (random_shuffle_inputs) {
82 while (nr_trials > sample_count) {
86 for (i = 0; i < s; ++i) {
87 idxl = indices[i] * l;
88 idxlp = indices[i] * lp;
91 ICopy(x + idxl, samples_x + il, l);
92 ICopy(xp + idxlp, samples_xp + ilp, lp);
96 HypogenFunc(samples_x, samples_xp, tmp_model);
99 CostFunc(tmp_model, x, xp, n, &nr_inliers, inliers + n, &cost, error_tol);
100 if ((nr_inliers > *consensus_size) ||
101 (nr_inliers == *consensus_size && cost < best_cost)) {
102 *consensus_size = nr_inliers;
104 ICopy(tmp_model, model, k);
105 ICopy(inliers + n, inliers, *consensus_size);
106 if (adaptive_trial_count) {
107 tmp_inlierprob =
IDiv(static_cast<double>(*consensus_size), n);
108 if (tmp_inlierprob > actual_inlierprob) {
109 actual_inlierprob = tmp_inlierprob;
116 bool succeeded = *consensus_size >= min_nr_inliers;
118 if (succeeded && re_est_model_w_inliers && RefitFunc !=
nullptr) {
119 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
PlanningContext is the runtime context in planning. It is persistent across multiple frames...
Definition: atomic_hash_map.h:25
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:30
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:46