Commit 4bacfcff authored by Debargha Mukherjee's avatar Debargha Mukherjee Committed by Gerrit Code Review
Browse files

Merge "Fix ransac random generator seeding" into nextgenv2

parents 321556a5 efa65822
...@@ -92,16 +92,16 @@ static void project_points_double_homography(double *mat, double *points, ...@@ -92,16 +92,16 @@ static void project_points_double_homography(double *mat, double *points,
} }
} }
static int get_rand_indices(int npoints, int minpts, int *indices) { static int get_rand_indices(int npoints, int minpts, int *indices,
unsigned int *seed) {
int i, j; int i, j;
unsigned int seed = (unsigned int)npoints; int ptr = rand_r(seed) % npoints;
int ptr = rand_r(&seed) % npoints;
if (minpts > npoints) return 0; if (minpts > npoints) return 0;
indices[0] = ptr; indices[0] = ptr;
ptr = (ptr == npoints - 1 ? 0 : ptr + 1); ptr = (ptr == npoints - 1 ? 0 : ptr + 1);
i = 1; i = 1;
while (i < minpts) { while (i < minpts) {
int index = rand_r(&seed) % npoints; int index = rand_r(seed) % npoints;
while (index) { while (index) {
ptr = (ptr == npoints - 1 ? 0 : ptr + 1); ptr = (ptr == npoints - 1 ? 0 : ptr + 1);
for (j = 0; j < i; ++j) { for (j = 0; j < i; ++j) {
...@@ -132,6 +132,7 @@ static int ransac(double *matched_points, int npoints, int *number_of_inliers, ...@@ -132,6 +132,7 @@ static int ransac(double *matched_points, int npoints, int *number_of_inliers,
int N = 10000, trial_count = 0; int N = 10000, trial_count = 0;
int i; int i;
int ret_val = 0; int ret_val = 0;
unsigned int seed = (unsigned int)npoints;
int max_inliers = 0; int max_inliers = 0;
double best_variance = 0.0; double best_variance = 0.0;
...@@ -139,7 +140,7 @@ static int ransac(double *matched_points, int npoints, int *number_of_inliers, ...@@ -139,7 +140,7 @@ static int ransac(double *matched_points, int npoints, int *number_of_inliers,
WarpedMotionParams wm; WarpedMotionParams wm;
double points1[2 * MAX_MINPTS]; double points1[2 * MAX_MINPTS];
double points2[2 * MAX_MINPTS]; double points2[2 * MAX_MINPTS];
int indices[MAX_MINPTS]; int indices[MAX_MINPTS] = { 0 };
double *best_inlier_set1; double *best_inlier_set1;
double *best_inlier_set2; double *best_inlier_set2;
...@@ -153,10 +154,6 @@ static int ransac(double *matched_points, int npoints, int *number_of_inliers, ...@@ -153,10 +154,6 @@ static int ransac(double *matched_points, int npoints, int *number_of_inliers,
double *cnp1, *cnp2; double *cnp1, *cnp2;
double T1[9], T2[9]; double T1[9], T2[9];
// srand((unsigned)time(NULL)) ;
// better to make this deterministic for a given sequence for ease of testing
srand(npoints);
*number_of_inliers = 0; *number_of_inliers = 0;
if (npoints < minpts * MINPTS_MULTIPLIER) { if (npoints < minpts * MINPTS_MULTIPLIER) {
printf("Cannot find motion with %d matches\n", npoints); printf("Cannot find motion with %d matches\n", npoints);
...@@ -203,7 +200,7 @@ static int ransac(double *matched_points, int npoints, int *number_of_inliers, ...@@ -203,7 +200,7 @@ static int ransac(double *matched_points, int npoints, int *number_of_inliers,
int num_degenerate_iter = 0; int num_degenerate_iter = 0;
while (degenerate) { while (degenerate) {
num_degenerate_iter++; num_degenerate_iter++;
if (!get_rand_indices(npoints, minpts, indices)) { if (!get_rand_indices(npoints, minpts, indices, &seed)) {
ret_val = 1; ret_val = 1;
goto finish_ransac; goto finish_ransac;
} }
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment