Skip to content

Commit b10a4c8

Browse files
authored
Merge pull request #27 from punto2018/getters
added getters for parsed image and parsed MRZ, fixed render view usage without xib
2 parents 48d0dc5 + 2c564ec commit b10a4c8

File tree

3 files changed

+32
-5
lines changed

3 files changed

+32
-5
lines changed

PassportScanner.xcodeproj/project.pbxproj

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,7 @@
184184
TargetAttributes = {
185185
7F132F2D1B9ED2C5001A542A = {
186186
CreatedOnToolsVersion = 6.4;
187-
DevelopmentTeam = 6Z7QY98HTS;
187+
DevelopmentTeam = Q6FGJYQPM4;
188188
LastSwiftMigration = 0800;
189189
};
190190
};
@@ -402,7 +402,7 @@
402402
buildSettings = {
403403
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
404404
CLANG_ENABLE_MODULES = YES;
405-
DEVELOPMENT_TEAM = 6Z7QY98HTS;
405+
DEVELOPMENT_TEAM = Q6FGJYQPM4;
406406
ENABLE_BITCODE = NO;
407407
INFOPLIST_FILE = PassportScanner/Info.plist;
408408
IPHONEOS_DEPLOYMENT_TARGET = 8.0;
@@ -425,7 +425,7 @@
425425
buildSettings = {
426426
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
427427
CLANG_ENABLE_MODULES = YES;
428-
DEVELOPMENT_TEAM = 6Z7QY98HTS;
428+
DEVELOPMENT_TEAM = Q6FGJYQPM4;
429429
ENABLE_BITCODE = NO;
430430
INFOPLIST_FILE = PassportScanner/Info.plist;
431431
IPHONEOS_DEPLOYMENT_TARGET = 8.0;

Pod/MRZParser.swift

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,12 @@ import Foundation
1111
@objc(MRZParser)
1212
open class MRZParser : NSObject{
1313

14+
@objc public var parsedMRZ: String = ""
15+
16+
1417
@objc public init(scan: String, debug: Bool = false) {
1518
super.init()
19+
parsedMRZ = scan
1620
}
1721

1822
/// Was the last scan valid. A value of 1 is for when all validations are OK

Pod/PassportScannerController.swift

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,9 @@ open class PassportScannerController: UIViewController, MGTesseractDelegate {
3434
/// If false then apply filters in post processing, otherwise instead of in camera preview
3535
@objc public var showPostProcessingFilters = true
3636

37+
//last parsed image
38+
@objc public var parsedImage: UIImage?
39+
3740
// The parsing to be applied
3841
@objc public var mrzType: MRZType = MRZType.auto
3942

@@ -180,6 +183,11 @@ open class PassportScannerController: UIViewController, MGTesseractDelegate {
180183
camera = try Camera(sessionPreset: AVCaptureSession.Preset.hd1920x1080)
181184
camera.location = PhysicalCameraLocation.backFacing
182185

186+
if renderView==nil {
187+
renderView = RenderView.init(frame: self.view.bounds)
188+
self.view.addSubview(renderView)
189+
}
190+
183191
if !showPostProcessingFilters {
184192
// Apply only the cropping
185193
camera --> renderView
@@ -290,7 +298,14 @@ open class PassportScannerController: UIViewController, MGTesseractDelegate {
290298
self.stopScan()
291299
}
292300

293-
301+
open func imageFromView(myView: UIView) -> UIImage {
302+
UIGraphicsBeginImageContextWithOptions(myView.bounds.size, myView.isOpaque, 0.0)
303+
myView.drawHierarchy(in: myView.bounds, afterScreenUpdates: true)
304+
let snapshotImageFromMyView = UIGraphicsGetImageFromCurrentImageContext()
305+
UIGraphicsEndImageContext()
306+
//print(snapshotImageFromMyView)
307+
return snapshotImageFromMyView!
308+
}
294309

295310
/**
296311
Processing the image
@@ -330,7 +345,15 @@ open class PassportScannerController: UIViewController, MGTesseractDelegate {
330345
if mrz.isValid() < self.accuracy {
331346
print("Scan quality insufficient : \(mrz.isValid())")
332347
} else {
333-
self.camera.stopCapture()
348+
DispatchQueue.main.async {
349+
let subviews = self.renderView.subviews
350+
for view in subviews {
351+
view.removeFromSuperview()
352+
}
353+
self.parsedImage = self.imageFromView(myView: self.renderView)
354+
self.camera.stopCapture()
355+
}
356+
334357
DispatchQueue.main.async {
335358
self.successfulScan(mrz: mrz)
336359
}

0 commit comments

Comments
 (0)