Face.fromJson constructor

Face.fromJson(
  1. Map json
)

Returns an instance of Face from a given json.

Implementation

factory Face.fromJson(Map<dynamic, dynamic> json) => Face(
      boundingBox: RectJson.fromJson(json['rect']),
      headEulerAngleX: json['headEulerAngleX'],
      headEulerAngleY: json['headEulerAngleY'],
      headEulerAngleZ: json['headEulerAngleZ'],
      leftEyeOpenProbability: json['leftEyeOpenProbability'],
      rightEyeOpenProbability: json['rightEyeOpenProbability'],
      smilingProbability: json['smilingProbability'],
      trackingId: json['trackingId'],
      landmarks: Map<FaceLandmarkType, FaceLandmark?>.fromIterables(
          FaceLandmarkType.values,
          FaceLandmarkType.values.map((FaceLandmarkType type) {
        final List<dynamic>? pos = json['landmarks'][type.name];
        return (pos == null)
            ? null
            : FaceLandmark(
                type: type,
                position: Point<int>(pos[0].toInt(), pos[1].toInt()),
              );
      })),
      contours: Map<FaceContourType, FaceContour?>.fromIterables(
          FaceContourType.values,
          FaceContourType.values.map((FaceContourType type) {
        /// added empty map to pass the tests
        final List<dynamic>? arr =
            (json['contours'] ?? <String, dynamic>{})[type.name];
        return (arr == null)
            ? null
            : FaceContour(
                type: type,
                points: arr
                    .map<Point<int>>((dynamic pos) =>
                        Point<int>(pos[0].toInt(), pos[1].toInt()))
                    .toList(),
              );
      })),
    );