désactivation de l'auto analyse au chargement de l'écran d'analyse

This commit is contained in:
2026-01-31 20:55:28 +01:00
parent 972474750f
commit 9ccb149dda
3 changed files with 634 additions and 430 deletions

3
devtools_options.yaml Normal file
View File

@@ -0,0 +1,3 @@
description: This file stores settings for Dart & Flutter DevTools.
documentation: https://docs.flutter.dev/tools/devtools/extensions#configure-extension-enablement-states
extensions:

View File

@@ -34,11 +34,11 @@ class AnalysisProvider extends ChangeNotifier {
required GroupingAnalyzerService groupingAnalyzerService, required GroupingAnalyzerService groupingAnalyzerService,
required SessionRepository sessionRepository, required SessionRepository sessionRepository,
DistortionCorrectionService? distortionService, DistortionCorrectionService? distortionService,
}) : _detectionService = detectionService, }) : _detectionService = detectionService,
_scoreCalculatorService = scoreCalculatorService, _scoreCalculatorService = scoreCalculatorService,
_groupingAnalyzerService = groupingAnalyzerService, _groupingAnalyzerService = groupingAnalyzerService,
_sessionRepository = sessionRepository, _sessionRepository = sessionRepository,
_distortionService = distortionService ?? DistortionCorrectionService(); _distortionService = distortionService ?? DistortionCorrectionService();
AnalysisState _state = AnalysisState.initial; AnalysisState _state = AnalysisState.initial;
String? _errorMessage; String? _errorMessage;
@@ -80,7 +80,8 @@ class AnalysisProvider extends ChangeNotifier {
double get targetCenterY => _targetCenterY; double get targetCenterY => _targetCenterY;
double get targetRadius => _targetRadius; double get targetRadius => _targetRadius;
int get ringCount => _ringCount; int get ringCount => _ringCount;
List<double>? get ringRadii => _ringRadii != null ? List.unmodifiable(_ringRadii!) : null; List<double>? get ringRadii =>
_ringRadii != null ? List.unmodifiable(_ringRadii!) : null;
double get imageAspectRatio => _imageAspectRatio; double get imageAspectRatio => _imageAspectRatio;
List<Shot> get shots => List.unmodifiable(_shots); List<Shot> get shots => List.unmodifiable(_shots);
ScoreResult? get scoreResult => _scoreResult; ScoreResult? get scoreResult => _scoreResult;
@@ -97,13 +98,22 @@ class AnalysisProvider extends ChangeNotifier {
DistortionParameters? get distortionParams => _distortionParams; DistortionParameters? get distortionParams => _distortionParams;
String? get correctedImagePath => _correctedImagePath; String? get correctedImagePath => _correctedImagePath;
bool get hasDistortion => _distortionParams?.needsCorrection ?? false; bool get hasDistortion => _distortionParams?.needsCorrection ?? false;
/// Retourne le chemin de l'image à afficher (corrigée si activée, originale sinon) /// Retourne le chemin de l'image à afficher (corrigée si activée, originale sinon)
String? get displayImagePath => _distortionCorrectionEnabled && _correctedImagePath != null String? get displayImagePath =>
_distortionCorrectionEnabled && _correctedImagePath != null
? _correctedImagePath ? _correctedImagePath
: _imagePath; : _imagePath;
/// Analyze an image /// Analyze an image
Future<void> analyzeImage(String imagePath, TargetType targetType) async { ///
/// [autoAnalyze] determines if we should run automatic detection immediately.
/// If false, only the image is loaded and default target parameters are set.
Future<void> analyzeImage(
String imagePath,
TargetType targetType, {
bool autoAnalyze = true,
}) async {
_state = AnalysisState.loading; _state = AnalysisState.loading;
_imagePath = imagePath; _imagePath = imagePath;
_targetType = targetType; _targetType = targetType;
@@ -119,6 +129,20 @@ class AnalysisProvider extends ChangeNotifier {
_imageAspectRatio = frame.image.width / frame.image.height; _imageAspectRatio = frame.image.width / frame.image.height;
frame.image.dispose(); frame.image.dispose();
if (!autoAnalyze) {
// Just setup default values without running detection
_targetCenterX = 0.5;
_targetCenterY = 0.5;
_targetRadius = 0.4;
// Initialize empty shots list
_shots = [];
_state = AnalysisState.success;
notifyListeners();
return;
}
// Detect target and impacts // Detect target and impacts
final result = _detectionService.detectTarget(imagePath, targetType); final result = _detectionService.detectTarget(imagePath, targetType);
@@ -162,13 +186,7 @@ class AnalysisProvider extends ChangeNotifier {
/// Add a manual shot /// Add a manual shot
void addShot(double x, double y) { void addShot(double x, double y) {
final score = _calculateShotScore(x, y); final score = _calculateShotScore(x, y);
final shot = Shot( final shot = Shot(id: _uuid.v4(), x: x, y: y, score: score, sessionId: '');
id: _uuid.v4(),
x: x,
y: y,
score: score,
sessionId: '',
);
_shots.add(shot); _shots.add(shot);
_recalculateScores(); _recalculateScores();
@@ -190,11 +208,7 @@ class AnalysisProvider extends ChangeNotifier {
if (index == -1) return; if (index == -1) return;
final newScore = _calculateShotScore(newX, newY); final newScore = _calculateShotScore(newX, newY);
_shots[index] = _shots[index].copyWith( _shots[index] = _shots[index].copyWith(x: newX, y: newY, score: newScore);
x: newX,
y: newY,
score: newScore,
);
_recalculateScores(); _recalculateScores();
_recalculateGrouping(); _recalculateGrouping();
@@ -334,7 +348,9 @@ class AnalysisProvider extends ChangeNotifier {
double tolerance = 2.0, double tolerance = 2.0,
bool clearExisting = false, bool clearExisting = false,
}) async { }) async {
if (_imagePath == null || _targetType == null || _referenceImpacts.length < 2) { if (_imagePath == null ||
_targetType == null ||
_referenceImpacts.length < 2) {
return 0; return 0;
} }
@@ -343,16 +359,17 @@ class AnalysisProvider extends ChangeNotifier {
.map((shot) => ReferenceImpact(x: shot.x, y: shot.y)) .map((shot) => ReferenceImpact(x: shot.x, y: shot.y))
.toList(); .toList();
final detectedImpacts = _detectionService.detectImpactsWithOpenCVFromReferences( final detectedImpacts = _detectionService
_imagePath!, .detectImpactsWithOpenCVFromReferences(
_targetType!, _imagePath!,
_targetCenterX, _targetType!,
_targetCenterY, _targetCenterX,
_targetRadius, _targetCenterY,
_ringCount, _targetRadius,
references, _ringCount,
tolerance: tolerance, references,
); tolerance: tolerance,
);
if (clearExisting) { if (clearExisting) {
_shots.clear(); _shots.clear();
@@ -381,13 +398,7 @@ class AnalysisProvider extends ChangeNotifier {
/// Add a reference impact for calibrated detection /// Add a reference impact for calibrated detection
void addReferenceImpact(double x, double y) { void addReferenceImpact(double x, double y) {
final score = _calculateShotScore(x, y); final score = _calculateShotScore(x, y);
final shot = Shot( final shot = Shot(id: _uuid.v4(), x: x, y: y, score: score, sessionId: '');
id: _uuid.v4(),
x: x,
y: y,
score: score,
sessionId: '',
);
_referenceImpacts.add(shot); _referenceImpacts.add(shot);
notifyListeners(); notifyListeners();
} }
@@ -428,7 +439,9 @@ class AnalysisProvider extends ChangeNotifier {
double tolerance = 2.0, double tolerance = 2.0,
bool clearExisting = false, bool clearExisting = false,
}) async { }) async {
if (_imagePath == null || _targetType == null || _learnedCharacteristics == null) { if (_imagePath == null ||
_targetType == null ||
_learnedCharacteristics == null) {
return 0; return 0;
} }
@@ -468,7 +481,13 @@ class AnalysisProvider extends ChangeNotifier {
} }
/// Adjust target position /// Adjust target position
void adjustTargetPosition(double centerX, double centerY, double radius, {int? ringCount, List<double>? ringRadii}) { void adjustTargetPosition(
double centerX,
double centerY,
double radius, {
int? ringCount,
List<double>? ringRadii,
}) {
_targetCenterX = centerX; _targetCenterX = centerX;
_targetCenterY = centerY; _targetCenterY = centerY;
_targetRadius = radius; _targetRadius = radius;
@@ -529,8 +548,7 @@ class AnalysisProvider extends ChangeNotifier {
} }
} }
/* version deux a tester*/
/* version deux a tester*/
/// Calcule ET applique la correction pour un feedback immédiat /// Calcule ET applique la correction pour un feedback immédiat
Future<void> calculateAndApplyDistortion() async { Future<void> calculateAndApplyDistortion() async {
// 1. Calcul des paramètres (votre code actuel) // 1. Calcul des paramètres (votre code actuel)
@@ -566,7 +584,7 @@ class AnalysisProvider extends ChangeNotifier {
notifyListeners(); notifyListeners();
} }
} }
/* fin section deux a tester*/ /* fin section deux a tester*/
int _calculateShotScore(double x, double y) { int _calculateShotScore(double x, double y) {
if (_targetType == TargetType.concentric) { if (_targetType == TargetType.concentric) {

File diff suppressed because it is too large Load Diff