MediaPipeTasksVision Framework Reference

ImageSegmenter

final class ImageSegmenter

Segments images, video frames, or live camera streams with a TFLite model that has metadata (region-of-interest is unsupported).

  • Creates an image segmenter in .image mode from a local model file path.

    Declaration

    Swift

    convenience init(modelPath: String) throws
  • Creates an image segmenter and initializes the underlying MediaPipe task graph.

    Declaration

    Swift

    init(options: ImageSegmenterOptions) throws
  • Category labels from the model metadata, indexed by category mask value and confidence mask position, or empty if the model has no label map.

    Declaration

    Swift

    final let labels: [String]
  • Segments a single image in .image running mode.

    Declaration

    Swift

    final func segment(image: MPImage, imageProcessingOptions: ImageProcessingOptions? = nil) throws -> ImageSegmenterResult
  • Segments a decoded video frame at monotonically increasing timestampInMilliseconds in .video running mode.

    Declaration

    Swift

    final func segment(videoFrame: MPImage, timestampInMilliseconds: Int, imageProcessingOptions: ImageProcessingOptions? = nil) throws -> ImageSegmenterResult
  • Sends a live-stream frame at monotonically increasing timestampInMilliseconds for asynchronous segmentation in .liveStream running mode.

    Results are delivered to ImageSegmenterOptions.liveStreamResultHandler.

    Declaration

    Swift

    final func segmentAsync(image: MPImage, timestampInMilliseconds: Int, imageProcessingOptions: ImageProcessingOptions? = nil) throws