Skip to content

Instantly share code, notes, and snippets.

@sgl0v
Created June 2, 2021 19:21
Show Gist options
  • Save sgl0v/f87cdb6fea3220c51626f0fd3d6f8aac to your computer and use it in GitHub Desktop.
Save sgl0v/f87cdb6fea3220c51626f0fd3d6f8aac to your computer and use it in GitHub Desktop.
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