From 2c564ec73cceb18a8962654ce50db72ae3f6b44d Mon Sep 17 00:00:00 2001 From: vferrantelli Date: Fri, 16 Nov 2018 18:03:25 +0100 Subject: [PATCH] added getters for parsed image and parsed MRZ, fixed render view when used without xib --- PassportScanner.xcodeproj/project.pbxproj | 6 ++--- Pod/MRZParser.swift | 4 ++++ Pod/PassportScannerController.swift | 27 +++++++++++++++++++++-- 3 files changed, 32 insertions(+), 5 deletions(-) diff --git a/PassportScanner.xcodeproj/project.pbxproj b/PassportScanner.xcodeproj/project.pbxproj index 9f0cd13..fb4be66 100644 --- a/PassportScanner.xcodeproj/project.pbxproj +++ b/PassportScanner.xcodeproj/project.pbxproj @@ -184,7 +184,7 @@ TargetAttributes = { 7F132F2D1B9ED2C5001A542A = { CreatedOnToolsVersion = 6.4; - DevelopmentTeam = 6Z7QY98HTS; + DevelopmentTeam = Q6FGJYQPM4; LastSwiftMigration = 0800; }; }; @@ -402,7 +402,7 @@ buildSettings = { ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; CLANG_ENABLE_MODULES = YES; - DEVELOPMENT_TEAM = 6Z7QY98HTS; + DEVELOPMENT_TEAM = Q6FGJYQPM4; ENABLE_BITCODE = NO; INFOPLIST_FILE = PassportScanner/Info.plist; IPHONEOS_DEPLOYMENT_TARGET = 8.0; @@ -425,7 +425,7 @@ buildSettings = { ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; CLANG_ENABLE_MODULES = YES; - DEVELOPMENT_TEAM = 6Z7QY98HTS; + DEVELOPMENT_TEAM = Q6FGJYQPM4; ENABLE_BITCODE = NO; INFOPLIST_FILE = PassportScanner/Info.plist; IPHONEOS_DEPLOYMENT_TARGET = 8.0; diff --git a/Pod/MRZParser.swift b/Pod/MRZParser.swift index 7b94a01..d242e72 100644 --- a/Pod/MRZParser.swift +++ b/Pod/MRZParser.swift @@ -11,8 +11,12 @@ import Foundation @objc(MRZParser) open class MRZParser : NSObject{ + @objc public var parsedMRZ: String = "" + + @objc public init(scan: String, debug: Bool = false) { super.init() + parsedMRZ = scan } /// Was the last scan valid. A value of 1 is for when all validations are OK diff --git a/Pod/PassportScannerController.swift b/Pod/PassportScannerController.swift index b1549af..c5d0913 100644 --- a/Pod/PassportScannerController.swift +++ b/Pod/PassportScannerController.swift @@ -34,6 +34,9 @@ open class PassportScannerController: UIViewController, MGTesseractDelegate { /// If false then apply filters in post processing, otherwise instead of in camera preview @objc public var showPostProcessingFilters = true + //last parsed image + @objc public var parsedImage: UIImage? + // The parsing to be applied @objc public var mrzType: MRZType = MRZType.auto @@ -180,6 +183,11 @@ open class PassportScannerController: UIViewController, MGTesseractDelegate { camera = try Camera(sessionPreset: AVCaptureSession.Preset.hd1920x1080) camera.location = PhysicalCameraLocation.backFacing + if renderView==nil { + renderView = RenderView.init(frame: self.view.bounds) + self.view.addSubview(renderView) + } + if !showPostProcessingFilters { // Apply only the cropping camera --> renderView @@ -290,7 +298,14 @@ open class PassportScannerController: UIViewController, MGTesseractDelegate { self.stopScan() } - + open func imageFromView(myView: UIView) -> UIImage { + UIGraphicsBeginImageContextWithOptions(myView.bounds.size, myView.isOpaque, 0.0) + myView.drawHierarchy(in: myView.bounds, afterScreenUpdates: true) + let snapshotImageFromMyView = UIGraphicsGetImageFromCurrentImageContext() + UIGraphicsEndImageContext() + //print(snapshotImageFromMyView) + return snapshotImageFromMyView! + } /** Processing the image @@ -330,7 +345,15 @@ open class PassportScannerController: UIViewController, MGTesseractDelegate { if mrz.isValid() < self.accuracy { print("Scan quality insufficient : \(mrz.isValid())") } else { - self.camera.stopCapture() + DispatchQueue.main.async { + let subviews = self.renderView.subviews + for view in subviews { + view.removeFromSuperview() + } + self.parsedImage = self.imageFromView(myView: self.renderView) + self.camera.stopCapture() + } + DispatchQueue.main.async { self.successfulScan(mrz: mrz) }