Skip to main content

Multiple Objects Scanner | iOS Document Scanner

The ScanbotSDK provides the ability to detect multiple non-overlapping rectangular objects in a UIImage or SampleBufferRef. The results of scanning are stored in an image storage (more about Image storage).

There are two ways to integrate the component into the application:

Usage of the Classical UI component:#

The main class of the classical UI component is SBSDKMultipleObjectScannerViewController.

Usually this view controller is embedded as a child view controller into another view controller, the parent view controller. The parent view controller usually acts as the delegate and processes the recognition results. You still have full control over the UI elements and can add additional views and buttons to your view controller. The classical component does not display results, instead it just forwards them to the delegate.

import Foundationimport ScanbotSDK
// This is a simple, empty view controller which acts as a container and delegate for the SBSDKMultipleObjectScannerViewController.class MultipleObjectsScannerSwiftViewController: UIViewController {
    // The instance of the recognition view controller.    var recognizerController: SBSDKMultipleObjectScannerViewController?
    override func viewDidLoad() {        super.viewDidLoad()
        // Create the SBSDKMultipleObjectScannerViewController instance        // and let it embed into this view controller's view.        self.recognizerController = SBSDKMultipleObjectScannerViewController(parentViewController: self,                                                                             parentView: self.view)
        // Set the delegate to this view controller.        self.recognizerController?.delegate = self
        // Turn the shutter button on/off.        self.recognizerController?.shutterButtonHidden = false    }}
extension MultipleObjectsScannerSwiftViewController: SBSDKMultipleObjectScannerViewControllerDelegate {    func scannerController(_ controller: SBSDKMultipleObjectScannerViewController,                           didCaptureObjectImagesInStorage imageStorage: SBSDKImageStoring) {        // Process the detected images in storage.    }}

Usage of the Ready to use UI component:#

The main class of the ready to use UI component is SBSDKUIMultipleObjectScannerViewController.

Usually this view controller is used as a separate screen for scanning multiple rectangular objects, e.g. business cards. It returns its results wrapped in an SBSDKUIDocument instance.

While you don't have direct control of the actual scanner view controller, you can use the SBSDKUIMultipleObjectScannerConfiguration to customize it in a variety of ways, such as colors, texts and behavior.

import Foundationimport ScanbotSDK
class MultipleObjectsScannerUISwiftViewController: UIViewController {    override func viewDidAppear(_ animated: Bool) {        super.viewDidAppear(animated)        // Start scanning here. Usually this is an action triggered by some button or menu.        self.startScanning()    }
    private func startScanning() {
        // Create the default configuration object.        let configuration = SBSDKUIMultipleObjectScannerConfiguration.default()
        // Behavior configuration:        // e.g. enable batch mode.        configuration.behaviorConfiguration.isBatchModeEnabled = true
        // UI configuration:        // e.g. configure various colors.        configuration.uiConfiguration.topBarBackgroundColor = UIColor.red        configuration.uiConfiguration.topBarButtonsActiveColor = UIColor.white        configuration.uiConfiguration.topBarButtonsInactiveColor = UIColor.white.withAlphaComponent(0.3)
        // Text configuration:        // e.g. customize some UI elements' text.        configuration.textConfiguration.batchButtonTitle = "Batch Mode"        configuration.textConfiguration.flashButtonTitle = "Flash"
        // Present the recognizer view controller modally on this view controller.        SBSDKUIMultipleObjectScannerViewController.present(on: self, with: configuration, andDelegate: self)    }}
extension MultipleObjectsScannerUISwiftViewController: SBSDKUIMultipleObjectScannerViewControllerDelegate {    func multipleObjectScannerViewController(_ viewController: SBSDKUIMultipleObjectScannerViewController,                                             didFinishWith document: SBSDKUIDocument) {        // Process the recognized document.    }}