fix: opacity 80% for impacts + lower quality for pics + removing slowly zoom if you back go back

This commit is contained in:
qguillaume
2026-06-08 22:00:34 +02:00
parent f0b15941cf
commit 9afe3c8508
4 changed files with 92 additions and 14 deletions

View File

@@ -244,7 +244,8 @@ class _CaptureScreenState extends State<CaptureScreen>
return;
}
await File(tempPath).writeAsBytes(img.encodeJpg(converted, quality: 60));
// PERF : qualité 50 pour la frame d'analyse temps réel (jetable)
await File(tempPath).writeAsBytes(img.encodeJpg(converted, quality: 50));
final result = await _opencvService.detectTarget(tempPath);
@@ -735,7 +736,7 @@ class _CaptureScreenState extends State<CaptureScreen>
}
// ─────────────────────────────────────────────────────────────────────────
// Capture manuelle (inchangée, sauf ajout stop IMU)
// Capture manuelle (MODIFIÉE : ajout dégradation post-capture pour perf)
// ─────────────────────────────────────────────────────────────────────────
Future<void> _takePictureManually() async {
if (_cameraController == null || !_cameraController!.value.isInitialized) {
@@ -784,6 +785,15 @@ class _CaptureScreenState extends State<CaptureScreen>
finalPath = photo.path; // on garde la photo originale en secours
}
// PERF : on dégrade fortement la photo juste après la capture.
// Une résolution réduite suffit pour la calibration et le plotting,
// et accélère nettement le décodage à chaque écran (chargement plotting).
try {
finalPath = await _downscaleForPipeline(finalPath);
} catch (e) {
debugPrint('Downscale ignoré: $e');
}
setState(() {
_selectedImagePath = finalPath;
_showLiveCamera = false;
@@ -797,6 +807,38 @@ class _CaptureScreenState extends State<CaptureScreen>
}
}
/// Réduit fortement la résolution de la photo pour accélérer tous les
/// écrans suivants (crop, calibration, plotting). 1080 px de côté max
/// + JPEG qualité 70 : largement suffisant pour la détection visuelle.
///
/// Baisser `maxSide` (ex. 900) ou `quality` (ex. 60) rend le chargement
/// encore plus rapide au prix d'un peu de finesse à l'écran.
Future<String> _downscaleForPipeline(String sourcePath) async {
final bytes = await File(sourcePath).readAsBytes();
final decoded = img.decodeImage(bytes);
if (decoded == null) return sourcePath;
const int maxSide = 1080;
final int longest = math.max(decoded.width, decoded.height);
if (longest <= maxSide) {
return sourcePath; // déjà assez petite, rien à faire
}
final double ratio = maxSide / longest;
final resized = img.copyResize(
decoded,
width: (decoded.width * ratio).round(),
height: (decoded.height * ratio).round(),
interpolation: img.Interpolation.linear, // rapide
);
final tempDir = await getTemporaryDirectory();
final outPath =
'${tempDir.path}/downscaled_${DateTime.now().millisecondsSinceEpoch}.jpg';
await File(outPath).writeAsBytes(img.encodeJpg(resized, quality: 70));
return outPath;
}
// ─────────────────────────────────────────────────────────────────────────
// Helpers UI (inchangés)
// ─────────────────────────────────────────────────────────────────────────
@@ -861,9 +903,10 @@ class _CaptureScreenState extends State<CaptureScreen>
try {
final XFile? image = await _picker.pickImage(
source: ImageSource.gallery,
maxWidth: 2048,
maxHeight: 2048,
imageQuality: 90,
// PERF : limite d'import plus agressive pour accélérer le pipeline
maxWidth: 1280,
maxHeight: 1280,
imageQuality: 75,
);
if (image != null) {
setState(() {