Created
August 2, 2017 09:53
-
-
Save ivanherreragl/95425393cd5acf74cc047e17f5b012a9 to your computer and use it in GitHub Desktop.
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 imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [String : Any]) { | |
picker.dismiss(animated: true) | |
classificationLabel.text = "Analyzing Image…" | |
correctedImageView.image = nil | |
guard let uiImage = info[UIImagePickerControllerOriginalImage] as? UIImage | |
else { fatalError("no image from image picker") } | |
guard let ciImage = CIImage(image: uiImage) | |
else { fatalError("can't create CIImage from UIImage") } | |
let orientation = CGImagePropertyOrientation(uiImage.imageOrientation) | |
inputImage = ciImage.applyingOrientation(Int32(orientation.rawValue)) | |
// Show the image in the UI. | |
imageView.image = uiImage | |
// Run the rectangle detector, which upon completion runs the ML classifier. | |
let handler = VNImageRequestHandler(ciImage: ciImage, orientation: Int32(orientation.rawValue)) | |
DispatchQueue.global(qos: .userInteractive).async { | |
do { | |
try handler.perform([self.rectanglesRequest]) | |
} catch { | |
print(error) | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Use the below code:
inputImage = ciImage.oriented(forExifOrientation: Int32(orientation.rawValue))