{\rtf1\ansi\ansicpg1252\cocoartf1504\cocoasubrtf820 {\fonttbl\f0\fnil\fcharset0 HelveticaNeue;} {\colortbl;\red255\green255\blue255;\red53\green53\blue53;} {\*\expandedcolortbl;;\cssrgb\c27059\c27059\c27059;} \paperw11900\paperh16840\margl1440\margr1440\vieww10800\viewh8400\viewkind0 \deftab560 \pard\pardeftab560\slleading20\pardirnatural\partightenfactor0 \f0\fs24 \cf2 func openScanVC() \{\ /** Instantiate the scanning coordinator */\ let error: NSErrorPointer = nil\ let coordinator = self.coordinatorWithError(error: error)\ \ /** If scanning isn't supported, present an error */\ if coordinator == nil \{\ let messageString: String = (error!.pointee?.localizedDescription) ?? ""\ UIAlertView(title: "Warning", message: messageString, delegate: nil, cancelButtonTitle: "Ok").show()\ return\ \}\ \ /** Allocate and present the scanning view controller */\ let scanningViewController: UIViewController = PPViewControllerFactory.cameraViewController(with: self, coordinator: coordinator!, error: nil)\ \ /** Allow autorotation - if it makes sense for your use case */\ let scanController = scanningViewController as! PPScanningViewController\ scanController.autorotate = true\ scanController.supportedOrientations = UIInterfaceOrientationMask.all\ \ /** You can use other presentation methods as well */\ self.present(scanningViewController, animated: true, completion: nil)\ \}\ \ func coordinatorWithError(error: NSErrorPointer) -> PPCameraCoordinator? \{\ \ if (PPCameraCoordinator.isScanningUnsupported(for: PPCameraType.back, error: error)) \{\ return nil;\ \}\ \ if settings.scanSettings.recognizerSettingsList.count != 0\{\ settings.scanSettings.removeAllRecognizerSettings()\ \}\ \ settings.licenseSettings.licenseKey = "XGF5IXQW-EBFGSDDR-PUIYAVTC-BMDEBDCN-RRGYYTMM-JWGE3DCN-RRGYZ3MG-TDLFI3HR"\ \ switch scanType \{\ case 1:\ \ self.docScanner()\ \ switch self.idTypeSelected \{\ case 0:\ // Document Only\ break\ \ case 1,4:\ \ do\{\ let usDlSettings = PPUsdlRecognizerSettings()\ \ settings.scanSettings.add(usDlSettings)\ \}\ \ break\ case 2,3:\ \ do \{ // Remove this if you're not using MRTD recognition\ \ // To specify we want to perform MRTD (machine readable travel document) recognition, initialize the MRTD recognizer settings\ let mrtdRecognizerSettings = PPMrtdRecognizerSettings()\ \ /** You can modify the properties of mrtdRecognizerSettings to suit your use-case */\ \ // tell the library to get full image of the document. Setting this to YES makes sense just if\ // settings.metadataSettings.dewarpedImage = YES, otherwise it wastes CPU time.\ mrtdRecognizerSettings.dewarpFullDocument = true;\ \ // Add MRTD Recognizer setting to a list of used recognizer settings\ settings.scanSettings.add(mrtdRecognizerSettings)\ \}\ \ break\ \ case 4:\ break\ \ case 5:\ \ do\{\ let usDlSettings = PPUsdlRecognizerSettings()\ \ settings.scanSettings.add(usDlSettings)\ \}\ \ do \{ // Remove this if you're not using MRTD recognition\ \ // To specify we want to perform MRTD (machine readable travel document) recognition, initialize the MRTD recognizer settings\ let mrtdRecognizerSettings = PPMrtdRecognizerSettings()\ \ /** You can modify the properties of mrtdRecognizerSettings to suit your use-case */\ \ // tell the library to get full image of the document. Setting this to YES makes sense just if\ // settings.metadataSettings.dewarpedImage = YES, otherwise it wastes CPU time.\ mrtdRecognizerSettings.dewarpFullDocument = true;\ \ // Add MRTD Recognizer setting to a list of used recognizer settings\ settings.scanSettings.add(mrtdRecognizerSettings)\ \}\ \ do \{ // Remove this if you're not using UKDL recognition\ \ // To specify we want to perform UKDL (UK Driver's license) recognition, initialize the UKDL recognizer settings\ let eudlRecognizerSettings = PPEudlRecognizerSettings.init(eudlCountry: .germany)\ \ // eudlRecognizerSettings.showFullDocument = true\ \ /** You can modify the properties of ukdlRecognizerSettings to suit your use-case */\ \ // If you want to save the image of the UKDL, set this to YES\ eudlRecognizerSettings.showFullDocument = true;\ \ // Add UKDL Recognizer setting to a list of used recognizer settings\ settings.scanSettings.add(eudlRecognizerSettings)\ \}\ \ break\ \ default:\ break\ \}\ break\ \ case 2:\ do\{\ \ let faceDetection = PPFaceDetectorSettings()\ \ let detector = PPDetectorRecognizerSettings(detectorSettings: faceDetection)\ \ settings.scanSettings.add(detector)\ \ \}\ break\ \ default:\ break\ \}\ // DISABLE this if you don't need to store images to improve performance!\ \ let metaDataSettings = PPMetadataSettings()\ \ metaDataSettings.dewarpedImage = true\ \ settings.metadataSettings = metaDataSettings\ \ /** 4. Initialize the Scanning Coordinator object*/\ \ let coordinator: PPCameraCoordinator = PPCameraCoordinator(settings: settings, delegate: nil)\ return coordinator\ \}\ \ func docScanner()\{\ let documentDetectorSettings = PPDocumentDetectorSettings.init(numStableDetectionsThreshold: 5)\ // ID1 specification\ let specificationId1 = PPDocumentSpecification.new(from: .id1Card)\ \ var documentDocodeingId1 : [PPDecodingInfo] = [PPDecodingInfo]()\ \ documentDocodeingId1.append(PPDecodingInfo.init(location: CGRect(x: 0, y: 0, width: 1.0, height: 1.0), dewarpedHeight: 700, uniqueId: "ID1"))\ \ specificationId1.setDecodingInfo(documentDocodeingId1)\ \ // ID2 specification\ \ let specificationId2 = PPDocumentSpecification.new(from: .id2Card)\ \ var documentDocodeingId2 : [PPDecodingInfo] = [PPDecodingInfo]()\ \ documentDocodeingId2.append(PPDecodingInfo.init(location: CGRect(x: 0, y: 0, width: 1.0, height: 1.0), dewarpedHeight: 800, uniqueId: "ID2"))\ \ specificationId2.setDecodingInfo(documentDocodeingId2)\ \ //ID3 Specification\ // ID1 specification\ let specificationId3 = PPDocumentSpecification.new(from: .cheque)\ \ var documentDocodeingId3 : [PPDecodingInfo] = [PPDecodingInfo]()\ \ documentDocodeingId3.append(PPDecodingInfo.init(location: CGRect(x: 0, y: 0, width: 1.0, height: 1.0), dewarpedHeight: 600, uniqueId: "ID1"))\ \ specificationId3.setDecodingInfo(documentDocodeingId3)\ \ documentDetectorSettings.setDocumentSpecifications([specificationId1,specificationId2,specificationId3])\ \ // MRTD detector\ \ var mrtdDecoding : [PPDecodingInfo] = [PPDecodingInfo]()\ \ mrtdDecoding.append(PPDecodingInfo.init(location: CGRect(x: 0, y: 0, width: 1.0, height: 1.0), dewarpedHeight: 700, uniqueId: "MRTD"))\ \ let mrtdDetectorSettings = PPMrtdDetectorSettings.init(decodingInfoArray: mrtdDecoding)\ \ \ // MULTI detector\ \ let multiDetectorSettings = PPMultiDetectorSettings.init(settingsArray: [documentDetectorSettings,mrtdDetectorSettings])\ \ multiDetectorSettings?.allowMultipleResults = true\ \ // Detector recognizer\ \ let detectorRecognizerSettings = PPDetectorRecognizerSettings.init(detectorSettings: documentDetectorSettings)\ \ settings.scanSettings.add(detectorRecognizerSettings)\ \}\ \ // func scann\ func scanningViewControllerUnauthorizedCamera(_ scanningViewController: UIViewController) \{\ // Add any logic which handles UI when app user doesn't allow usage of the phone's camera\ \}\ \ \ func scanningViewController(scanningViewController: UIViewController, didFindError error: NSError) \{\ // Can be ignored. See description of the method\ \}\ \ \ public func scanningViewController(_ scanningViewController: UIViewController, didFindError error: Error) \{\ // Can be ignored\ \}\ \ \ func scanningViewControllerDidClose(_ scanningViewController: UIViewController) \{\ // As scanning view controller is presented full screen and modally, dismiss it\ self.scanTimer.invalidate()\ self.dismiss(animated: true, completion: nil)\ \}\ \ \ func scanningViewController(_ scanningViewController: UIViewController?, didOutputResults results: [PPRecognizerResult]) \{\ \ // return if we don't have any results\ if (results.count == 0) \{\ return\ \}\ \ let scanController = scanningViewController as! PPScanningViewController\ \ var message = ""\ var title = ""\ \ // Collect data from the result\ for result in results \{\ title = "Scan result"\ message = result.description\ \ if result is PPUsdlRecognizerResult\{\ \ \}\ \ \ \ if (result is PPMrtdRecognizerResult) \{\ scanController.pauseScanning()\ self.scanTimer.invalidate()\ \ \}\ \ if (result is PPEudlRecognizerResult) \{\ scanController.pauseScanning()\ \}\ \}\ \}\ \ \ func scanningViewController(_ scanningViewController: UIViewController, didFinishDetectionWith result: PPDetectorResult) \{\ \ \}\ \ \ func scanningViewController(_ scanningViewController: UIViewController?, didOutputMetadata metadata: PPMetadata) \{\ \ if (metadata is PPImageMetadata) \{\ // self.scanTimer.invalidate()\ let result: PPImageMetadata = metadata as! PPImageMetadata\ let image: UIImage = result.image()\ \ if (result.name == PPEudlRecognizerSettings.full_DOCUMENT_IMAGE()) \{\ print("This image is EUDL full document");\ \} else if (result.name == PPMrtdRecognizerSettings.full_DOCUMENT_IMAGE()) \{\ print("This image is full Machine readable travel document");\ \} else if (result.name == PPMrtdRecognizerSettings.mrz_IMAGE()) \{\ print("This image is Machine readable zone");\ \} else if (result.name == PPMyKadRecognizerSettings.full_DOCUMENT_IMAGE()) \{\ print("This image is full MyKad");\ \}\ \}\ \}\ \ }