35 int sizeof_param,
int sizeof_model) {
45 printf(
"Cound not allocate memory for %d sample pointers.",
53 printf(
"Cound not allocate %d bytes of memory for model parameters.",
66 int support_limit,
int max_rounds,
74 i < max_rounds && max_support < support_limit;
78 for (sample_c = 0; sample_c <
min_params; sample_c++) {
79 int r = rand() % (param_c-sample_c);
81 for (
int j = 0; j < sample_c; j++)
91 for (
int j = 0; j < param_c; j++) {
97 printf(
"Hypothesis got %d support\n", hypo_support);
99 if (hypo_support > max_support) {
100 max_support = hypo_support;
109 int support_limit,
int max_rounds,
110 void* model,
char *inlier_mask) {
117 i < max_rounds && max_support < support_limit;
121 for (
int j = 0; j < param_c && sample_c <
max_params; j++) {
123 samples[sample_c++] = (
char*)params + j*sizeof_param;
124 if (inlier_mask) inlier_mask[j] = 1;
126 if (inlier_mask) inlier_mask[j] = 0;
130 printf(
"Found %d supporting parameters\n", sample_c);
132 if (sample_c > max_support) {
135 max_support = sample_c;
158 printf(
"Cound not allocate %d bytes of memory for model parameters.",
165 int support_limit,
int max_rounds,
173 i < max_rounds && max_support < support_limit;
177 for (sample_c = 0; sample_c <
min_params; sample_c++) {
178 int r = rand() % (param_c-sample_c);
179 for (
int j = 0; j < sample_c; j++)
188 int hypo_support = 0;
189 for (
int j = 0; j < param_c; j++) {
195 printf(
"Hypothesis got %d support\n", hypo_support);
197 if (hypo_support > max_support) {
198 max_support = hypo_support;
207 int support_limit,
int max_rounds,
208 void* model,
char *inlier_mask) {
215 i < max_rounds && max_support < support_limit;
219 for (
int j = 0; j < param_c && sample_c <
max_params; j++) {
222 if (inlier_mask) inlier_mask[j] = 1;
224 if (inlier_mask) inlier_mask[j] = 0;
228 printf(
"Found %d supporting parameters\n", sample_c);
231 if (sample_c > max_support) {
234 max_support = sample_c;
248 float inlier_percentage) {
250 (log(1-success_propability) / log(1-pow(inlier_percentage,3)));
RansacImpl(int min_params, int max_params, int sizeof_param, int sizeof_model)
int _refine(void *params, int param_c, int support_limit, int max_rounds, void *model, char *inlier_mask=NULL)
int _estimate(void *params, int param_c, int support_limit, int max_rounds, void *model)
This file implements a generic RANSAC algorithm.
virtual void _doEstimate(void **params, int param_c, void *model)
virtual bool _doSupports(void *param, void *model)
int estimateRequiredRounds(float success_propability, float inlier_percentage)
How many rounds are needed for the Ransac to work.