Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Pet Segmentation iOS View Controller with Fritz (www.fritz.ai)
class ViewController: UIViewController, UIImagePickerControllerDelegate,
UINavigationControllerDelegate {
/// The rest of the view controller...
/// Scores output from model greater than this value will be set as 1.
/// Lowering this value will make the mask more intense for lower confidence values.
var clippingScoresAbove: Double { return 0.6 }
/// Values lower than this value will not appear in the mask.
var zeroingScoresBelow: Double { return 0.4 }
private lazy var visionModel = FritzVisionPetSegmentationModel()
/// The rest of the view controller...
@objc func imagePickerController(_ picker: UIImagePickerController!, didFinishPickingImage image: UIImage!, editingInfo: NSDictionary!){
self.dismiss(animated: true, completion: { () -> Void in
})
createSticker(image)
}
func createSticker(_ uiImage: UIImage) {
guard let result = try? visionModel.predict(FritzVisionImage(image: uiImage)),
let mask = result.buildSingleClassMask(
forClass: FritzVisionPetClass.pet,
clippingScoresAbove: clippingScoresAbove,
zeroingScoresBelow: zeroingScoresBelow
)
else { return }
let petSticker = fritzImage.masked(withAlphaMask: mask)
DispatchQueue.main.async {
self.imageView.image = petSticker
}
}
}
@hsiaoer

This comment has been minimized.

Copy link

commented Jul 26, 2019

Line 31-45 can remove and replace with this

   let petSticker = fritzImage.masked(withAlphaMask: mask)

    DispatchQueue.main.async {
      self.imageView.image = petSticker
    }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.