DoreHairSegment
Getting Started
The following instructions will guide you on how to implement the DoreHairSegment SDK on a specific platform.
IOS
Technical Specifications:
Xcode | 14.2 or Above |
IOS Version | 13.0 or Above |
Supported Device | iPhoneSE or Above |
You can implement DoreHairSegment SDK in your existing/new IOS Xcode project with in just 3 Steps
Step 1:
1. Add this line in your pod file
pod 'DoreHairSegment'
2. Run pod install, and open project
pod install
3. Cocoapod version should be 1.12.1 or above
Step 2:
Initiate DoreHairSegment Manager
private var modelManager: HairSegmentManager?
modelManager = HairSegmentManager()
//load license
let isValid:Bool = (modelManager?.init_data(licKey: "insert your license key here") ?? false)
Step 3:
Execute Segment Session with input image
//run model and get result
let inputimage:UIImage = UIImage(pixelBuffer: pixelBuffer)!
//run model and get result
let outImage:CGImage = (self.modelManager?.run_model(onFrame: inputimage))!
//preview the output image
DispatchQueue.main.async {
self.segmentView.image = ciImage
}
Hair Color Change
//get color mask (you can adjust RGBA value)
let ciImage:UIImage = getColorMask(result.semanticPredictions,R: RGBCode[0], G: RGBCode[1], B: RGBCode[2], A: 255)!
let rgbCIimage:CIImage = CIImage.init(cvPixelBuffer: pixelBuffer)
let img:UIImage = convertCItoUIimage(cmage: rgbCIimage)
//you can change BlendMode and adjust alpha value (0.1 to 1)
let outputImage:UIImage = maskblendImage(backgroundImage: img, maskImage: ciImage, maskblendMode: CGBlendMode.multiply, blendAlpha: 0.8)!
DispatchQueue.main.async {
self.maskoutView.image = outputImage
}
DoreHairSegmentLite (Lite Version SDK)
DoreHairSegmentLite is used for reducing app size, all support and library files will be downloaded at runtime (Internet connection required).
Total SDK size will be 1.2MB Max
How to use :
Step 1:
1. Add this line in your pod file
pod 'DoreHairSegmentLite'
2. Run pod install, and open project
pod install
3. Cocoapod version should be 1.12.1 or above
Step 2:
Add "HairSegmentLiteDelegate" in your view controller
class ImageSegment: UIViewController, HairSegmentLiteDelegate {
Initiate HairSegmentLiteManager
private var modelManager: HairSegmentLiteManager?
modelManager = HairSegmentLiteManager()
modelManager?.delegate = self
//Load license / start initiating
self.modelManager?.init_data(licKey: "insert your license key here")
Library file will be download at runtime when you initiate "HairSegmentLiteManager", it will be download and placed in app internal storage, you can get download completion signal through DoreHairSegmentLiteDelegate callback, use some progress indicator until download completion. this download progress will be processed only on first time, it will load with app internal storage location from second time load.
func onHairSegmentLiteSuccess(_ info: String) {
self.alertView.dismiss(animated: true, completion: nil)
//DoreHairSegment Library files downloaded successfully...! Ready to run segment
}
func onHairSegmentLiteFailure(_ error: String) {
self.alertView.dismiss(animated: true, completion: nil)
//DoreHairSegment Library files downloading failed..!
print(error)
}
func onHairSegmentLiteProgressUpdate(_ progress: String) {
//DoreHairSegment Library files downloading...!
print(progress)
self.progressView!.progress = Float(progress)!
}
func onHairSegmentLiteDownloadSpeed(_ dps: String) {
print(dps)
}
Step 3:
Execute Segment Session with input image
//run and get result
let result:segmentOut = segmentOut ( features: (self.modelManager?.run_model(onFrame: pixelBuffer))! )
//mask image Black - bacground, White - foreground
let ciImage:UIImage = getMaskBW(result.semanticPredictions)!
DispatchQueue.main.async {
self.segmentView.image = ciImage
}