Skip to content

Instantly share code, notes, and snippets.

@JohannMG
Last active February 11, 2016 15:28
Show Gist options
  • Save JohannMG/15d52148bbde372b834e to your computer and use it in GitHub Desktop.
Save JohannMG/15d52148bbde372b834e to your computer and use it in GitHub Desktop.
OCR View Notes and Doc

#OCR Integration Notes

Library Dependencies:

Main OCR Files structure

-Curves non-ARC objective-c code must have appropriate compiler flags -Filters -Luhn Card validation methods. Used in account creation besides OC -Main Contains "AutoTakeViewController" the main API endpoint -Picture Pot -Resources Color LUTs -tessdata/AAA.trainedata Card training data. I seem to need it int the CCM main app for now. Investigating.

API Usage

Process for accessing, opening, and obtaining data from OCR View

  1. Check camera permissions
  2. Create AutoTakeViewController()
  3. Set self as delegate to AutoTakeViewControllerDelegate protocol
  4. Display AutoTakeViewController
  5. The OCR view manages it's own dismissal, sends delegate a notification when it does
  6. Accept AutoTakeViewControllerDidDismiss: membershipNumber: from protocol
  7. Parse membershipNumber into UI Form

If the user closed the OCR view, the membershipNumber returns as nil. Otherwise membershipNumber returns with a validated membership number with each of the 4 blocks separated by spaces

AutoTakeViewController.h/m provides the helpers to displays views as well as AutoTakeViewControllerDelegate

###Example Code

//called in response to button push
func useOCR() {
	//must check or get camera permissions, moved this into CCMFramework
	if CCMFramework.getCameraVideoPermissions() {

		//create OCR view, set self as delegate, present VC
		let ocrVC = AutoTakeViewController()
        ocrVC.delegate = self
        presentViewController(ocrVC, animated: true, nil)
	}
}

//protocol method 
extension YourAwesomeViewController : AutoTakeViewControllerDelegate {
	
	//called on both successful and manual exits
	func AutoTakeViewControllerDidDismiss(controller: AutoTakeViewController!,
	                   membershipNumber memberNumber: String!) {

		//can be obj-c nil if no successful scan
		if memberNumber == nil { return }

		//blocks separated by spaces "### ### ######### #"
		let stringsArr:[String] = memberNumber.componentsSeparatedByString(" ")
		populateFields(stringsArr)
	}
}

Still Existing Problems

  • Imported code uses the 3.4.0 version, but the 4.0.0 version is breaking
  • 3.4.0 version is not compatible with Xcode bitcode
  • Not scanning in iPad? Investigating

###Misc Notes

  • Current TesseractOCR library version does not support bitcode
  • Had to move tessdata into the main CCM application
  • Seemed that the main CCM needed/wanted it's own lib dependency of GPUImage
  • Code did not seems to work well in it's own framework what I think is due to both library dependencies and cross-objectiveC-to-Swift barriers. Worked with Rashaad on this for a bit and determined that moving OCR into the main Framework to be the action for right now.

####More raw inspection noise below about working back through the original implementation

####Main OCR Uses TesseractOCR iOS 3.4.0 https://github.com/gali8/Tesseract-OCR-iOS

AutoTakeViewController.h

<AutoTakeViewControllerDelegate>
- (void)AutoTakeViewControllerDidDismiss:(AutoTakeViewController *)controller membershipNumber:(NSString *)memberNumber;

[]AutoTakeViewController
	- (IBAction)cancel:(id)sender;

####Usage of API notes from original AAA application

MembershipSignOnView.h View controller for the type in or scan card screen. contains the button to scan.

defines, uses

on scan button click calls didPressScanMembershipCardButton to it's delegate.

SingleSignOnView.m/h is MembershipSignOnViewDelegate

didPressScanMembershipCardButton -> calls itself controller.... ?

AAA/Controllers/SingleSignOnController.m:269:- (void)showOCR{
[self.controller showOCR];

SingleSignOnController.m/h is AutoTakeViewControllerDelegate (and methods of course) -showOCR() checks for camera permissions, (if none, returns) makes new AutoTakeViewController() sets self as AutoTakeViewController delegate presents AutoTakeViewController NOTE: OCR view is presented by SingleSignOnController but dismisses itself

(void)AutoTakeViewControllerDidDismiss:(AutoTakeViewController *)controller membershipNumber:(NSString *)memberNumber{

sends this to SingleSignOnView -> MembershipSignOnView with the Number

populateMembershipNumberField(): does just that

NEED TO CONFIRM: member number string parts come back already divided into sections XXX XXX etc by spaces

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment