Coder Social home page Coder Social logo

cv-apps / document-scanner-ios Goto Github PK

View Code? Open in Web Editor NEW

This project forked from adorsys/yeswescan

0.0 2.0 1.0 1.91 MB

A library with a ready to use view controller for document scanning

License: Apache License 2.0

Swift 93.59% Ruby 6.41%

document-scanner-ios's Introduction

YesWeScan

Build Status Swift 4.2 license platform Carthage compatible

This pod contains a ready to use view controller for document scanning. Yes we scan!

Requirements

  • iOS 10.0 SDK or later

Scanner Preview

Demo

Installation

Cocoapods

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

pod 'YesWeScan'

Carthage

YesWeScan is also available via Carthage. Add the following line to your Cartfile:

github "adorsys/document-scanner-ios"

Using this Pod

Scanner View Controller

The main class in this project is ScannerViewController. You can access it with import YesWeScan.

class ViewController: UIViewController,  {
  var scannedImage: UIImage?

  override func viewDidLoad() {
    super.viewDidLoad()
    let scanner = ScannerViewController()
    scanner.delegate = self
    navigationController?.pushViewController(scanner, animated: true)
  }
}

Delegate Methods

The scanner will not capture images without a delegate. You should therefore set the delegate property of the scanner VC.

You will then receive calls when the scanner found an image of suitable quality:

extension ViewController: ScannerViewControllerDelegate {
  func didCapture(image: UIImage) {
    scannedImage = image
    navigationController?.popViewController(animated: true)
  }
}

Scanner Quality

You can customize the scanner's accuracy using the jitter property. Higher values will make it easier to capture an image, but it won't be as steady.

The default value here is 100.

The Scanner resolution can be configured by passing the ScannerViewController an AVCaptureSession.Preset during initialization. The default value is .high. If the given preset isn't supported by the capture device, it'll fall back to the default value.

UI Configuration

The scanner's UI can be configured using the initializer:

ScannerViewController(config: [.torch, .manualCapture])

The following options are available:

  • .targetBraces: A button to toggle targeting braces
  • .torch: A button for controlling the torch
  • .manualCapture: A manual camera shutter

The default value here is .all

You can also configure the previewColor (color of scan preview rect) and braceColor (color of the target finder braces).

The defaults here are UIColor.green and UIColor.red, respectively.

Performance hint

The scanner takes quite some time to fire up the AVCaptureSession, etc, which means initializing a ScannerViewController is expensive.

Depending on your use case, it probably makes sense to store a strong reference to the ScannerViewController in the presenting View Controller (as seen in the Example project).

Siri Shortcuts

The scanner example project supports Siri Shortcuts since iOS 12*. The User own shortcut opens the app and navigates to the Document Scanner. You can find the implementation in the example project.

The implementation works as follows: Activate Siri in the project and add a NSUserActivityTypes identifier in info.plist. Then activate Siri Shortcut adding following lines in the project:

if #available(iOS 12.0, *) {
    let identifier = Bundle.main.userActivityIdentifier
    let activity = NSUserActivity(activityType: identifier)
    activity.title = "The String the User will see in preferences"
    activity.userInfo = ["Document Scanner" : "open document scanner"]
    activity.isEligibleForSearch = true
    activity.isEligibleForPrediction = true
    activity.persistentIdentifier = NSUserActivityPersistentIdentifier(identifier)
    view.userActivity = activity
    activity.becomeCurrent()
}

To call a specific function add in the AppDelegate.swift file:

func application(_ application: UIApplication, continue userActivity: NSUserActivity, restorationHandler: @escaping ([UIUserActivityRestoring]?) -> Void) -> Bool {
    if #available(iOS 12.0, *) {
        if userActivity.activityType == Bundle.main.userActivityIdentifier {
            let navigationController = window?.rootViewController! as! UINavigationController
            let viewController = navigationController.children.first as! ViewController
            viewController.theFunctionToCall()
        }
        return true
    }
    return false
}

License

YesWeScan is released under the Apache 2.0 License. Please see the LICENSE file for more information.

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.