@@ -210,10 +210,17 @@ int GDALGCPsToHomography(int nGCPCount, const GDAL_GCP *pasGCPList,
210
210
return FALSE ;
211
211
}
212
212
213
- GDALMatrix LtL (9 , 9 );
213
+ /* -------------------------------------------------------------------- */
214
+ /* Calculate the best fit homography following */
215
+ /* https://www.cs.unc.edu/~ronisen/teaching/fall_2023/pdf_slides/ */
216
+ /* lecture9_transformation.pdf */
217
+ /* Since rank(AtA) = rank(8) = 8, append an additional equation */
218
+ /* h_normalized[6] = 1 to fully define the solution. */
219
+ /* -------------------------------------------------------------------- */
220
+ GDALMatrix AtA (9 , 9 );
214
221
GDALMatrix rhs (9 , 1 );
215
222
rhs (6 , 0 ) = 1 ;
216
- LtL (6 , 6 ) = 1 ;
223
+ AtA (6 , 6 ) = 1 ;
217
224
218
225
for (int i = 0 ; i < nGCPCount; ++i)
219
226
{
@@ -227,31 +234,31 @@ int GDALGCPsToHomography(int nGCPCount, const GDAL_GCP *pasGCPList,
227
234
return FALSE ;
228
235
}
229
236
230
- double Lx [] = {1 , pixel, line, 0 , 0 ,
237
+ double Ax [] = {1 , pixel, line, 0 , 0 ,
231
238
0 , -geox, -geox * pixel, -geox * line};
232
- double Ly [] = {0 , 0 , 0 , 1 , pixel, line, -geoy, -geoy * pixel,
239
+ double Ay [] = {0 , 0 , 0 , 1 , pixel, line, -geoy, -geoy * pixel,
233
240
-geoy * line};
234
241
int j, k;
235
- // Populate the lower triangle of symmetric LtL matrix
242
+ // Populate the lower triangle of symmetric AtA matrix
236
243
for (j = 0 ; j < 9 ; j++)
237
244
{
238
245
for (k = j; k < 9 ; k++)
239
246
{
240
- LtL (j, k) += Lx [j] * Lx [k] + Ly [j] * Ly [k];
247
+ AtA (j, k) += Ax [j] * Ax [k] + Ay [j] * Ay [k];
241
248
}
242
249
}
243
250
}
244
- // Populate the upper triangle of symmetric LtL matrix
251
+ // Populate the upper triangle of symmetric AtA matrix
245
252
for (int j = 0 ; j < 9 ; j++)
246
253
{
247
254
for (int k = 0 ; k < j; k++)
248
255
{
249
- LtL (j, k) = LtL (k, j);
256
+ AtA (j, k) = AtA (k, j);
250
257
}
251
258
}
252
259
253
260
GDALMatrix h_normalized (9 , 1 );
254
- if (!GDALLinearSystemSolve (LtL , rhs, h_normalized))
261
+ if (!GDALLinearSystemSolve (AtA , rhs, h_normalized))
255
262
{
256
263
return FALSE ;
257
264
}
0 commit comments