Skip to main content

Health Insurance Card Scanner | iOS Document Scanner

The Scanbot SDK provides the ability to recognize European health insurance cards (EHIC), a.k.a. elektronische Gesundheitkarten(eGK).

The EHIC Scanner is based on the OCR feature and thus requires the proper installation of the OCR language files deu.traineddata and eng.traineddata (aka. blob files). For more details on how to set up the OCR language files please refer to the OCR section.

EHIC Scanner UI#

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

Classical UI Component#

import UIKitimport ScanbotSDK
class EHICScannerSwiftViewController: UIViewController {
    // The instance of the camera session for the EHIC recognition feature.    private let cameraSession = SBSDKCameraSession(for: FeatureEHICRecognition)
    // The instance of the EHIC recognizer.    private let ehicRecognizer = SBSDKHealthInsuranceCardRecognizer()
    override func viewDidLoad() {        super.viewDidLoad()
        // Assign self as a video delegate for the camera session.        self.cameraSession.videoDelegate = self
        // Add the camera's preview layer as a sublayer to the view controller's view layer.        self.view.layer.addSublayer(self.cameraSession.previewLayer)    }
    override func viewWillAppear(_ animated: Bool) {        super.viewWillAppear(animated)
        // Start the camera session just before view appears to provide a smooth transition.        self.cameraSession.start()    }
    override func viewDidDisappear(_ animated: Bool) {        super.viewDidDisappear(animated)
        // Stop the camera session when view is no longer visible.        self.cameraSession.stop()    }}
// MARK: - SBSDKCameraSessionDelegateextension EHICScannerSwiftViewController: SBSDKCameraSessionDelegate {
    // Implement this function to process the camera's output.    func captureOutput(_ output: AVCaptureOutput,                       didOutput sampleBuffer: CMSampleBuffer,                       from connection: AVCaptureConnection) {
        // Recognize the EHIC card with recognizer.        let result = self.ehicRecognizer.recognize(from: sampleBuffer,                                      orientation: self.cameraSession.videoOrientation)        // Process the recognized result.    }}

Ready-To-Use UI Component#

The main class of the Ready-To-Use UI (RTU UI) component is SBSDKUIHealthInsuranceCardScannerViewController.

Usually this view controller is used as a separate screen for scanning European health insurance cards in a UIImage or CMSampleBufferRef. It returns the recognition results in a delegate method.

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

import UIKitimport ScanbotSDK
class EHICScannerUISwiftViewController: 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()    }
    func startScanning() {
        // Create the default configuration object.        let configuration = SBSDKUIHealthInsuranceCardScannerConfiguration.default()
        // Behavior configuration:        // e.g. turn on the flashlight.        configuration.behaviorConfiguration.isFlashEnabled = true
        // UI configuration:        // e.g. configure various colors.        configuration.uiConfiguration.topBarButtonsColor = UIColor.white        configuration.uiConfiguration.topBarBackgroundColor = UIColor.red
        // Text configuration:        // e.g. customize some UI elements' text.        configuration.textConfiguration.flashButtonTitle = "Flash"        configuration.textConfiguration.cancelButtonTitle = "Cancel"
        // Present the recognizer view controller modally on this view controller.        SBSDKUIHealthInsuranceCardScannerViewController.present(on: self,                                                                with: configuration,                                                                andDelegate: self)    }}
extension EHICScannerUISwiftViewController: SBSDKUIHealthInsuranceCardScannerViewControllerDelegate {    func healthInsuranceCardDetectionViewController(_ viewController: SBSDKUIHealthInsuranceCardScannerViewController,                                                    didDetectCard card: SBSDKHealthInsuranceCardRecognitionResult) {        // Process the detected card.    }}