static int find_affine(int np, double *pts1, double *pts2, double *mat) { const int np2 = np * 2; 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]; normalize_homography(pts1, np, T1); normalize_homography(pts2, np, T2); for (i = 0; i < np; ++i) { dx = *(pts2++); dy = *(pts2++); sx = *(pts1++); sy = *(pts1++); a[i * 2 * 6 + 0] = sx; a[i * 2 * 6 + 1] = sy; a[i * 2 * 6 + 2] = 0; a[i * 2 * 6 + 3] = 0; a[i * 2 * 6 + 4] = 1; a[i * 2 * 6 + 5] = 0; a[(i * 2 + 1) * 6 + 0] = 0; a[(i * 2 + 1) * 6 + 1] = 0; a[(i * 2 + 1) * 6 + 2] = sx; a[(i * 2 + 1) * 6 + 3] = sy; a[(i * 2 + 1) * 6 + 4] = 0; a[(i * 2 + 1) * 6 + 5] = 1; b[2 * i] = dx; b[2 * i + 1] = dy; } if (pseudo_inverse(temp, a, np2, 6)) { aom_free(a); return 1; } multiply_mat(temp, b, mat, 6, np2, 1); denormalize_affine_reorder(mat, T1, T2); aom_free(a); return 0; }
static int find_affine(int np, double *pts1, double *pts2, double *mat) { const int np2 = np * 2; double *a = (double *)aom_malloc(sizeof(*a) * (np2 * 7 + 42)); double *b = a + np2 * 6; double *temp = b + np2; int i; double sx, sy, dx, dy; double T1[9], T2[9]; normalize_homography(pts1, np, T1); normalize_homography(pts2, np, T2); for (i = 0; i < np; ++i) { dx = *(pts2++); dy = *(pts2++); sx = *(pts1++); sy = *(pts1++); a[i * 2 * 6 + 0] = sx; a[i * 2 * 6 + 1] = sy; a[i * 2 * 6 + 2] = 0; a[i * 2 * 6 + 3] = 0; a[i * 2 * 6 + 4] = 1; a[i * 2 * 6 + 5] = 0; a[(i * 2 + 1) * 6 + 0] = 0; a[(i * 2 + 1) * 6 + 1] = 0; a[(i * 2 + 1) * 6 + 2] = sx; a[(i * 2 + 1) * 6 + 3] = sy; a[(i * 2 + 1) * 6 + 4] = 0; a[(i * 2 + 1) * 6 + 5] = 1; b[2 * i] = dx; b[2 * i + 1] = dy; } if (!least_squares(6, a, np2, 6, b, temp, mat)) { aom_free(a); return 1; } denormalize_affine_reorder(mat, T1, T2); aom_free(a); return 0; }