GithubHelp home page GithubHelp logo

thepowerofswift / kirsch Goto Github PK

View Code? Open in Web Editor NEW

This project forked from coverfy/kirsch

0.0 0.0 0.0 203 KB

Cool scanner developed with swift

License: MIT License

Swift 69.11% Ruby 2.82% Objective-C 2.03% Shell 26.05%

kirsch's Introduction

Kirsch

CI Status Version License Platform

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

Features

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

Example

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

Requirements

  • iOS 9.0+
  • 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
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()
}

Credits

This project has been developed to use it into the Coverfy App. An app to organize all your insurances, take a look at it https://www.coverfy.com!

image

Base 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.

kirsch's People

Contributors

josepbordesjove avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.