Kirsch 0.3.0

Kirsch 0.3.0

测试已测试
语言语言 SwiftSwift
许可 MIT
发布上次发布2017年8月
SwiftSwift版本3.0
SPM支持SPM

Josep Bordes维护。



Kirsch 0.3.0

Kirsch

Kirsch是一个优雅且简单的扫描库,可自动扫描文档并裁剪。

特性

  • [x] 自动和手动文档捕获
  • [x] 彩色和黑白过滤器
  • [x] 边缘裁剪

示例

要运行示例项目,请克隆仓库,然后从示例目录首先运行pod install

要求

  • iOS 9.3+
  • Xcode 8.1, 8.2, 8.3和9.0
  • Swift 3.0, 3.1, 3.2和4.0

安装

Kirsch可以通过CocoaPods使用。要安装它,只需将以下行添加到Podfile中

pod "Kirsch"

使用

初始化和配置扫描仪

要初始化扫描仪,只需调用其初始化方法并带上所需选项。

  • videoFrameOption: 指示显示视频的视图的大小(.normal、.square、.fullScreen和.withBottomMargin)
  • applyFilterCallback: 应为空
  • ratio: 您要扫描的文档的大致宽高比(高度/宽度)
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()函数之前调用。

控制函数

  • Filter: 指示要应用的过滤器类型(.contrast、.none)
  • Orientation: 帮助检测器确定文档的哪个方向(.vertical、horizontal)
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文件。