Dr-Swopt 1 неделя назад
Родитель
Сommit
25926af9ea
1 измененных файлов с 16 добавлено и 5 удалено
  1. 16 5
      palm_oil_mobile/lib/screens/live_analysis_screen.dart

+ 16 - 5
palm_oil_mobile/lib/screens/live_analysis_screen.dart

@@ -28,8 +28,11 @@ class _LiveAnalysisScreenState extends State<LiveAnalysisScreen> {
   
   
   // Detection Lock Logic
   // Detection Lock Logic
   bool _isLocked = false;
   bool _isLocked = false;
-  static const double _lockThreshold = 0.75;
-  static const int _frameThrottle = 10; // Process every 10th frame
+  static const double _lockThreshold = 0.60;
+  static const int _frameThrottle = 2; // Check frames more frequently
+  
+  int _consecutiveDetections = 0;
+  static const int _requiredConsecutive = 3; // Number of frames to hold
 
 
   @override
   @override
   void initState() {
   void initState() {
@@ -78,15 +81,23 @@ class _LiveAnalysisScreenState extends State<LiveAnalysisScreen> {
     try {
     try {
       final detections = await _tfliteService.runInferenceOnStream(image);
       final detections = await _tfliteService.runInferenceOnStream(image);
       
       
-      bool locked = false;
+      bool currentFrameHasFruit = false;
       if (detections.isNotEmpty) {
       if (detections.isNotEmpty) {
-        locked = detections.any((d) => d.confidence > _lockThreshold);
+        currentFrameHasFruit = detections.any((d) => d.confidence > _lockThreshold);
       }
       }
 
 
+      if (currentFrameHasFruit) {
+        _consecutiveDetections++;
+      } else {
+        _consecutiveDetections--; // Just drop by one, don't kill the whole lock
+      }
+      
+      _consecutiveDetections = _consecutiveDetections.clamp(0, _requiredConsecutive);
+
       if (mounted) {
       if (mounted) {
         setState(() {
         setState(() {
           _detections = detections;
           _detections = detections;
-          _isLocked = locked;
+          _isLocked = _consecutiveDetections >= _requiredConsecutive;
         });
         });
       }
       }
     } catch (e) {
     } catch (e) {