TestsTested | ✗ |
LangLanguage | SwiftSwift |
License | MIT |
ReleasedLast Release | Aug 2017 |
SwiftSwift Version | 3.0 |
SPMSupports SPM | ✗ |
Maintained by Josep Bordes.
Kirsch is an elegant and simple scanner library to automatically scan documents and crop them.
To run the example project, clone the repo, and run pod install
from the Example directory first.
Kirsch is available through CocoaPods. To install it, simply add the following line to your Podfile:
pod "Kirsch"
To initialize the scanner simply call it’s initilaizer with the desired options.
import UIKit
import Kirsch
class ViewController: UIViewController, KirschDelegate {
lazy var scanner: Kirsch = {
let scanner = Kirsch(superview: self.view, videoFrameOption: .fullScreen, applyFilterCallback: nil, ratio: 1.5)
scanner.configure()
return scanner
}()
viewDidLoad() {
super.viewDidLoad()
// Create the video filter
scanner.delegate = self
}
override func viewDidAppear(_ animated: Bool) {
do {
try scanner.start()
} catch {
presentAlertView(title: "Some Error Occurred", message: error.localizedDescription)
}
}
}
scanner.isBlackFilterActivated // Activate the black filter
scanner.isFlashActive // Activate the flashlight of the phone
scanner.configure() // Configure the scanner
scanner.start() // Start the scanner
swift scanner.stop() // Stop the scanner
Note: that the configure() should be called before the start() function.
scanner.captureImage(withFilter: .contrast, andOrientation: .vertical) // Captures vertical image and applying a high contrast filter
scanner.captureImage(withOrientation: .vertical) // Captures a vertical image without applying any filters
scanner.captureImageWithNoCrop(withOrientation: .vertical) // Captures a vertical image without cropping any borders
The capturing progress indicates if an image is being well detected and the phone is able to capture it. When this progress arrives at 100%, the scanner has detected an stable image
func getCapturingProgress(_ progress: Float?) {
guard let progress = progress else { return }
if progress >= 1 {
scanner.captureImage(withFilter: .contrast, andOrientation: .vertical)
}
}
When the an image is captured, it will be returned by this delegate function
func getCapturedImageFiltered(_ image: UIImage?) {
guard let capturedImage = image else { return }
self.coverfyScanner.stop()
}
Some ideas of this scanner has been taken from the IRLScanner (https://github.com/hartws1/IRLScanner)
josepbordesjove, [email protected]
Kirsch is available under the MIT license. See the LICENSE file for more info.