import UIKit
import MLImageSegmentationLibrary
class ViewController: UIViewController {
var options:MLImageSegmentationSetting?
var analyzer:MLImageSegmentationAnalyzer?
@IBOutlet weak var resultImageView: UIImageView!
@IBOutlet weak var btnRemoveBackground: UIButton!
override func viewDidLoad() {
super.viewDidLoad()
setRemoverSettings()
initAnalyser()
setActions()
}
func setActions(){
btnRemoveBackground.addTarget(self, action: #selector(removeBackground), for: .touchUpInside)
}
func initAnalyser() {
analyzer = MLImageSegmentationAnalyzer.sharedInstance()
analyzer?.setImageSegmentationAnalyzer(options!)
}
func setRemoverSettings(){
options = MLImageSegmentationSetting.init()
options?.exact = true
options?.analyzerType = MLImageSegmentationAnalyzerType.body
options?.scene = MLImageSegmentationScene.all
}
@objc func removeBackground() {
let frame = MLFrame(image: UIImage(named: "deneme")!)
analyzer?.asyncAnalyse(frame) { (res) in
self.resultImageView.image = nil
self.resultImageView.image = res.getForeground()
self.analyzer?.stop()
} addOnFailureListener: { (errorCode, errorStr) in
print("ErrorCode: ", errorCode, "error: ", errorStr)
self.analyzer?.stop()
}
}
}
-
Notifications
You must be signed in to change notification settings - Fork 1
License
AsynctaskCoffee/BackgroundRemove-HMS-Core-Swift
Folders and files
Name | Name | Last commit message | Last commit date | |
---|---|---|---|---|
Repository files navigation
About
No description, website, or topics provided.
Resources
License
Stars
Watchers
Forks
Releases
No releases published
Packages 0
No packages published