35 return (x > 0 ? 1 : (x < 0) ? -1 : 0);
38 bool Givens(
double** C,
double* d,
double* x,
double* r,
int N,
int n,
int want_r);
50 for (
size_t i = 0; i < 3; ++i)
52 for (
size_t j = 0; j < 3; ++j)
61 int aNRows = iNMatches * 2;
62 _Amat =
new double*[aNRows];
63 for(
int aRowIter = 0; aRowIter < aNRows; ++aRowIter)
68 _Bvec =
new double[aNRows];
69 _Rvec =
new double[aNRows];
81 for(
int aRowIter = 0; aRowIter < 2 *
_nMatches; ++aRowIter)
83 delete[]
_Amat[aRowIter];
112 for (
size_t i = 0; i < iMatches.size(); ++i)
117 _v1x += aMatchIt->_img1_x;
118 _v1y += aMatchIt->_img1_y;
119 _v2x += aMatchIt->_img2_x;
120 _v2y += aMatchIt->_img2_y;
123 _v1x /= (double)iMatches.size();
124 _v1y /= (double)iMatches.size();
125 _v2x /= (double)iMatches.size();
126 _v2y /= (double)iMatches.size();
132 o << H.
_H[0][0] <<
"\t" << H.
_H[0][1] <<
"\t" << H.
_H[0][2] << std::endl
133 << H.
_H[1][0] <<
"\t" << H.
_H[1][1] <<
"\t" << H.
_H[1][2] << std::endl
134 << H.
_H[2][0] <<
"\t" << H.
_H[2][1] <<
"\t" << H.
_H[2][2] << std::endl;
141 size_t aRow = iIndex * 2;
150 _Amat[aRow][3] = - aI1x;
151 _Amat[aRow][4] = - aI1y;
153 _Amat[aRow][6] = aI1x * aI2y;
154 _Amat[aRow][7] = aI1y * aI2y;
160 _Amat[aRow][0] = aI1x;
161 _Amat[aRow][1] = aI1y;
166 _Amat[aRow][6] = - aI1x * aI2x;
167 _Amat[aRow][7] = - aI1y * aI2x;
169 _Bvec[aRow] = - aI2x;
174 double aX = iX -
_v1x;
175 double aY = iY -
_v1y;
176 double aK = double(1. / (
_H[2][0] * aX +
_H[2][1] * aY +
_H[2][2]));
178 oX = aK * (
_H[0][0] * aX +
_H[0][1] * aY +
_H[0][2]) +
_v2x;
179 oY = aK * (
_H[1][0] * aX +
_H[1][1] * aY +
_H[1][2]) +
_v2y;
185 if (iMatches.size() < 4)
206 for (
size_t aFillRow = 0; aFillRow < iMatches.size(); ++aFillRow)
208 addMatch(aFillRow, *(iMatches[aFillRow]));
254 bool Givens(
double** C,
double* d,
double* x,
double* r,
int N,
int n,
int want_r)
257 double w, gamma,
sigma, rho, temp;
258 double epsilon = DBL_EPSILON;
266 for (j = 0; j < n; j++)
268 for (i = j + 1; i < N; i++)
272 if (fabs(C[j][j]) < epsilon * fabs(C[i][j]))
282 w =
fsign(C[j][j]) * sqrt(C[j][j] * C[j][j] + C[i][j] * C[i][j]);
288 sigma = -C[i][j] / w;
289 rho = (fabs(sigma) < gamma) ? sigma :
fsign(sigma) / gamma;
293 for (k = j + 1; k < n; k++)
296 temp = gamma * C[j][k] - sigma * C[i][k];
297 C[i][k] = sigma * C[j][k] + gamma * C[i][k];
303 temp = gamma * d[j] - sigma * d[i];
304 d[i] = sigma * d[j] + gamma * d[i];
317 for (i = n - 1; i >= 0; i--)
322 for (k = i + 1; k < n; k++)
333 for (i = n; i < N; i++)
344 for (j = n - 1; j >= 0; j--)
346 for (i = N - 1; i >= 0; i--)
348 if ((rho = C[i][j]) == 1)
353 else if (fabs(rho) < 1)
356 gamma = sqrt(1 - sigma * sigma);
360 gamma = 1 / fabs(rho);
361 sigma =
fsign(rho) * sqrt(1 - gamma * gamma);
363 temp = gamma * r[j] + sigma * r[i];
364 r[i] = -sigma * r[j] + gamma * r[i];
std::vector< PointMatchPtr > PointMatchVector_t
void initMatchesNormalization(PointMatchVector_t &iMatches)
void transformPoint(double iX, double iY, double &oX, double &oY)
void addMatch(size_t iIndex, PointMatch &iMatch)
bool Givens(double **C, double *d, double *x, double *r, int N, int n, int want_r)
void allocMemory(int iNPoints)
std::ostream & operator<<(std::ostream &o, const Homography &H)
bool estimate(PointMatchVector_t &iMatches)
std::shared_ptr< PointMatch > PointMatchPtr