Background Removal for Images
API Interface of the iOS Framework
private var backgroundRemover = BackgroundRemover(threshold: 0.5)backgroundRemover.loadModel { error in
self.dismissPresentedViewController(animated: true) {
if error != nil {
showError(on: self, message: "Failed to initialize BG Removal model: \(error!.localizedDescription)")
}
}
}let result = self.backgroundRemover.removeBackground(fromImage: image) { mask, error in
if error != nil {
showAlert(on: self, message: "BG Model runtime failure: \(error!.localizedDescription)")
return
}
DispatchQueue.main.async {
(self.loadingViewController as! LoadingViewController).update(text: "Applying Mask...")
DispatchQueue.global().async {
self.applyMask(mask!, to: image)
}
}
}Last updated