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.
iOS 15.0+
Swift Package Manager:
- File > Add Package Dependencies…
- Add
https://github.com/SaladDays831/FaceSeg.git
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.
drawDebugImage
Original image with face bounding boxes, paths, and landmarks.
drawFacesImage
Image with the segmented faces on a transparent background. The location/scale of the faces is preserved.
drawCutoutFacesImage
Original image with transparent holes in place of the detected faces.
faceInBoundingBoxSize
Side length (width == height) of the images in facesInBoundingBoxes.
drawFacesInBoundingBoxes
An array of detected faces as separate images.
Running on the simulator doesn't work. This is an issue with Vision introduced with iOS 15. https://developer.apple.com/forums/thread/690605
FaceSeg is released under the MIT license. See LICENSE for details.