test opecv échoué

This commit is contained in:
2026-01-27 22:20:53 +01:00
parent f1a8eefdc3
commit 334332bc78
9 changed files with 827 additions and 105 deletions

View File

@@ -402,13 +402,64 @@ class DistortionCorrectionService {
return h;
}
/// Résout le système linéaire pour trouver la matrice d'homographie 3x3.
/// Utilise l'élimination de Gauss-Jordan avec pivot partiel pour la stabilité.
List<double> _solveHomography(List<List<double>> a) {
// Implémentation simplifiée - normalisation et résolution
// En pratique, on devrait utiliser une vraie décomposition SVD
// Le système 'a' est de taille 8x9 (8 équations, 9 inconnues).
// On fixe h8 = 1.0 pour résoudre le système, ce qui nous donne un système 8x8.
final int n = 8;
final List<List<double>> matrix = List.generate(n, (i) => List<double>.from(a[i]));
// Vecteur B (les constantes de l'autre côté de l'égalité)
// Dans DLT, -h8 * dx (ou dy) devient le terme constant.
final List<double> b = List.generate(n, (i) => -matrix[i][8]);
// Pour l'instant, retourner une matrice identité
// TODO: Implémenter une vraie résolution
return [1, 0, 0, 0, 1, 0, 0, 0, 1];
// Élimination de Gauss-Jordan
for (int i = 0; i < n; i++) {
// Recherche du pivot (valeur maximale dans la colonne pour limiter les erreurs)
int pivot = i;
for (int j = i + 1; j < n; j++) {
if (matrix[j][i].abs() > matrix[pivot][i].abs()) {
pivot = j;
}
}
// Échange des lignes (si nécessaire)
final List<double> tempRow = matrix[i];
matrix[i] = matrix[pivot];
matrix[pivot] = tempRow;
final double tempB = b[i];
b[i] = b[pivot];
b[pivot] = tempB;
// Vérification de la singularité (division par zéro impossible)
if (matrix[i][i].abs() < 1e-10) {
return [1, 0, 0, 0, 1, 0, 0, 0, 1]; // Retourne identité si échec
}
// Normalisation de la ligne pivot
for (int j = i + 1; j < n; j++) {
final double factor = matrix[j][i] / matrix[i][i];
b[j] -= factor * b[i];
for (int k = i; k < n; k++) {
matrix[j][k] -= factor * matrix[i][k];
}
}
}
// Substitution arrière
final List<double> h = List.filled(9, 0.0);
for (int i = n - 1; i >= 0; i--) {
double sum = 0.0;
for (int j = i + 1; j < n; j++) {
sum += matrix[i][j] * h[j];
}
h[i] = (b[i] - sum) / matrix[i][i];
}
h[8] = 1.0; // Normalisation finale
return h;
}
({double x, double y}) _applyPerspectiveTransform(List<double> h, double x, double y) {