Kirsch是一个优雅且简单的扫描库,可自动扫描文档并裁剪。
要运行示例项目,请克隆仓库,然后从示例目录首先运行pod install
。
Kirsch可以通过CocoaPods使用。要安装它,只需将以下行添加到Podfile中
pod "Kirsch"
要初始化扫描仪,只需调用其初始化方法并带上所需选项。
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
注意:configure()应在start()函数之前调用。
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
捕获进度指示图像是否被良好检测以及手机是否能够捕获它。当此进度达到100%时,扫描仪已检测到稳定的图像。
func getCapturingProgress(_ progress: Float?) {
guard let progress = progress else { return }
if progress >= 1 {
scanner.captureImage(withFilter: .contrast, andOrientation: .vertical)
}
}
当捕获图像时,它将由这个委托函数返回。
func getCapturedImageFiltered(_ image: UIImage?) {
guard let capturedImage = image else { return }
self.coverfyScanner.stop()
}
此扫描仪的一些想法取自于IRLScanner (https://github.com/hartws1/IRLScanner)。
josepbordesjove, [email protected]
Kirsch适用于MIT许可证。有关更多信息,请参阅LICENSE文件。