Skip to content

SaladDays831/FaceSeg

Repository files navigation

FaceSeg

FaceSeg is a facial segmentation package written in Swift. It uses Apple's Vision framework and its facial observations + landmarks to create different images with segmented faces.

Requirements

iOS 15.0+

Installation

Swift Package Manager:

  • File > Add Package Dependencies…
  • Add https://github.com/SaladDays831/FaceSeg.git

Usage

Create a FaceSegConfiguration with the outputs you want (everything defaults to false to save on performance — if nothing is enabled, only metadata is returned), pass it to FaceSeg, then await the result.

let config = FaceSegConfiguration(drawFacesImage: true, drawCutoutFacesImage: true)
let faceSeg = FaceSeg(configuration: config)

do {
    let result = try await faceSeg.segment(myCoolImage)
    print("Found \(result.metadata.faceCount) faces")
} catch {
    print("FaceSeg failed: \(error.localizedDescription)")
}

A working example can be found in the FaceSegDemo folder.

FaceSegConfiguration parameters

drawDebugImage
Original image with face bounding boxes, paths, and landmarks.

Debug image

drawFacesImage
Image with the segmented faces on a transparent background. The location/scale of the faces is preserved.

Faces image

drawCutoutFacesImage
Original image with transparent holes in place of the detected faces.

Cutout Faces image

faceInBoundingBoxSize
Side length (width == height) of the images in facesInBoundingBoxes.
drawFacesInBoundingBoxes
An array of detected faces as separate images.

Note ⚠️

Running on the simulator doesn't work. This is an issue with Vision introduced with iOS 15. https://developer.apple.com/forums/thread/690605

License

FaceSeg is released under the MIT license. See LICENSE for details.

About

A Swift Package for facial segmentation using Vision

Topics

Resources

License

Stars

Watchers

Forks

Packages

 
 
 

Contributors

Languages