Skip to content

Instantly share code, notes, and snippets.

@jamesonthecrow
Last active June 11, 2019 22:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jamesonthecrow/f71f65e8d383bb9f715b0a15e6a42acc to your computer and use it in GitHub Desktop.
Save jamesonthecrow/f71f65e8d383bb9f715b0a15e6a42acc to your computer and use it in GitHub Desktop.
Pet Segmentation iOS View Controller with Fritz (www.fritz.ai)
import UIKit
import AVFoundation
import Fritz
class ViewController: UIViewController, UIImagePickerControllerDelegate,
UINavigationControllerDelegate {
@IBOutlet var imageView: UIImageView!
var maskView: UIImageView!
var backgroundView: UIImageView!
let context = CIContext()
override func viewDidLoad() {
super.viewDidLoad()
openPhotoLibrary()
backgroundView = UIImageView(frame: view.bounds)
backgroundView.backgroundColor = .red
view.addSubview(backgroundView)
imageView = UIImageView(frame: view.bounds)
imageView.contentMode = .scaleAspectFit
view.addSubview(imageView)
}
override func viewDidAppear(_ animated: Bool) {
super.viewDidAppear(animated)
}
func openPhotoLibrary() {
if UIImagePickerController.isSourceTypeAvailable(.photoLibrary) {
let imagePicker = UIImagePickerController()
imagePicker.delegate = self
imagePicker.sourceType = .photoLibrary
imagePicker.allowsEditing = true
self.present(imagePicker, animated: true, completion: nil)
}
}
@objc func imagePickerController(_ picker: UIImagePickerController!, didFinishPickingImage image: UIImage!, editingInfo: NSDictionary!){
self.dismiss(animated: true, completion: { () -> Void in
})
self.imageView.image = image
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment