YOLODetectionResults.fromMap constructor

YOLODetectionResults.fromMap(
  1. Map map
)

Creates YOLODetectionResults from a map representation.

This factory constructor deserializes results received from the platform channel. The map should contain:

  • 'detections': List of detection maps
  • 'annotatedImage': (optional) Uint8List of image data
  • 'processingTimeMs': double representing processing time

Implementation

factory YOLODetectionResults.fromMap(Map<dynamic, dynamic> map) {
  // Parse detections
  final detectionsData = map['detections'] as List<dynamic>?;
  final detections = detectionsData != null
      ? detectionsData
            .map((detection) => YOLOResult.fromMap(detection))
            .toList()
      : <YOLOResult>[];

  // Parse annotated image if available
  final annotatedImage = map['annotatedImage'] as Uint8List?;

  // Parse processing time
  final processingTimeMs = map.containsKey('processingTimeMs')
      ? (map['processingTimeMs'] as num).toDouble()
      : 0.0;

  return YOLODetectionResults(
    detections: detections,
    annotatedImage: annotatedImage,
    processingTimeMs: processingTimeMs,
  );
}