Created
June 2, 2021 19:21
-
-
Save sgl0v/f87cdb6fea3220c51626f0fd3d6f8aac 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
extension ImageScanner { | |
private func postProcessImage(_ image: UIImage) -> Result<UIImage, Error> { | |
guard let ciImage = CIImage(image: image), | |
let orientation = CGImagePropertyOrientation(rawValue: UInt32(image.imageOrientation.rawValue)) else { | |
return .failure(ImageProviderError.internalError) | |
} | |
let inputImage = ciImage.oriented(forExifOrientation: Int32(orientation.rawValue)) | |
return detectRectangle(on: ciImage, orientation: orientation).flatMap {detectedRectangle in // ➊ | |
self.cropImage(inputImage, with: detectedRectangle) // ➋ | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment