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 Vision | |
class ViewController: UIViewController, UIImagePickerControllerDelegate, UINavigationControllerDelegate { | |
@IBOutlet weak var imageView: UIImageView! | |
@IBOutlet weak var textView: UITextView! | |
var animalRecognitionRequest = VNRecognizeAnimalsRequest(completionHandler: nil) | |
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 CoreML | |
enum Animal { | |
case cat | |
case dog | |
} | |
class ViewController: UIViewController, UIImagePickerControllerDelegate, UINavigationControllerDelegate { |
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 coremltools | |
coreml_model = coremltools.converters.keras.convert('model.h5', input_names=['image'], output_names=['output'],image_input_names='image') | |
coreml_model.author = 'Anupam Chugh' | |
coreml_model.short_description = 'Cat Dog Classifier converted from a Keras model' | |
coreml_model.input_description['image'] = 'Takes as input an image' | |
coreml_model.output_description['output'] = 'Prediction as cat or dog' | |
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 Vision | |
import VisionKit | |
class ViewController: UIViewController, VNDocumentCameraViewControllerDelegate { | |
@IBOutlet weak var imageView: UIImageView! | |
@IBOutlet weak var textView: UITextView! | |
var textRecognitionRequest = VNRecognizeTextRequest(completionHandler: nil) |
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
func createVisionRequest(image: UIImage){ | |
currentImage = image | |
guard let cgImage = image.cgImage else { | |
return | |
} | |
let requestHandler = VNImageRequestHandler(cgImage: cgImage, orientation: image.cgImageOrientation, options: [:]) | |
let vnRequests = [vnTextDetectionRequest] | |
DispatchQueue.global(qos: .background).async { |
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
extension ViewController: UIImagePickerControllerDelegate, UINavigationControllerDelegate { | |
func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [UIImagePickerController.InfoKey: Any]) { | |
picker.dismiss(animated: true) | |
guard let uiImage = info[UIImagePickerController.InfoKey.originalImage] as? UIImage else { | |
fatalError("Error!") | |
} | |
imageView.image = uiImage | |
createVisionRequest(image: uiImage) |
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
guard UIImagePickerController.isSourceTypeAvailable(.camera) else { | |
presentPhotoPicker(sourceType: .photoLibrary) | |
return | |
} | |
let photoSourcePicker = UIAlertController() | |
let takePhoto = UIAlertAction(title: "Camera", style: .default) { [unowned self] _ in | |
self.presentPhotoPicker(sourceType: .camera) | |
} | |
let choosePhoto = UIAlertAction(title: "Photos Library", style: .default) { [unowned self] _ in | |
self.presentPhotoPicker(sourceType: .photoLibrary) |
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
func imageClassifier(image: UIImage, wordNumber: Int, characterNumber: Int, currentObservation : VNTextObservation){ | |
let request = VNCoreMLRequest(model: model) { [weak self] request, error in | |
guard let results = request.results as? [VNClassificationObservation], | |
let topResult = results.first else { | |
fatalError("Unexpected result type from VNCoreMLRequest") | |
} | |
let result = topResult.identifier | |
let classificationInfo: [String: Any] = ["wordNumber" : wordNumber, | |
"characterNumber" : characterNumber, | |
"class" : result] |
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
struct ContentView : View { | |
@EnvironmentObject var observer : SwipeObserver | |
var body : some View{ | |
GeometryReader{geo in | |
ZStack{ | |
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
struct ContentView: View { | |
var body: some View { | |
VStack{ | |
Label("Hello Label", systemImage: "sun.min") | |
.font(.system(.title, design: .rounded)) | |
Label("Title only label", systemImage: "sun.min") | |
.font(.system(.title, design: .rounded)) |