Commit d8941da5 authored by emilkeyder@google.com's avatar emilkeyder@google.com Committed by Emil Keyder

Remove inlier_map argument from ransac methods.

Change-Id: I111180626f51a866f6b3ba17d17156d74ad53d57
parent 31b6a4f9
...@@ -241,15 +241,14 @@ static INLINE RansacFunc get_ransac_type(TransformationType type) { ...@@ -241,15 +241,14 @@ static INLINE RansacFunc get_ransac_type(TransformationType type) {
// computes global motion parameters by fitting a model using RANSAC // computes global motion parameters by fitting a model using RANSAC
static int compute_global_motion_params(TransformationType type, static int compute_global_motion_params(TransformationType type,
int *correspondences, int *correspondences,
int num_correspondences, double *params, int num_correspondences,
int *inlier_map) { double *params) {
int result; int result;
int num_inliers = 0; int num_inliers = 0;
RansacFunc ransac = get_ransac_type(type); RansacFunc ransac = get_ransac_type(type);
if (ransac == NULL) return 0; if (ransac == NULL) return 0;
result = ransac(correspondences, num_correspondences, &num_inliers, result = ransac(correspondences, num_correspondences, &num_inliers, params);
inlier_map, params);
if (!result && num_inliers < MIN_INLIER_PROB * num_correspondences) { if (!result && num_inliers < MIN_INLIER_PROB * num_correspondences) {
result = 1; result = 1;
num_inliers = 0; num_inliers = 0;
...@@ -284,7 +283,6 @@ int compute_global_motion_feature_based(TransformationType type, ...@@ -284,7 +283,6 @@ int compute_global_motion_feature_based(TransformationType type,
int *correspondences; int *correspondences;
int num_inliers; int num_inliers;
int frm_corners[2 * MAX_CORNERS], ref_corners[2 * MAX_CORNERS]; int frm_corners[2 * MAX_CORNERS], ref_corners[2 * MAX_CORNERS];
int *inlier_map = NULL;
unsigned char *frm_buffer = frm->y_buffer; unsigned char *frm_buffer = frm->y_buffer;
unsigned char *ref_buffer = ref->y_buffer; unsigned char *ref_buffer = ref->y_buffer;
...@@ -319,10 +317,8 @@ int compute_global_motion_feature_based(TransformationType type, ...@@ -319,10 +317,8 @@ int compute_global_motion_feature_based(TransformationType type,
(int *)ref_corners, num_ref_corners, frm->y_width, frm->y_height, (int *)ref_corners, num_ref_corners, frm->y_width, frm->y_height,
frm->y_stride, ref->y_stride, correspondences); frm->y_stride, ref->y_stride, correspondences);
inlier_map = (int *)malloc(num_correspondences * sizeof(*inlier_map)); num_inliers = compute_global_motion_params(type, correspondences,
num_inliers = compute_global_motion_params( num_correspondences, params);
type, correspondences, num_correspondences, params, inlier_map);
free(correspondences); free(correspondences);
free(inlier_map);
return (num_inliers > 0); return (num_inliers > 0);
} }
...@@ -156,7 +156,7 @@ static int get_rand_indices(int npoints, int minpts, int *indices, ...@@ -156,7 +156,7 @@ static int get_rand_indices(int npoints, int minpts, int *indices,
} }
static int ransac(int *matched_points, int npoints, int *number_of_inliers, static int ransac(int *matched_points, int npoints, int *number_of_inliers,
int *best_inlier_mask, double *best_params, const int minpts, double *best_params, const int minpts,
IsDegenerateFunc is_degenerate, IsDegenerateFunc is_degenerate,
FindTransformationFunc find_transformation, FindTransformationFunc find_transformation,
ProjectPointsDoubleFunc projectpoints) { ProjectPointsDoubleFunc projectpoints) {
...@@ -183,7 +183,6 @@ static int ransac(int *matched_points, int npoints, int *number_of_inliers, ...@@ -183,7 +183,6 @@ static int ransac(int *matched_points, int npoints, int *number_of_inliers,
double *corners1; double *corners1;
double *corners2; double *corners2;
double *image1_coord; double *image1_coord;
int *inlier_mask;
double *cnp1, *cnp2; double *cnp1, *cnp2;
...@@ -202,10 +201,9 @@ static int ransac(int *matched_points, int npoints, int *number_of_inliers, ...@@ -202,10 +201,9 @@ static int ransac(int *matched_points, int npoints, int *number_of_inliers,
corners1 = (double *)aom_malloc(sizeof(*corners1) * npoints * 2); corners1 = (double *)aom_malloc(sizeof(*corners1) * npoints * 2);
corners2 = (double *)aom_malloc(sizeof(*corners2) * npoints * 2); corners2 = (double *)aom_malloc(sizeof(*corners2) * npoints * 2);
image1_coord = (double *)aom_malloc(sizeof(*image1_coord) * npoints * 2); image1_coord = (double *)aom_malloc(sizeof(*image1_coord) * npoints * 2);
inlier_mask = (int *)aom_malloc(sizeof(*inlier_mask) * npoints);
if (!(best_inlier_set1 && best_inlier_set2 && inlier_set1 && inlier_set2 && if (!(best_inlier_set1 && best_inlier_set2 && inlier_set1 && inlier_set2 &&
corners1 && corners2 && image1_coord && inlier_mask)) { corners1 && corners2 && image1_coord)) {
ret_val = 1; ret_val = 1;
goto finish_ransac; goto finish_ransac;
} }
...@@ -260,8 +258,7 @@ static int ransac(int *matched_points, int npoints, int *number_of_inliers, ...@@ -260,8 +258,7 @@ static int ransac(int *matched_points, int npoints, int *number_of_inliers,
double dy = image1_coord[i * 2 + 1] - corners2[i * 2 + 1]; double dy = image1_coord[i * 2 + 1] - corners2[i * 2 + 1];
double distance = sqrt(dx * dx + dy * dy); double distance = sqrt(dx * dx + dy * dy);
inlier_mask[i] = distance < INLIER_THRESHOLD; if (distance < INLIER_THRESHOLD) {
if (inlier_mask[i]) {
inlier_set1[num_inliers * 2] = corners1[i * 2]; inlier_set1[num_inliers * 2] = corners1[i * 2];
inlier_set1[num_inliers * 2 + 1] = corners1[i * 2 + 1]; inlier_set1[num_inliers * 2 + 1] = corners1[i * 2 + 1];
inlier_set2[num_inliers * 2] = corners2[i * 2]; inlier_set2[num_inliers * 2] = corners2[i * 2];
...@@ -291,8 +288,6 @@ static int ransac(int *matched_points, int npoints, int *number_of_inliers, ...@@ -291,8 +288,6 @@ static int ransac(int *matched_points, int npoints, int *number_of_inliers,
num_inliers * 2 * sizeof(*best_inlier_set1)); num_inliers * 2 * sizeof(*best_inlier_set1));
memcpy(best_inlier_set2, inlier_set2, memcpy(best_inlier_set2, inlier_set2,
num_inliers * 2 * sizeof(*best_inlier_set2)); num_inliers * 2 * sizeof(*best_inlier_set2));
memcpy(best_inlier_mask, inlier_mask,
npoints * sizeof(*best_inlier_mask));
assert(npoints > 0); assert(npoints > 0);
fracinliers = (double)num_inliers / (double)npoints; fracinliers = (double)num_inliers / (double)npoints;
...@@ -318,7 +313,6 @@ finish_ransac: ...@@ -318,7 +313,6 @@ finish_ransac:
aom_free(corners1); aom_free(corners1);
aom_free(corners2); aom_free(corners2);
aom_free(image1_coord); aom_free(image1_coord);
aom_free(inlier_mask);
return ret_val; return ret_val;
} }
...@@ -343,45 +337,43 @@ static int is_degenerate_homography(double *p) { ...@@ -343,45 +337,43 @@ static int is_degenerate_homography(double *p) {
} }
int ransac_translation(int *matched_points, int npoints, int *number_of_inliers, int ransac_translation(int *matched_points, int npoints, int *number_of_inliers,
int *best_inlier_mask, double *best_params) { double *best_params) {
return ransac(matched_points, npoints, number_of_inliers, best_inlier_mask, return ransac(matched_points, npoints, number_of_inliers, best_params, 3,
best_params, 3, is_degenerate_translation, find_translation, is_degenerate_translation, find_translation,
project_points_double_translation); project_points_double_translation);
} }
int ransac_rotzoom(int *matched_points, int npoints, int *number_of_inliers, int ransac_rotzoom(int *matched_points, int npoints, int *number_of_inliers,
int *best_inlier_mask, double *best_params) { double *best_params) {
return ransac(matched_points, npoints, number_of_inliers, best_inlier_mask, return ransac(matched_points, npoints, number_of_inliers, best_params, 3,
best_params, 3, is_degenerate_affine, find_rotzoom, is_degenerate_affine, find_rotzoom,
project_points_double_rotzoom); project_points_double_rotzoom);
} }
int ransac_affine(int *matched_points, int npoints, int *number_of_inliers, int ransac_affine(int *matched_points, int npoints, int *number_of_inliers,
int *best_inlier_mask, double *best_params) { double *best_params) {
return ransac(matched_points, npoints, number_of_inliers, best_inlier_mask, return ransac(matched_points, npoints, number_of_inliers, best_params, 3,
best_params, 3, is_degenerate_affine, find_affine, is_degenerate_affine, find_affine,
project_points_double_affine); project_points_double_affine);
} }
int ransac_homography(int *matched_points, int npoints, int *number_of_inliers, int ransac_homography(int *matched_points, int npoints, int *number_of_inliers,
int *best_inlier_mask, double *best_params) { double *best_params) {
return ransac(matched_points, npoints, number_of_inliers, best_inlier_mask, return ransac(matched_points, npoints, number_of_inliers, best_params, 4,
best_params, 4, is_degenerate_homography, find_homography, is_degenerate_homography, find_homography,
project_points_double_homography); project_points_double_homography);
} }
int ransac_hortrapezoid(int *matched_points, int npoints, int ransac_hortrapezoid(int *matched_points, int npoints,
int *number_of_inliers, int *best_inlier_mask, int *number_of_inliers, double *best_params) {
double *best_params) { return ransac(matched_points, npoints, number_of_inliers, best_params, 4,
return ransac(matched_points, npoints, number_of_inliers, best_inlier_mask, is_degenerate_homography, find_hortrapezoid,
best_params, 4, is_degenerate_homography, find_hortrapezoid,
project_points_double_hortrapezoid); project_points_double_hortrapezoid);
} }
int ransac_vertrapezoid(int *matched_points, int npoints, int ransac_vertrapezoid(int *matched_points, int npoints,
int *number_of_inliers, int *best_inlier_mask, int *number_of_inliers, double *best_params) {
double *best_params) { return ransac(matched_points, npoints, number_of_inliers, best_params, 4,
return ransac(matched_points, npoints, number_of_inliers, best_inlier_mask, is_degenerate_homography, find_vertrapezoid,
best_params, 4, is_degenerate_homography, find_vertrapezoid,
project_points_double_vertrapezoid); project_points_double_vertrapezoid);
} }
...@@ -20,23 +20,20 @@ ...@@ -20,23 +20,20 @@
#include "av1/common/warped_motion.h" #include "av1/common/warped_motion.h"
typedef int (*RansacFunc)(int *matched_points, int npoints, typedef int (*RansacFunc)(int *matched_points, int npoints,
int *number_of_inliers, int *best_inlier_mask, int *number_of_inliers, double *best_params);
double *best_params);
/* Each of these functions fits a motion model from a set of /* Each of these functions fits a motion model from a set of
corresponding points in 2 frames using RANSAC. */ corresponding points in 2 frames using RANSAC. */
int ransac_homography(int *matched_points, int npoints, int *number_of_inliers, int ransac_homography(int *matched_points, int npoints, int *number_of_inliers,
int *best_inlier_indices, double *best_params); double *best_params);
int ransac_affine(int *matched_points, int npoints, int *number_of_inliers, int ransac_affine(int *matched_points, int npoints, int *number_of_inliers,
int *best_inlier_indices, double *best_params); double *best_params);
int ransac_hortrapezoid(int *matched_points, int npoints, int ransac_hortrapezoid(int *matched_points, int npoints,
int *number_of_inliers, int *best_inlier_indices, int *number_of_inliers, double *best_params);
double *best_params);
int ransac_vertrapezoid(int *matched_points, int npoints, int ransac_vertrapezoid(int *matched_points, int npoints,
int *number_of_inliers, int *best_inlier_indices, int *number_of_inliers, double *best_params);
double *best_params);
int ransac_rotzoom(int *matched_points, int npoints, int *number_of_inliers, int ransac_rotzoom(int *matched_points, int npoints, int *number_of_inliers,
int *best_inlier_indices, double *best_params); double *best_params);
int ransac_translation(int *matched_points, int npoints, int *number_of_inliers, int ransac_translation(int *matched_points, int npoints, int *number_of_inliers,
int *best_inlier_indices, double *best_params); double *best_params);
#endif // AV1_ENCODER_RANSAC_H_ #endif // AV1_ENCODER_RANSAC_H_
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