Last active
June 11, 2019 22:30
-
-
Save jamesonthecrow/f71f65e8d383bb9f715b0a15e6a42acc to your computer and use it in GitHub Desktop.
Pet Segmentation iOS View Controller with Fritz (www.fritz.ai)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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