webClassificationResult function

ClassificationResult webClassificationResult(
  1. Map<Object?, Object?> result
)

Converts a JSON-like MediaPipe web classification result.

Implementation

ClassificationResult webClassificationResult(Map<Object?, Object?> result) {
  final List<Object?> heads = result['classifications']! as List<Object?>;
  return ClassificationResult(
    timestampMs: webOptionalInt(result['timestampMs']),
    classifications: heads.map((Object? value) {
      final Map<Object?, Object?> head = value! as Map<Object?, Object?>;
      final List<Object?> categories = head['categories']! as List<Object?>;
      return Classifications(
        headIndex: (head['headIndex']! as num).toInt(),
        headName: webEmptyToNull(head['headName'] as String?),
        categories: categories.map((Object? categoryValue) {
          final Map<Object?, Object?> category = categoryValue! as Map<Object?, Object?>;
          return Category(
            index: (category['index']! as num).toInt(),
            score: (category['score']! as num).toDouble(),
            categoryName: webEmptyToNull(category['categoryName'] as String?),
            displayName: webEmptyToNull(category['displayName'] as String?),
          );
        }),
      );
    }),
  );
}