From: Sarah Parker Date: Tue, 6 Sep 2016 18:25:04 +0000 (-0700) Subject: Style fixes for global motion experiment X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=f9a961c5d07a059c589073b7e484d0c0c21ef1d8;p=libvpx Style fixes for global motion experiment These are in response to a post-commit review in Ib6664df44090e8cfa4db9f2f9e0556931ccfe5c8 Change-Id: I1e07ccab18558dfdd996547a72a396abe02ed23d --- diff --git a/av1/common/warped_motion.c b/av1/common/warped_motion.c index 2e550cb0d..167cb66e9 100644 --- a/av1/common/warped_motion.c +++ b/av1/common/warped_motion.c @@ -16,20 +16,20 @@ #include "av1/common/warped_motion.h" -static ProjectPointsType get_project_points_type(TransformationType type) { +static ProjectPointsFunc get_project_points_type(TransformationType type) { switch (type) { - case HOMOGRAPHY: return projectPointsHomography; - case AFFINE: return projectPointsAffine; - case ROTZOOM: return projectPointsRotZoom; - case TRANSLATION: return projectPointsTranslation; + case HOMOGRAPHY: return project_points_homography; + case AFFINE: return project_points_affine; + case ROTZOOM: return project_points_rotzoom; + case TRANSLATION: return project_points_translation; default: assert(0); return NULL; } } -void projectPointsTranslation(int16_t *mat, int *points, int *proj, const int n, - const int stride_points, const int stride_proj, - const int subsampling_x, - const int subsampling_y) { +void project_points_translation(int16_t *mat, int *points, int *proj, + const int n, const int stride_points, + const int stride_proj, const int subsampling_x, + const int subsampling_y) { int i; for (i = 0; i < n; ++i) { const int x = *(points++), y = *(points++); @@ -52,9 +52,9 @@ void projectPointsTranslation(int16_t *mat, int *points, int *proj, const int n, } } -void projectPointsRotZoom(int16_t *mat, int *points, int *proj, const int n, - const int stride_points, const int stride_proj, - const int subsampling_x, const int subsampling_y) { +void project_points_rotzoom(int16_t *mat, int *points, int *proj, const int n, + const int stride_points, const int stride_proj, + const int subsampling_x, const int subsampling_y) { int i; for (i = 0; i < n; ++i) { const int x = *(points++), y = *(points++); @@ -79,9 +79,9 @@ void projectPointsRotZoom(int16_t *mat, int *points, int *proj, const int n, } } -void projectPointsAffine(int16_t *mat, int *points, int *proj, const int n, - const int stride_points, const int stride_proj, - const int subsampling_x, const int subsampling_y) { +void project_points_affine(int16_t *mat, int *points, int *proj, const int n, + const int stride_points, const int stride_proj, + const int subsampling_x, const int subsampling_y) { int i; for (i = 0; i < n; ++i) { const int x = *(points++), y = *(points++); @@ -106,9 +106,10 @@ void projectPointsAffine(int16_t *mat, int *points, int *proj, const int n, } } -void projectPointsHomography(int16_t *mat, int *points, int *proj, const int n, - const int stride_points, const int stride_proj, - const int subsampling_x, const int subsampling_y) { +void project_points_homography(int16_t *mat, int *points, int *proj, + const int n, const int stride_points, + const int stride_proj, const int subsampling_x, + const int subsampling_y) { int i; int64_t x, y, Z; int64_t xp, yp; @@ -226,24 +227,6 @@ static int32_t do_cubic_filter(int32_t *p, int x) { } } -/* -static int32_t do_linear_filter(int32_t *p, int x) { - int32_t sum = 0; - sum = p[0] * (WARPEDPIXEL_PREC_SHIFTS - x) + p[1] * x; - sum <<= (WARPEDPIXEL_FILTER_BITS - WARPEDPIXEL_PREC_BITS); - return sum; -} - -static int32_t do_4tap_filter(int32_t *p, int x) { - int i; - int32_t sum = 0; - for (i = 0; i < 4; ++i) { - sum += p[i - 1] * filter_4tap[x][i]; - } - return sum; -} -*/ - static INLINE void get_subcolumn(int taps, uint8_t *ref, int32_t *col, int stride, int x, int y_start) { int i; @@ -473,7 +456,7 @@ static double highbd_warp_erroradv(WarpedMotionParams *wm, uint8_t *ref8, int subsampling_x, int subsampling_y, int x_scale, int y_scale, int bd) { int i, j; - ProjectPointsType projectpoints = get_project_points_type(wm->wmtype); + ProjectPointsFunc projectpoints = get_project_points_type(wm->wmtype); uint16_t *dst = CONVERT_TO_SHORTPTR(dst8); uint16_t *ref = CONVERT_TO_SHORTPTR(ref8); int gm_err = 0, no_gm_err = 0; @@ -506,7 +489,7 @@ static void highbd_warp_plane(WarpedMotionParams *wm, uint8_t *ref8, int width, int subsampling_y, int x_scale, int y_scale, int bd) { int i, j; - ProjectPointsType projectpoints = get_project_points_type(wm->wmtype); + ProjectPointsFunc projectpoints = get_project_points_type(wm->wmtype); uint16_t *pred = CONVERT_TO_SHORTPTR(pred8); uint16_t *ref = CONVERT_TO_SHORTPTR(ref8); if (projectpoints == NULL) return; @@ -534,7 +517,7 @@ static double warp_erroradv(WarpedMotionParams *wm, uint8_t *ref, int width, int gm_err = 0, no_gm_err = 0; int gm_sumerr = 0, no_gm_sumerr = 0; int i, j; - ProjectPointsType projectpoints = get_project_points_type(wm->wmtype); + ProjectPointsFunc projectpoints = get_project_points_type(wm->wmtype); for (i = p_row; i < p_row + p_height; ++i) { for (j = p_col; j < p_col + p_width; ++j) { int in[2], out[2]; @@ -561,7 +544,7 @@ static void warp_plane(WarpedMotionParams *wm, uint8_t *ref, int width, int subsampling_x, int subsampling_y, int x_scale, int y_scale) { int i, j; - ProjectPointsType projectpoints = get_project_points_type(wm->wmtype); + ProjectPointsFunc projectpoints = get_project_points_type(wm->wmtype); if (projectpoints == NULL) return; for (i = p_row; i < p_row + p_height; ++i) { for (j = p_col; j < p_col + p_width; ++j) { @@ -591,11 +574,10 @@ double av1_warp_erroradv(WarpedMotionParams *wm, return highbd_warp_erroradv( wm, ref, width, height, stride, dst, p_col, p_row, p_width, p_height, p_stride, subsampling_x, subsampling_y, x_scale, y_scale, bd); - else #endif // CONFIG_AOM_HIGHBITDEPTH - return warp_erroradv(wm, ref, width, height, stride, dst, p_col, p_row, - p_width, p_height, p_stride, subsampling_x, - subsampling_y, x_scale, y_scale); + return warp_erroradv(wm, ref, width, height, stride, dst, p_col, p_row, + p_width, p_height, p_stride, subsampling_x, + subsampling_y, x_scale, y_scale); } void av1_warp_plane(WarpedMotionParams *wm, diff --git a/av1/common/warped_motion.h b/av1/common/warped_motion.h index d7e8a2236..53f06dde9 100644 --- a/av1/common/warped_motion.h +++ b/av1/common/warped_motion.h @@ -8,8 +8,8 @@ * be found in the AUTHORS file in the root of the source tree. */ -#ifndef AV1_COMMON_WARPED_MOTION_H -#define AV1_COMMON_WARPED_MOTION_H +#ifndef AV1_COMMON_WARPED_MOTION_H_ +#define AV1_COMMON_WARPED_MOTION_H_ #include #include @@ -22,43 +22,29 @@ #include "aom_dsp/aom_dsp_common.h" #include "av1/common/mv.h" -// Bits of precision used for the model -#define WARPEDMODEL_PREC_BITS 8 -#define WARPEDMODEL_ROW3HOMO_PREC_BITS 12 - -// Bits of subpel precision for warped interpolation -#define WARPEDPIXEL_PREC_BITS 6 -#define WARPEDPIXEL_PREC_SHIFTS (1 << WARPEDPIXEL_PREC_BITS) - -// Taps for ntap filter -#define WARPEDPIXEL_FILTER_TAPS 6 - -// Precision of filter taps -#define WARPEDPIXEL_FILTER_BITS 7 - -#define WARPEDDIFF_PREC_BITS (WARPEDMODEL_PREC_BITS - WARPEDPIXEL_PREC_BITS) - -typedef void (*ProjectPointsType)(int16_t *mat, int *points, int *proj, +typedef void (*ProjectPointsFunc)(int16_t *mat, int *points, int *proj, const int n, const int stride_points, const int stride_proj, const int subsampling_x, const int subsampling_y); -void projectPointsHomography(int16_t *mat, int *points, int *proj, const int n, - const int stride_points, const int stride_proj, - const int subsampling_x, const int subsampling_y); +void project_points_translation(int16_t *mat, int *points, int *proj, + const int n, const int stride_points, + const int stride_proj, const int subsampling_x, + const int subsampling_y); -void projectPointsAffine(int16_t *mat, int *points, int *proj, const int n, - const int stride_points, const int stride_proj, - const int subsampling_x, const int subsampling_y); +void project_points_rotzoom(int16_t *mat, int *points, int *proj, const int n, + const int stride_points, const int stride_proj, + const int subsampling_x, const int subsampling_y); -void projectPointsRotZoom(int16_t *mat, int *points, int *proj, const int n, - const int stride_points, const int stride_proj, - const int subsampling_x, const int subsampling_y); +void project_points_affine(int16_t *mat, int *points, int *proj, const int n, + const int stride_points, const int stride_proj, + const int subsampling_x, const int subsampling_y); -void projectPointsTranslation(int16_t *mat, int *points, int *proj, const int n, - const int stride_points, const int stride_proj, - const int subsampling_x, const int subsampling_y); +void project_points_homography(int16_t *mat, int *points, int *proj, + const int n, const int stride_points, + const int stride_proj, const int subsampling_x, + const int subsampling_y); double av1_warp_erroradv(WarpedMotionParams *wm, #if CONFIG_AOM_HIGHBITDEPTH @@ -81,4 +67,4 @@ void av1_warp_plane(WarpedMotionParams *wm, // Integerize model into the WarpedMotionParams structure void av1_integerize_model(const double *model, TransformationType wmtype, WarpedMotionParams *wm); -#endif // AV1_COMMON_WARPED_MOTION_H +#endif // AV1_COMMON_WARPED_MOTION_H_ diff --git a/av1/encoder/corner_detect.c b/av1/encoder/corner_detect.c index a0500e3e7..44747d384 100644 --- a/av1/encoder/corner_detect.c +++ b/av1/encoder/corner_detect.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2010 The WebM project authors. All Rights Reserved. + * Copyright (c) 2016 The WebM project authors. All Rights Reserved. * * Use of this source code is governed by a BSD-style license * that can be found in the LICENSE file in the root of the source @@ -14,22 +14,23 @@ #include #include -#include "av1/encoder/corner_detect.h" #include "third_party/fastfeat/fast.h" +#include "av1/encoder/corner_detect.h" + // Fast_9 wrapper #define FAST_BARRIER 40 -int FastCornerDetect(unsigned char *buf, int width, int height, int stride, - int *points, int max_points) { +int fast_corner_detect(unsigned char *buf, int width, int height, int stride, + int *points, int max_points) { int num_points; - xy *frm_corners_xy = fast9_detect_nonmax(buf, width, height, stride, - FAST_BARRIER, &num_points); + xy *const frm_corners_xy = fast9_detect_nonmax(buf, width, height, stride, + FAST_BARRIER, &num_points); num_points = (num_points <= max_points ? num_points : max_points); if (num_points > 0 && frm_corners_xy) { - memcpy(points, frm_corners_xy, sizeof(xy) * num_points); + memcpy(points, frm_corners_xy, sizeof(*frm_corners_xy) * num_points); free(frm_corners_xy); return num_points; - } else { - return 0; } + free(frm_corners_xy); + return 0; } diff --git a/av1/encoder/corner_detect.h b/av1/encoder/corner_detect.h index f658a6bc0..257f1db5e 100644 --- a/av1/encoder/corner_detect.h +++ b/av1/encoder/corner_detect.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2010 The WebM project authors. All Rights Reserved. + * Copyright (c) 2016 The WebM project authors. All Rights Reserved. * * Use of this source code is governed by a BSD-style license * that can be found in the LICENSE file in the root of the source @@ -15,7 +15,7 @@ #include #include -int FastCornerDetect(unsigned char *buf, int width, int height, int stride, - int *points, int max_points); +int fast_corner_detect(unsigned char *buf, int width, int height, int stride, + int *points, int max_points); -#endif // AV1_ENCODER_CORNER_DETECT_H +#endif // AV1_ENCODER_CORNER_DETECT_H_ diff --git a/av1/encoder/corner_match.c b/av1/encoder/corner_match.c index 02e821227..2cb282b63 100644 --- a/av1/encoder/corner_match.c +++ b/av1/encoder/corner_match.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2010 The WebM project authors. All Rights Reserved. + * Copyright (c) 2016 The WebM project authors. All Rights Reserved. * * Use of this source code is governed by a BSD-style license * that can be found in the LICENSE file in the root of the source @@ -76,7 +76,7 @@ static int is_eligible_distance(double point1x, double point1y, double point2x, static void improve_correspondence(unsigned char *frm, unsigned char *ref, int width, int height, int frm_stride, int ref_stride, - correspondence *correspondences, + Correspondence *correspondences, int num_correspondences) { int i; for (i = 0; i < num_correspondences; ++i) { @@ -161,7 +161,7 @@ int determine_correspondence(unsigned char *frm, int *frm_corners, double *correspondence_pts) { // TODO(sarahparker) Improve this to include 2-way match int i, j; - correspondence *correspondences = (correspondence *)correspondence_pts; + Correspondence *correspondences = (Correspondence *)correspondence_pts; int num_correspondences = 0; for (i = 0; i < num_frm_corners; ++i) { double best_match_ncc = 0.0; diff --git a/av1/encoder/corner_match.h b/av1/encoder/corner_match.h index 01c0ea4f8..521c75686 100644 --- a/av1/encoder/corner_match.h +++ b/av1/encoder/corner_match.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2010 The WebM project authors. All Rights Reserved. + * Copyright (c) 2016 The WebM project authors. All Rights Reserved. * * Use of this source code is governed by a BSD-style license * that can be found in the LICENSE file in the root of the source @@ -18,7 +18,7 @@ typedef struct { double x, y; double rx, ry; -} correspondence; +} Correspondence; int determine_correspondence(unsigned char *frm, int *frm_corners, int num_frm_corners, unsigned char *ref, @@ -26,4 +26,4 @@ int determine_correspondence(unsigned char *frm, int *frm_corners, int height, int frm_stride, int ref_stride, double *correspondence_pts); -#endif // AV1_ENCODER_CORNER_MATCH_H +#endif // AV1_ENCODER_CORNER_MATCH_H_ diff --git a/av1/encoder/encodeframe.c b/av1/encoder/encodeframe.c index 7de74d1b6..cfc47188a 100644 --- a/av1/encoder/encodeframe.c +++ b/av1/encoder/encodeframe.c @@ -4481,13 +4481,13 @@ static void refine_integerized_param(WarpedMotionParams *wm, } } -static void convert_to_params(double *H, TransformationType type, +static void convert_to_params(const double *params, TransformationType type, int16_t *model) { int i, diag_value; int alpha_present = 0; int n_params = n_trans_model_params[type]; - model[0] = (int16_t)floor(H[0] * (1 << GM_TRANS_PREC_BITS) + 0.5); - model[1] = (int16_t)floor(H[1] * (1 << GM_TRANS_PREC_BITS) + 0.5); + model[0] = (int16_t)floor(params[0] * (1 << GM_TRANS_PREC_BITS) + 0.5); + model[1] = (int16_t)floor(params[1] * (1 << GM_TRANS_PREC_BITS) + 0.5); model[0] = (int16_t)clamp(model[0], GM_TRANS_MIN, GM_TRANS_MAX) * GM_TRANS_DECODE_FACTOR; model[1] = (int16_t)clamp(model[1], GM_TRANS_MIN, GM_TRANS_MAX) * @@ -4495,7 +4495,7 @@ static void convert_to_params(double *H, TransformationType type, for (i = 2; i < n_params; ++i) { diag_value = ((i && 1) ? (1 << GM_ALPHA_PREC_BITS) : 0); - model[i] = (int16_t)floor(H[i] * (1 << GM_ALPHA_PREC_BITS) + 0.5); + model[i] = (int16_t)floor(params[i] * (1 << GM_ALPHA_PREC_BITS) + 0.5); model[i] = (int16_t)(clamp(model[i] - diag_value, GM_ALPHA_MIN, GM_ALPHA_MAX) + diag_value) * @@ -4511,11 +4511,12 @@ static void convert_to_params(double *H, TransformationType type, } } -static void convert_model_to_params(double *H, TransformationType type, +static void convert_model_to_params(const double *params, + TransformationType type, Global_Motion_Params *model) { // TODO(sarahparker) implement for homography if (type > HOMOGRAPHY) - convert_to_params(H, type, (int16_t *)model->motion_params.wmmat); + convert_to_params(params, type, (int16_t *)model->motion_params.wmmat); model->gmtype = get_gmtype(model); model->motion_params.wmtype = gm_to_trans_type(model->gmtype); } @@ -4547,13 +4548,14 @@ static void encode_frame_internal(AV1_COMP *cpi) { if (cpi->common.frame_type == INTER_FRAME && cpi->Source) { YV12_BUFFER_CONFIG *ref_buf; int frame; - double H[9] = { 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + double erroradvantage = 0; + double params[9] = { 0, 0, 0, 0, 0, 0, 0, 0, 0 }; for (frame = LAST_FRAME; frame <= ALTREF_FRAME; ++frame) { ref_buf = get_ref_frame_buffer(cpi, frame); if (ref_buf) { if (compute_global_motion_feature_based(GLOBAL_MOTION_MODEL, - cpi->Source, ref_buf, H)) { - convert_model_to_params(H, GLOBAL_MOTION_MODEL, + cpi->Source, ref_buf, params)) { + convert_model_to_params(params, GLOBAL_MOTION_MODEL, &cm->global_motion[frame]); if (get_gmtype(&cm->global_motion[frame]) > GLOBAL_ZERO) { refine_integerized_param( @@ -4565,7 +4567,7 @@ static void encode_frame_internal(AV1_COMP *cpi) { ref_buf->y_stride, cpi->Source->y_buffer, cpi->Source->y_width, cpi->Source->y_height, cpi->Source->y_stride, 3); // compute the advantage of using gm parameters over 0 motion - double erroradvantage = av1_warp_erroradv( + erroradvantage = av1_warp_erroradv( &cm->global_motion[frame].motion_params, #if CONFIG_AOM_HIGHBITDEPTH xd->cur_buf->flags & YV12_FLAG_HIGHBITDEPTH, xd->bd, diff --git a/av1/encoder/global_motion.c b/av1/encoder/global_motion.c index cda6aaf2e..5d88dbf18 100644 --- a/av1/encoder/global_motion.c +++ b/av1/encoder/global_motion.c @@ -25,12 +25,12 @@ #define MAX_CORNERS 4096 #define MIN_INLIER_PROB 0.1 -INLINE RansacType get_ransac_type(TransformationType type) { +INLINE RansacFunc get_ransac_type(TransformationType type) { switch (type) { - case HOMOGRAPHY: return ransacHomography; - case AFFINE: return ransacAffine; - case ROTZOOM: return ransacRotZoom; - case TRANSLATION: return ransacTranslation; + case HOMOGRAPHY: return ransac_homography; + case AFFINE: return ransac_affine; + case ROTZOOM: return ransac_rotzoom; + case TRANSLATION: return ransac_translation; default: assert(0); return NULL; } } @@ -42,7 +42,7 @@ static int compute_global_motion_params(TransformationType type, int *inlier_map) { int result; int num_inliers = 0; - RansacType ransac = get_ransac_type(type); + RansacFunc ransac = get_ransac_type(type); if (ransac == NULL) return 0; result = ransac(correspondences, num_correspondences, &num_inliers, @@ -66,10 +66,12 @@ int compute_global_motion_feature_based(TransformationType type, int *inlier_map = NULL; // compute interest points in images using FAST features - num_frm_corners = FastCornerDetect(frm->y_buffer, frm->y_width, frm->y_height, - frm->y_stride, frm_corners, MAX_CORNERS); - num_ref_corners = FastCornerDetect(ref->y_buffer, ref->y_width, ref->y_height, - ref->y_stride, ref_corners, MAX_CORNERS); + num_frm_corners = + fast_corner_detect(frm->y_buffer, frm->y_width, frm->y_height, + frm->y_stride, frm_corners, MAX_CORNERS); + num_ref_corners = + fast_corner_detect(ref->y_buffer, ref->y_width, ref->y_height, + ref->y_stride, ref_corners, MAX_CORNERS); // find correspondences between the two images correspondences = diff --git a/av1/encoder/ransac.c b/av1/encoder/ransac.c index 81c1c21eb..a6533cad2 100644 --- a/av1/encoder/ransac.c +++ b/av1/encoder/ransac.c @@ -28,14 +28,14 @@ static const double TINY_NEAR_ZERO = 1.0E-12; -static inline double SIGN(double a, double b) { +static INLINE double sign(double a, double b) { return ((b) >= 0 ? fabs(a) : -fabs(a)); } -static inline double PYTHAG(double a, double b) { - double absa, absb, ct; - absa = fabs(a); - absb = fabs(b); +static INLINE double pythag(double a, double b) { + double ct; + const double absa = fabs(a); + const double absb = fabs(b); if (absa > absb) { ct = absb / absa; @@ -46,33 +46,27 @@ static inline double PYTHAG(double a, double b) { } } -int IMIN(int a, int b) { return (((a) < (b)) ? (a) : (b)); } - -int IMAX(int a, int b) { return (((a) < (b)) ? (b) : (a)); } - -void MultiplyMat(double *m1, double *m2, double *res, const int M1, - const int N1, const int N2) { - int timesInner = N1; - int timesRows = M1; - int timesCols = N2; +static void multiply_mat(const double *m1, const double *m2, double *res, + const int m1_rows, const int inner_dim, + const int m2_cols) { double sum; int row, col, inner; - for (row = 0; row < timesRows; ++row) { - for (col = 0; col < timesCols; ++col) { + for (row = 0; row < m1_rows; ++row) { + for (col = 0; col < m2_cols; ++col) { sum = 0; - for (inner = 0; inner < timesInner; ++inner) - sum += m1[row * N1 + inner] * m2[inner * N2 + col]; + for (inner = 0; inner < inner_dim; ++inner) + sum += m1[row * m1_rows + inner] * m2[inner * m2_cols + col]; *(res++) = sum; } } } -static int svdcmp_(double **u, int m, int n, double w[], double **v) { +static int svdcmp(double **u, int m, int n, double w[], double **v) { const int max_its = 30; int flag, i, its, j, jj, k, l, nm; double anorm, c, f, g, h, s, scale, x, y, z; - double *rv1 = (double *)malloc(sizeof(*rv1) * (n + 1)); + double *rv1 = (double *)aom_malloc(sizeof(*rv1) * (n + 1)); g = scale = anorm = 0.0; for (i = 0; i < n; i++) { l = i + 1; @@ -86,7 +80,7 @@ static int svdcmp_(double **u, int m, int n, double w[], double **v) { s += u[k][i] * u[k][i]; } f = u[i][i]; - g = -SIGN(sqrt(s), f); + g = -sign(sqrt(s), f); h = f * g - s; u[i][i] = f - g; for (j = l; j < n; j++) { @@ -107,7 +101,7 @@ static int svdcmp_(double **u, int m, int n, double w[], double **v) { s += u[i][k] * u[i][k]; } f = u[i][l]; - g = -SIGN(sqrt(s), f); + g = -sign(sqrt(s), f); h = f * g - s; u[i][l] = f - g; for (k = l; k < n; k++) rv1[k] = u[i][k] / h; @@ -136,8 +130,7 @@ static int svdcmp_(double **u, int m, int n, double w[], double **v) { g = rv1[i]; l = i; } - - for (i = IMIN(m, n) - 1; i >= 0; i--) { + for (i = AOMMIN(m, n) - 1; i >= 0; i--) { l = i + 1; g = w[i]; for (j = l; j < n; j++) u[i][j] = 0.0; @@ -173,7 +166,7 @@ static int svdcmp_(double **u, int m, int n, double w[], double **v) { rv1[i] = c * rv1[i]; if ((double)(fabs(f) + anorm) == anorm) break; g = w[i]; - h = PYTHAG(f, g); + h = pythag(f, g); w[i] = h; h = 1.0 / h; c = g * h; @@ -204,8 +197,8 @@ static int svdcmp_(double **u, int m, int n, double w[], double **v) { g = rv1[nm]; h = rv1[k]; f = ((y - z) * (y + z) + (g - h) * (g + h)) / (2.0 * h * y); - g = PYTHAG(f, 1.0); - f = ((x - z) * (x + z) + h * ((y / (f + SIGN(g, f))) - h)) / x; + g = pythag(f, 1.0); + f = ((x - z) * (x + z) + h * ((y / (f + sign(g, f))) - h)) / x; c = s = 1.0; for (j = l; j <= nm; j++) { i = j + 1; @@ -213,7 +206,7 @@ static int svdcmp_(double **u, int m, int n, double w[], double **v) { y = w[i]; h = s * g; g = c * g; - z = PYTHAG(f, h); + z = pythag(f, h); rv1[j] = z; c = f / z; s = h / z; @@ -227,7 +220,7 @@ static int svdcmp_(double **u, int m, int n, double w[], double **v) { v[jj][j] = x * c + z * s; v[jj][i] = z * c - x * s; } - z = PYTHAG(f, h); + z = pythag(f, h); w[j] = z; if (z) { z = 1.0 / z; @@ -248,28 +241,27 @@ static int svdcmp_(double **u, int m, int n, double w[], double **v) { w[k] = x; } } - free(rv1); + aom_free(rv1); return 0; } static int SVD(double *U, double *W, double *V, double *matx, int M, int N) { // Assumes allocation for U is MxN - double **nrU, **nrV; + double **nrU = (double **)aom_malloc((M) * sizeof(*nrU)); + double **nrV = (double **)aom_malloc((N) * sizeof(*nrV)); int problem, i; - nrU = (double **)malloc((M) * sizeof(*nrU)); - nrV = (double **)malloc((N) * sizeof(*nrV)); problem = !(nrU && nrV); if (!problem) { - problem = 0; for (i = 0; i < M; i++) { nrU[i] = &U[i * N]; } for (i = 0; i < N; i++) { nrV[i] = &V[i * N]; } - } - if (problem) { + } else { + if (nrU) aom_free(nrU); + if (nrV) aom_free(nrV); return 1; } @@ -279,23 +271,25 @@ static int SVD(double *U, double *W, double *V, double *matx, int M, int N) { } /* HERE IT IS: do SVD */ - if (svdcmp_(nrU, M, N, W, nrV)) { + if (svdcmp(nrU, M, N, W, nrV)) { + aom_free(nrU); + aom_free(nrV); return 1; } - /* free Numerical Recipes arrays */ - free(nrU); - free(nrV); + /* aom_free Numerical Recipes arrays */ + aom_free(nrU); + aom_free(nrV); return 0; } -int PseudoInverse(double *inv, double *matx, const int M, const int N) { - double *U, *W, *V, ans; +int pseudo_inverse(double *inv, double *matx, const int M, const int N) { + double ans; int i, j, k; - U = (double *)malloc(M * N * sizeof(*matx)); - W = (double *)malloc(N * sizeof(*matx)); - V = (double *)malloc(N * N * sizeof(*matx)); + double *const U = (double *)aom_malloc(M * N * sizeof(*matx)); + double *const W = (double *)aom_malloc(N * sizeof(*matx)); + double *const V = (double *)aom_malloc(N * N * sizeof(*matx)); if (!(U && W && V)) { return 1; @@ -318,19 +312,19 @@ int PseudoInverse(double *inv, double *matx, const int M, const int N) { inv[j + M * i] = ans; } } - free(U); - free(W); - free(V); + aom_free(U); + aom_free(W); + aom_free(V); return 0; } //////////////////////////////////////////////////////////////////////////////// // ransac -typedef int (*isDegenerateType)(double *p); -typedef void (*normalizeType)(double *p, int np, double *T); -typedef void (*denormalizeType)(double *H, double *T1, double *T2); -typedef int (*findTransformationType)(int points, double *points1, - double *points2, double *H); +typedef int (*IsDegenerateFunc)(double *p); +typedef void (*NormalizeFunc)(double *p, int np, double *T); +typedef void (*DenormalizeFunc)(double *params, double *T1, double *T2); +typedef int (*FindTransformationFunc)(int points, double *points1, + double *points2, double *params); static int get_rand_indices(int npoints, int minpts, int *indices) { int i, j; @@ -354,12 +348,12 @@ static int get_rand_indices(int npoints, int minpts, int *indices) { return 1; } -int ransac_(double *matched_points, int npoints, int *number_of_inliers, - int *best_inlier_mask, double *bestH, const int minpts, - const int paramdim, isDegenerateType isDegenerate, - normalizeType normalize, denormalizeType denormalize, - findTransformationType findTransformation, - ProjectPointsType projectpoints, TransformationType type) { +static int ransac(double *matched_points, int npoints, int *number_of_inliers, + int *best_inlier_mask, double *best_params, const int minpts, + const int paramdim, IsDegenerateFunc is_degenerate, + NormalizeFunc normalize, DenormalizeFunc denormalize, + FindTransformationFunc find_transformation, + ProjectPointsFunc projectpoints, TransformationType type) { static const double INLIER_THRESHOLD_NORMALIZED = 0.1; static const double INLIER_THRESHOLD_UNNORMALIZED = 1.0; static const double PROBABILITY_REQUIRED = 0.9; @@ -375,7 +369,7 @@ int ransac_(double *matched_points, int npoints, int *number_of_inliers, int max_inliers = 0; double best_variance = 0.0; - double H[MAX_PARAMDIM]; + double params[MAX_PARAMDIM]; WarpedMotionParams wm; double points1[2 * MAX_MINPTS]; double points2[2 * MAX_MINPTS]; @@ -405,15 +399,23 @@ int ransac_(double *matched_points, int npoints, int *number_of_inliers, } memset(&wm, 0, sizeof(wm)); - best_inlier_set1 = (double *)malloc(sizeof(*best_inlier_set1) * npoints * 2); - best_inlier_set2 = (double *)malloc(sizeof(*best_inlier_set2) * npoints * 2); - inlier_set1 = (double *)malloc(sizeof(*inlier_set1) * npoints * 2); - inlier_set2 = (double *)malloc(sizeof(*inlier_set2) * npoints * 2); - corners1 = (double *)malloc(sizeof(*corners1) * npoints * 2); - corners1_int = (int *)malloc(sizeof(*corners1_int) * npoints * 2); - corners2 = (double *)malloc(sizeof(*corners2) * npoints * 2); - image1_coord = (int *)malloc(sizeof(*image1_coord) * npoints * 2); - inlier_mask = (int *)malloc(sizeof(*inlier_mask) * npoints); + best_inlier_set1 = + (double *)aom_malloc(sizeof(*best_inlier_set1) * npoints * 2); + best_inlier_set2 = + (double *)aom_malloc(sizeof(*best_inlier_set2) * npoints * 2); + inlier_set1 = (double *)aom_malloc(sizeof(*inlier_set1) * npoints * 2); + inlier_set2 = (double *)aom_malloc(sizeof(*inlier_set2) * npoints * 2); + corners1 = (double *)aom_malloc(sizeof(*corners1) * npoints * 2); + corners1_int = (int *)aom_malloc(sizeof(*corners1_int) * npoints * 2); + corners2 = (double *)aom_malloc(sizeof(*corners2) * npoints * 2); + image1_coord = (int *)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 && + corners1 && corners1_int && corners2 && image1_coord && inlier_mask)) { + ret_val = 1; + goto finish_ransac; + } for (cnp1 = corners1, cnp2 = corners2, i = 0; i < npoints; ++i) { *(cnp1++) = *(matched_points++); @@ -451,14 +453,14 @@ int ransac_(double *matched_points, int npoints, int *number_of_inliers, points2[i * 2 + 1] = corners2[index * 2 + 1]; i++; } - degenerate = isDegenerate(points1); + degenerate = is_degenerate(points1); if (num_degenerate_iter > MAX_DEGENERATE_ITER) { ret_val = 1; goto finish_ransac; } } - if (findTransformation(minpts, points1, points2, H)) { + if (find_transformation(minpts, points1, points2, params)) { trial_count++; continue; } @@ -468,7 +470,7 @@ int ransac_(double *matched_points, int npoints, int *number_of_inliers, corners1_int[2 * i + 1] = (int)corners1[i * 2 + 1]; } - av1_integerize_model(H, type, &wm); + av1_integerize_model(params, type, &wm); projectpoints((int16_t *)wm.wmmat, corners1_int, image1_coord, npoints, 2, 2, 0, 0); @@ -500,7 +502,7 @@ int ransac_(double *matched_points, int npoints, int *number_of_inliers, (num_inliers == max_inliers && variance < best_variance)) { best_variance = variance; max_inliers = num_inliers; - memcpy(bestH, H, paramdim * sizeof(*bestH)); + memcpy(best_params, params, paramdim * sizeof(*best_params)); memcpy(best_inlier_set1, inlier_set1, num_inliers * 2 * sizeof(*best_inlier_set1)); memcpy(best_inlier_set2, inlier_set2, @@ -516,33 +518,34 @@ int ransac_(double *matched_points, int npoints, int *number_of_inliers, pNoOutliers = fmin(1 - EPS, pNoOutliers); temp = (int)(log(1.0 - PROBABILITY_REQUIRED) / log(pNoOutliers)); if (temp > 0 && temp < N) { - N = IMAX(temp, MIN_TRIALS); + N = AOMMAX(temp, MIN_TRIALS); } } } } trial_count++; } - findTransformation(max_inliers, best_inlier_set1, best_inlier_set2, bestH); + find_transformation(max_inliers, best_inlier_set1, best_inlier_set2, + best_params); if (normalize && denormalize) { - denormalize(bestH, T1, T2); + denormalize(best_params, T1, T2); } *number_of_inliers = max_inliers; finish_ransac: - free(best_inlier_set1); - free(best_inlier_set2); - free(inlier_set1); - free(inlier_set2); - free(corners1); - free(corners2); - free(image1_coord); - free(inlier_mask); + aom_free(best_inlier_set1); + aom_free(best_inlier_set2); + aom_free(inlier_set1); + aom_free(inlier_set2); + aom_free(corners1); + aom_free(corners2); + aom_free(image1_coord); + aom_free(inlier_mask); return ret_val; } /////////////////////////////////////////////////////////////////////////////// -static void normalizeHomography(double *pts, int n, double *T) { +static void normalize_homography(double *pts, int n, double *T) { // Assume the points are 2d coordinates with scale = 1 double *p = pts; double mean[2] = { 0, 0 }; @@ -592,63 +595,63 @@ static void invnormalize_mat(double *T, double *iT) { iT[8] = 1; } -static void denormalizeHomography(double *H, double *T1, double *T2) { +static void denormalize_homography(double *params, double *T1, double *T2) { double iT2[9]; - double H2[9]; + double params2[9]; invnormalize_mat(T2, iT2); - MultiplyMat(H, T1, H2, 3, 3, 3); - MultiplyMat(iT2, H2, H, 3, 3, 3); + multiply_mat(params, T1, params2, 3, 3, 3); + multiply_mat(iT2, params2, params, 3, 3, 3); } -static void denormalizeAffine(double *H, double *T1, double *T2) { - double Ha[MAX_PARAMDIM]; - Ha[0] = H[0]; - Ha[1] = H[1]; - Ha[2] = H[4]; - Ha[3] = H[2]; - Ha[4] = H[3]; - Ha[5] = H[5]; - Ha[6] = Ha[7] = 0; - Ha[8] = 1; - denormalizeHomography(Ha, T1, T2); - H[0] = Ha[5]; - H[1] = Ha[2]; - H[2] = Ha[1]; - H[3] = Ha[0]; - H[4] = Ha[3]; - H[5] = Ha[4]; +static void denormalize_affine(double *params, double *T1, double *T2) { + double params_denorm[MAX_PARAMDIM]; + params_denorm[0] = params[0]; + params_denorm[1] = params[1]; + params_denorm[2] = params[4]; + params_denorm[3] = params[2]; + params_denorm[4] = params[3]; + params_denorm[5] = params[5]; + params_denorm[6] = params_denorm[7] = 0; + params_denorm[8] = 1; + denormalize_homography(params_denorm, T1, T2); + params[0] = params_denorm[5]; + params[1] = params_denorm[2]; + params[2] = params_denorm[1]; + params[3] = params_denorm[0]; + params[4] = params_denorm[3]; + params[5] = params_denorm[4]; } -static void denormalizeRotZoom(double *H, double *T1, double *T2) { - double Ha[MAX_PARAMDIM]; - Ha[0] = H[0]; - Ha[1] = H[1]; - Ha[2] = H[2]; - Ha[3] = -H[1]; - Ha[4] = H[0]; - Ha[5] = H[3]; - Ha[6] = Ha[7] = 0; - Ha[8] = 1; - denormalizeHomography(Ha, T1, T2); - H[0] = Ha[5]; - H[1] = Ha[2]; - H[2] = Ha[1]; - H[3] = Ha[0]; +static void denormalize_rotzoom(double *params, double *T1, double *T2) { + double params_denorm[MAX_PARAMDIM]; + params_denorm[0] = params[0]; + params_denorm[1] = params[1]; + params_denorm[2] = params[2]; + params_denorm[3] = -params[1]; + params_denorm[4] = params[0]; + params_denorm[5] = params[3]; + params_denorm[6] = params_denorm[7] = 0; + params_denorm[8] = 1; + denormalize_homography(params_denorm, T1, T2); + params[0] = params_denorm[5]; + params[1] = params_denorm[2]; + params[2] = params_denorm[1]; + params[3] = params_denorm[0]; } -static void denormalizeTranslation(double *H, double *T1, double *T2) { - double Ha[MAX_PARAMDIM]; - Ha[0] = 1; - Ha[1] = 0; - Ha[2] = H[0]; - Ha[3] = 0; - Ha[4] = 1; - Ha[5] = H[1]; - Ha[6] = Ha[7] = 0; - Ha[8] = 1; - denormalizeHomography(Ha, T1, T2); - H[0] = Ha[5]; - H[1] = Ha[2]; +static void denormalize_translation(double *params, double *T1, double *T2) { + double params_denorm[MAX_PARAMDIM]; + params_denorm[0] = 1; + params_denorm[1] = 0; + params_denorm[2] = params[0]; + params_denorm[3] = 0; + params_denorm[4] = 1; + params_denorm[5] = params[1]; + params_denorm[6] = params_denorm[7] = 0; + params_denorm[8] = 1; + denormalize_homography(params_denorm, T1, T2); + params[0] = params_denorm[5]; + params[1] = params_denorm[2]; } static int is_collinear3(double *p1, double *p2, double *p3) { @@ -658,27 +661,27 @@ static int is_collinear3(double *p1, double *p2, double *p3) { return fabs(v) < collinear_eps; } -static int isDegenerateTranslation(double *p) { +static int is_degenerate_translation(double *p) { return (p[0] - p[2]) * (p[0] - p[2]) + (p[1] - p[3]) * (p[1] - p[3]) <= 2; } -static int isDegenerateAffine(double *p) { +static int is_degenerate_affine(double *p) { return is_collinear3(p, p + 2, p + 4); } -static int isDegenerateHomography(double *p) { +static int is_degenerate_homography(double *p) { return is_collinear3(p, p + 2, p + 4) || is_collinear3(p, p + 2, p + 6) || is_collinear3(p, p + 4, p + 6) || is_collinear3(p + 2, p + 4, p + 6); } -int findTranslation(const int np, double *pts1, double *pts2, double *mat) { +int find_translation(const int np, double *pts1, double *pts2, double *mat) { int i; double sx, sy, dx, dy; double sumx, sumy; double T1[9], T2[9]; - normalizeHomography(pts1, np, T1); - normalizeHomography(pts2, np, T2); + normalize_homography(pts1, np, T1); + normalize_homography(pts2, np, T2); sumx = 0; sumy = 0; @@ -693,21 +696,21 @@ int findTranslation(const int np, double *pts1, double *pts2, double *mat) { } mat[0] = sumx / np; mat[1] = sumy / np; - denormalizeTranslation(mat, T1, T2); + denormalize_translation(mat, T1, T2); return 0; } -int findRotZoom(const int np, double *pts1, double *pts2, double *mat) { +int find_rotzoom(const int np, double *pts1, double *pts2, double *mat) { const int np2 = np * 2; - double *a = (double *)malloc(sizeof(*a) * np2 * 9); + double *a = (double *)aom_malloc(sizeof(*a) * np2 * 9); double *b = a + np2 * 4; double *temp = b + np2; int i; double sx, sy, dx, dy; double T1[9], T2[9]; - normalizeHomography(pts1, np, T1); - normalizeHomography(pts2, np, T2); + normalize_homography(pts1, np, T1); + normalize_homography(pts2, np, T2); for (i = 0; i < np; ++i) { dx = *(pts2++); @@ -727,27 +730,27 @@ int findRotZoom(const int np, double *pts1, double *pts2, double *mat) { b[2 * i] = dx; b[2 * i + 1] = dy; } - if (PseudoInverse(temp, a, np2, 4)) { - free(a); + if (pseudo_inverse(temp, a, np2, 4)) { + aom_free(a); return 1; } - MultiplyMat(temp, b, mat, 4, np2, 1); - denormalizeRotZoom(mat, T1, T2); - free(a); + multiply_mat(temp, b, mat, 4, np2, 1); + denormalize_rotzoom(mat, T1, T2); + aom_free(a); return 0; } -int findAffine(const int np, double *pts1, double *pts2, double *mat) { +int find_affine(const int np, double *pts1, double *pts2, double *mat) { const int np2 = np * 2; - double *a = (double *)malloc(sizeof(*a) * np2 * 13); + double *a = (double *)aom_malloc(sizeof(*a) * np2 * 13); double *b = a + np2 * 6; double *temp = b + np2; int i; double sx, sy, dx, dy; double T1[9], T2[9]; - normalizeHomography(pts1, np, T1); - normalizeHomography(pts2, np, T2); + normalize_homography(pts1, np, T1); + normalize_homography(pts2, np, T2); for (i = 0; i < np; ++i) { dx = *(pts2++); @@ -771,28 +774,28 @@ int findAffine(const int np, double *pts1, double *pts2, double *mat) { b[2 * i] = dx; b[2 * i + 1] = dy; } - if (PseudoInverse(temp, a, np2, 6)) { - free(a); + if (pseudo_inverse(temp, a, np2, 6)) { + aom_free(a); return 1; } - MultiplyMat(temp, b, mat, 6, np2, 1); - denormalizeAffine(mat, T1, T2); - free(a); + multiply_mat(temp, b, mat, 6, np2, 1); + denormalize_affine(mat, T1, T2); + aom_free(a); return 0; } -int findHomography(const int np, double *pts1, double *pts2, double *mat) { +int find_homography(const int np, double *pts1, double *pts2, double *mat) { // Implemented from Peter Kovesi's normalized implementation const int np3 = np * 3; - double *a = (double *)malloc(sizeof(*a) * np3 * 18); + double *a = (double *)aom_malloc(sizeof(*a) * np3 * 18); double *U = a + np3 * 9; double S[9], V[9 * 9]; int i, mini; double sx, sy, dx, dy; double T1[9], T2[9]; - normalizeHomography(pts1, np, T1); - normalizeHomography(pts2, np, T2); + normalize_homography(pts1, np, T1); + normalize_homography(pts2, np, T2); for (i = 0; i < np; ++i) { dx = *(pts2++); @@ -828,7 +831,7 @@ int findHomography(const int np, double *pts1, double *pts2, double *mat) { } if (SVD(U, S, V, a, np3, 9)) { - free(a); + aom_free(a); return 1; } else { double minS = 1e12; @@ -842,100 +845,57 @@ int findHomography(const int np, double *pts1, double *pts2, double *mat) { } for (i = 0; i < 9; i++) mat[i] = V[i * 9 + mini]; - denormalizeHomography(mat, T1, T2); - free(a); + denormalize_homography(mat, T1, T2); + aom_free(a); if (mat[8] == 0.0) { return 1; } return 0; } -int findHomographyScale1(const int np, double *pts1, double *pts2, - double *mat) { - // This implementation assumes h33 = 1, but does not seem to give good results - const int np2 = np * 2; - double *a = (double *)malloc(sizeof(*a) * np2 * 17); - double *b = a + np2 * 8; - double *temp = b + np2; - int i, j; - double sx, sy, dx, dy; - double T1[9], T2[9]; - - normalizeHomography(pts1, np, T1); - normalizeHomography(pts2, np, T2); - - for (i = 0, j = np; i < np; ++i, ++j) { - dx = *(pts2++); - dy = *(pts2++); - sx = *(pts1++); - sy = *(pts1++); - a[i * 8 + 0] = a[j * 8 + 3] = sx; - a[i * 8 + 1] = a[j * 8 + 4] = sy; - a[i * 8 + 2] = a[j * 8 + 5] = 1; - a[i * 8 + 3] = a[i * 8 + 4] = a[i * 8 + 5] = a[j * 8 + 0] = a[j * 8 + 1] = - a[j * 8 + 2] = 0; - a[i * 8 + 6] = -dx * sx; - a[i * 8 + 7] = -dx * sy; - a[j * 8 + 6] = -dy * sx; - a[j * 8 + 7] = -dy * sy; - b[i] = dx; - b[j] = dy; - } - - if (PseudoInverse(temp, a, np2, 8)) { - free(a); - return 1; - } - MultiplyMat(temp, b, &*mat, 8, np2, 1); - mat[8] = 1; - - denormalizeHomography(mat, T1, T2); - free(a); - return 0; -} - -int ransacTranslation(double *matched_points, int npoints, - int *number_of_inliers, int *best_inlier_mask, - double *bestH) { - return ransac_(matched_points, npoints, number_of_inliers, best_inlier_mask, - bestH, 3, 2, isDegenerateTranslation, - NULL, // normalizeHomography, - NULL, // denormalizeRotZoom, - findTranslation, projectPointsTranslation, TRANSLATION); +int ransac_translation(double *matched_points, int npoints, + int *number_of_inliers, int *best_inlier_mask, + double *best_params) { + return ransac(matched_points, npoints, number_of_inliers, best_inlier_mask, + best_params, 3, 2, is_degenerate_translation, + NULL, // normalize_homography, + NULL, // denormalize_rotzoom, + find_translation, project_points_translation, TRANSLATION); } -int ransacRotZoom(double *matched_points, int npoints, int *number_of_inliers, - int *best_inlier_mask, double *bestH) { - return ransac_(matched_points, npoints, number_of_inliers, best_inlier_mask, - bestH, 3, 4, isDegenerateAffine, - NULL, // normalizeHomography, - NULL, // denormalizeRotZoom, - findRotZoom, projectPointsRotZoom, ROTZOOM); +int ransac_rotzoom(double *matched_points, int npoints, int *number_of_inliers, + int *best_inlier_mask, double *best_params) { + return ransac(matched_points, npoints, number_of_inliers, best_inlier_mask, + best_params, 3, 4, is_degenerate_affine, + NULL, // normalize_homography, + NULL, // denormalize_rotzoom, + find_rotzoom, project_points_rotzoom, ROTZOOM); } -int ransacAffine(double *matched_points, int npoints, int *number_of_inliers, - int *best_inlier_mask, double *bestH) { - return ransac_(matched_points, npoints, number_of_inliers, best_inlier_mask, - bestH, 3, 6, isDegenerateAffine, - NULL, // normalizeHomography, - NULL, // denormalizeAffine, - findAffine, projectPointsAffine, AFFINE); +int ransac_affine(double *matched_points, int npoints, int *number_of_inliers, + int *best_inlier_mask, double *best_params) { + return ransac(matched_points, npoints, number_of_inliers, best_inlier_mask, + best_params, 3, 6, is_degenerate_affine, + NULL, // normalize_homography, + NULL, // denormalize_affine, + find_affine, project_points_affine, AFFINE); } -int ransacHomography(double *matched_points, int npoints, - int *number_of_inliers, int *best_inlier_mask, - double *bestH) { - int result = ransac_(matched_points, npoints, number_of_inliers, - best_inlier_mask, bestH, 4, 8, isDegenerateHomography, - NULL, // normalizeHomography, - NULL, // denormalizeHomography, - findHomography, projectPointsHomography, HOMOGRAPHY); +int ransac_homography(double *matched_points, int npoints, + int *number_of_inliers, int *best_inlier_mask, + double *best_params) { + const int result = + ransac(matched_points, npoints, number_of_inliers, best_inlier_mask, + best_params, 4, 8, is_degenerate_homography, + NULL, // normalize_homography, + NULL, // denormalize_homography, + find_homography, project_points_homography, HOMOGRAPHY); if (!result) { // normalize so that H33 = 1 int i; - double m = 1.0 / bestH[8]; - for (i = 0; i < 8; ++i) bestH[i] *= m; - bestH[8] = 1.0; + const double m = 1.0 / best_params[8]; + for (i = 0; i < 8; ++i) best_params[i] *= m; + best_params[8] = 1.0; } return result; } diff --git a/av1/encoder/ransac.h b/av1/encoder/ransac.h index c8fbdc804..f75d70f92 100644 --- a/av1/encoder/ransac.h +++ b/av1/encoder/ransac.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2010 The WebM project authors. All Rights Reserved. + * Copyright (c) 2016 The WebM project authors. All Rights Reserved. * * Use of this source code is governed by a BSD-style license * that can be found in the LICENSE file in the root of the source @@ -18,20 +18,20 @@ #include "av1/common/warped_motion.h" -typedef int (*RansacType)(double *matched_points, int npoints, +typedef int (*RansacFunc)(double *matched_points, int npoints, int *number_of_inliers, int *best_inlier_mask, - double *bestH); + double *best_params); /* Each of these functions fits a motion model from a set of corresponding points in 2 frames using RANSAC.*/ -int ransacHomography(double *matched_points, int npoints, - int *number_of_inliers, int *best_inlier_indices, - double *bestH); -int ransacAffine(double *matched_points, int npoints, int *number_of_inliers, - int *best_inlier_indices, double *bestH); -int ransacRotZoom(double *matched_points, int npoints, int *number_of_inliers, - int *best_inlier_indices, double *bestH); -int ransacTranslation(double *matched_points, int npoints, +int ransac_homography(double *matched_points, int npoints, int *number_of_inliers, int *best_inlier_indices, - double *bestH); -#endif // AV1_ENCODER_RANSAC_H + double *best_params); +int ransac_affine(double *matched_points, int npoints, int *number_of_inliers, + int *best_inlier_indices, double *best_params); +int ransac_rotzoom(double *matched_points, int npoints, int *number_of_inliers, + int *best_inlier_indices, double *best_params); +int ransac_translation(double *matched_points, int npoints, + int *number_of_inliers, int *best_inlier_indices, + double *best_params); +#endif // AV1_ENCODER_RANSAC_H_ diff --git a/third_party/fastfeat/README b/third_party/fastfeat/README.libvpx similarity index 77% rename from third_party/fastfeat/README rename to third_party/fastfeat/README.libvpx index 035599996..2edd6e7bf 100644 --- a/third_party/fastfeat/README +++ b/third_party/fastfeat/README.libvpx @@ -1,8 +1,10 @@ -This code was taken from http://www.edwardrosten.com/work/fast.html. Fast 10, 11, and 12 -have been deleted. +URL: https://github.com/edrosten/fast-C-src +Version: 391d5e939eb1545d24c10533d7de424db8d9c191 +License: BSD +License File: LICENSE -FAST feature detectors in C Version 2.0 ---------------------------------------- +Description: +Library to compute FAST features with non-maximum suppression. The files are valid C and C++ code, and have no special requirements for compiling, and they do not depend on any libraries. Just compile them along with @@ -31,4 +33,6 @@ is the same as xsize. The detection, scoring and nonmaximal suppression are available as individual functions. To see how to use the individual functions, see fast.c - +Local Modifications: +Add lines to turn off clang formatting for these files +Remove Fast 10, 11 and 12