Kirsch 0.3.0

Kirsch 0.3.0

TestsTested
LangLanguage SwiftSwift
License MIT
ReleasedLast Release Aug 2017
SwiftSwift Version 3.0
SPMSupports SPM

Maintained by Josep Bordes.



Kirsch 0.3.0

Kirsch

Kirsch is an elegant and simple scanner library to automatically scan documents and crop them.

Features

  • [x] Automatic and manual document capture
  • [x] Color and black and white filter
  • [x] Border cropping

Example

To run the example project, clone the repo, and run pod install from the Example directory first.

Requirements

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

Installation

Kirsch is available through CocoaPods. To install it, simply add the following line to your Podfile:

pod "Kirsch"

Usage

Initialize and configure the scanner

To initialize the scanner simply call it’s initilaizer with the desired options.

  • videoFrameOption: Indicates the size of the view where the video is displayed (.normal, .square, .fullScreen and .withBottomMargin)
  • applyFilterCallback: Should stay nil
  • ratio: The approximate ratio (height/width) of the document you want to scan
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)
    }
  }
  
}

Options available

scanner.isBlackFilterActivated // Activate the black filter 
scanner.isFlashActive // Activate the flashlight of the phone 

Configuration Functions

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.

Control Functions

  • Filter: Indicates the type of filter it’s going to be applied (.contrast, .none)
  • Orientation: Helps the detector in which orientation the documents is going to be (.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

Delegate

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()
}

Based project

Some ideas of this scanner has been taken from the IRLScanner (https://github.com/hartws1/IRLScanner)

Author

josepbordesjove, [email protected]

License

Kirsch is available under the MIT license. See the LICENSE file for more info.