feat: target rectify service pour perfectionner la prise de photo avec detection
This commit is contained in:
@@ -49,7 +49,7 @@ class DetectedObject2D {
|
||||
class ObjectDetectionService {
|
||||
ObjectDetector? _detector;
|
||||
final StreamController<List<DetectedObject2D>> _controller =
|
||||
StreamController<List<DetectedObject2D>>.broadcast();
|
||||
StreamController<List<DetectedObject2D>>.broadcast();
|
||||
|
||||
bool _isBusy = false;
|
||||
bool _started = false;
|
||||
@@ -61,22 +61,22 @@ class ObjectDetectionService {
|
||||
_started = true;
|
||||
|
||||
// Mode STREAM : optimisé pour le flux vidéo temps réel.
|
||||
// classifyObjects: true => on récupère un label grossier + confiance.
|
||||
// multipleObjects: false => on suit l'objet principal (plus stable).
|
||||
// classifyObjects: true => label grossier + confiance par objet.
|
||||
// multipleObjects: true => on détecte et encadre TOUS les objets visibles.
|
||||
final options = ObjectDetectorOptions(
|
||||
mode: DetectionMode.stream,
|
||||
classifyObjects: true,
|
||||
multipleObjects: false,
|
||||
multipleObjects: true,
|
||||
);
|
||||
_detector = ObjectDetector(options: options);
|
||||
}
|
||||
|
||||
/// À appeler depuis `startImageStream`.
|
||||
Future<void> processCameraImage(
|
||||
CameraImage image,
|
||||
CameraDescription camera,
|
||||
DeviceOrientation deviceOrientation,
|
||||
) async {
|
||||
CameraImage image,
|
||||
CameraDescription camera,
|
||||
DeviceOrientation deviceOrientation,
|
||||
) async {
|
||||
if (!_started || _detector == null) return;
|
||||
if (_isBusy) return; // On saute la frame si la précédente n'est pas finie
|
||||
_isBusy = true;
|
||||
@@ -99,7 +99,7 @@ class ObjectDetectionService {
|
||||
double conf = 0;
|
||||
if (o.labels.isNotEmpty) {
|
||||
final best = o.labels.reduce(
|
||||
(a, b) => a.confidence >= b.confidence ? a : b,
|
||||
(a, b) => a.confidence >= b.confidence ? a : b,
|
||||
);
|
||||
label = best.text;
|
||||
conf = best.confidence;
|
||||
@@ -124,10 +124,10 @@ class ObjectDetectionService {
|
||||
|
||||
/// Convertit une CameraImage en InputImage ML Kit.
|
||||
InputImage? _toInputImage(
|
||||
CameraImage image,
|
||||
CameraDescription camera,
|
||||
DeviceOrientation deviceOrientation,
|
||||
) {
|
||||
CameraImage image,
|
||||
CameraDescription camera,
|
||||
DeviceOrientation deviceOrientation,
|
||||
) {
|
||||
// Rotation : combine l'orientation du capteur et celle de l'appareil.
|
||||
final sensorOrientation = camera.sensorOrientation;
|
||||
InputImageRotation? rotation;
|
||||
@@ -183,4 +183,4 @@ class ObjectDetectionService {
|
||||
_detector = null;
|
||||
_controller.close();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user