Coder Social home page Coder Social logo

yeswescan's Introduction

YesWeScan

Build Status Swift 5.2 license platform Carthage compatible SPM compatible

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

iOS 13 notice

iOS 13 contains the VNDocumentCameraViewController, which is an Apple-provided class that is likely to achieve better results and have less bugs than this pod.

If your app is targeting iOS 13 or higher, please consider using it instead of this pod.

Requirements

  • iOS 10.0 SDK or later
Xcode Version YesWeScan
<= 10.1 <= 1.3.0
>= 10.2 => 2.0.0

Scanner Preview

Demo

Installation

CocoaPods

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

pod 'YesWeScan', ~> '2.0'

Carthage

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

github "adorsys/YesWeScan"

Swift Package Manager

Starting in version 2.2.0, Swift Package Manager is also supported ๐ŸŽ‰

Add it to your project like this:

dependencies: [
    .package(url: "https://github.com/adorsys/YesWeScan.git", from: "2.2.0")
]

Usage

The scanner needs access to the camera. In order to allow this, your Info.plist must contain the NSCameraUsageDescription key.

An info.plist entry for NSCameraUsageDescription

Scanner View Controller

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

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

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

extension ViewController: ScannerViewControllerDelegate {
  func scanner(_ scanner: ScannerViewController, didCaptureImage 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.

Image Features needed before automatically capture

You can change the variable scanningQuality to control the scanning quality of the image. Changes to scanningQuality will influence the number of features required before taking a capture.

enum Quality {
  case high, medium, fast
}

The default value is .medium and this variable is available in ScannerViewController.

scanner.scanningQuality = .fast

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
  • .progressBar: Show a progress bar for the current scan

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.

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, like openDocumentScanner(), add this to AppDelegate:

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

Using the scanner directly

It's also possible to use the scanner class without the ScannerViewController class (that is part of this pod) directly.

As an example how to do this, take a look at the CustomUIViewController class.

License

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

yeswescan's People

Contributors

dandjelkovic avatar dependabot[bot] avatar fbernutz avatar francis-pouatcha avatar ghmarcus avatar msztech avatar steffsan avatar timabraham avatar xavierlowmiller avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

yeswescan's Issues

Scanning Process callback delegate

It's great to be able to contribute my ideas at here and thanks for working on previous PRs! I have a new suggestion for the project:

Since there'll be a set number of features required before the capturing (the featuresRequired set by user by the quality enum, which is by default 7). I'm thinking to add an optional delegate callback so that there could be a feedback for users how long their scan will still take.

And in the demo app, there could be a small transparent progress bar at the bottom indicating how many features are still required (so that they need to hold their phone to the paper). And there can be a haptic feedback every time the delegate is called.

What do you think of that feature? ๐Ÿ˜ƒ I can work on both the delegate callback and the example app.

Possibility to edit/use own UI

Hi,

Awesome setup. I just wanted to check if there's a possibility of using this library with my own VC which has a few custom changes instead of the default one that's provided?

Share buttons

Description

The current demo application can scan, capture, and crop images just fine.

Unfortunately, the images are of little use, because there is no way to transfer them to other apps.

I propose to add a "Share" button somewhere that enables the user to share the image with other apps.

It should be possible to share images (in JPG format I guess) as well as PDFs.

A feature to immediately capture the recognized area

I'm thinking about a property directCapture, which, if set to true (and is false by default), will immediately capture the recognized area when pressing the shooting button.

Would you mind of I submit a PR for this feature?

Disable AutoCapture

Is it possible to disable autocapture (i.e. hide the green rectangle which auto captures images)?

Thanks, and great library!

Support device rotation

The scanner is currently very buggy when rotating the device

  1. Before opening the scanner
  2. While scanning

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.