toMap method

Map<String, dynamic> toMap()

Convert this YOLOResult to a map (used for platform channel communication)

Implementation

Map<String, dynamic> toMap() {
  final map = <String, dynamic>{
    'classIndex': classIndex,
    'className': className,
    'confidence': confidence,
    'boundingBox': {
      'left': boundingBox.left,
      'top': boundingBox.top,
      'right': boundingBox.right,
      'bottom': boundingBox.bottom,
    },
    'normalizedBox': {
      'left': normalizedBox.left,
      'top': normalizedBox.top,
      'right': normalizedBox.right,
      'bottom': normalizedBox.bottom,
    },
  };

  if (mask != null) {
    map['mask'] = mask;
  }

  if (keypoints != null && keypointConfidences != null) {
    final keypointsData = <double>[];
    for (var i = 0; i < keypoints!.length; i++) {
      keypointsData.add(keypoints![i].x);
      keypointsData.add(keypoints![i].y);
      keypointsData.add(keypointConfidences![i]);
    }
    map['keypoints'] = keypointsData;
  }

  return map;
}