Skip to content

Instantly share code, notes, and snippets.

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 ivanherreragl/95425393cd5acf74cc047e17f5b012a9 to your computer and use it in GitHub Desktop.
Save ivanherreragl/95425393cd5acf74cc047e17f5b012a9 to your computer and use it in GitHub Desktop.
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)
}
}
}
@biranchi2018
Copy link

 applyingOrientation is deprecated now.
    inputImage = ciImage.applyingOrientation(Int32(orientation.rawValue))

Use the below code:
inputImage = ciImage.oriented(forExifOrientation: Int32(orientation.rawValue))

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment