Skip to content

Commit

Permalink
Merge pull request #27 from punto2018/getters
Browse files Browse the repository at this point in the history
added getters for parsed image and parsed MRZ, fixed render view usage without xib
  • Loading branch information
evermeer authored Nov 17, 2018
2 parents 48d0dc5 + 2c564ec commit b10a4c8
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 5 deletions.
6 changes: 3 additions & 3 deletions PassportScanner.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@
TargetAttributes = {
7F132F2D1B9ED2C5001A542A = {
CreatedOnToolsVersion = 6.4;
DevelopmentTeam = 6Z7QY98HTS;
DevelopmentTeam = Q6FGJYQPM4;
LastSwiftMigration = 0800;
};
};
Expand Down Expand Up @@ -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;
Expand All @@ -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;
Expand Down
4 changes: 4 additions & 0 deletions Pod/MRZParser.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
27 changes: 25 additions & 2 deletions Pod/PassportScannerController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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)
}
Expand Down

0 comments on commit b10a4c8

Please sign in to comment.