a bunch of flutter updates
This commit is contained in:
@@ -0,0 +1,2 @@
|
||||
export 'obstacle_analyzer.dart';
|
||||
export 'yolo_detector.dart';
|
||||
@@ -0,0 +1,37 @@
|
||||
enum ObstacleDirection { left, center, right }
|
||||
|
||||
class DetectionResult {
|
||||
final String label;
|
||||
final double confidence;
|
||||
final ObstacleDirection direction;
|
||||
final String estimatedDistance;
|
||||
|
||||
const DetectionResult({
|
||||
required this.label,
|
||||
required this.confidence,
|
||||
required this.direction,
|
||||
required this.estimatedDistance,
|
||||
});
|
||||
|
||||
String get directionName => direction.name.toUpperCase();
|
||||
|
||||
String get spokenId {
|
||||
final area = switch (direction) {
|
||||
ObstacleDirection.left => 'kiri',
|
||||
ObstacleDirection.center => 'tengah',
|
||||
ObstacleDirection.right => 'kanan',
|
||||
};
|
||||
return 'Hati-hati, $label di $area. Jarak $estimatedDistance.';
|
||||
}
|
||||
}
|
||||
|
||||
class ObstacleAnalyzer {
|
||||
DetectionResult analyzeFallback({String label = 'person', double confidence = 0.86}) {
|
||||
return DetectionResult(
|
||||
label: label,
|
||||
confidence: confidence,
|
||||
direction: ObstacleDirection.center,
|
||||
estimatedDistance: 'Close',
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,47 @@
|
||||
import 'package:flutter/foundation.dart';
|
||||
import 'package:flutter/services.dart';
|
||||
|
||||
import '../constants/app_constants.dart';
|
||||
import 'obstacle_analyzer.dart';
|
||||
|
||||
class YoloDetector {
|
||||
final ObstacleAnalyzer _analyzer;
|
||||
List<String> _labels = const [];
|
||||
bool _ready = false;
|
||||
|
||||
YoloDetector(this._analyzer);
|
||||
|
||||
bool get isReady => _ready;
|
||||
|
||||
Future<void> init() async {
|
||||
try {
|
||||
_labels = (await rootBundle.loadString(AppConstants.yoloLabelsPath))
|
||||
.split('\n')
|
||||
.map((e) => e.trim())
|
||||
.where((e) => e.isNotEmpty)
|
||||
.toList();
|
||||
if (kIsWeb) {
|
||||
_ready = false;
|
||||
return;
|
||||
}
|
||||
await rootBundle.load(await AppConstants.getSelectedYoloModelPath());
|
||||
_ready = true;
|
||||
} catch (e) {
|
||||
debugPrint('YOLO fallback mode: $e');
|
||||
_ready = false;
|
||||
}
|
||||
}
|
||||
|
||||
Future<DetectionResult?> detectFallback() async {
|
||||
if (_ready) {
|
||||
// Full tensor pre/post-processing belongs here once yolov8n.tflite is present.
|
||||
// The app keeps a deterministic fallback so demo flows remain testable.
|
||||
}
|
||||
final label = _labels.isNotEmpty ? _labels.first : 'person';
|
||||
return _analyzer.analyzeFallback(label: label);
|
||||
}
|
||||
|
||||
void dispose() {
|
||||
_ready = false;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user