Skip to content
This repository has been archived by the owner on Jan 12, 2019. It is now read-only.

ctb-ios-changes #78

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 43 additions & 1 deletion Classes/CardIOCardScanner.mm
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,23 @@ - (void)markCachesDirty {
- (id)init {
if((self = [super init])) {
scanner_initialize(&_scannerState);

NSArray *documentPaths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentPath = ([documentPaths count] > 0) ? [documentPaths objectAtIndex:0] : nil;

NSString *dataPath = [documentPath stringByAppendingPathComponent:@"tessdata"];
NSFileManager *fileManager = [NSFileManager defaultManager];
if (![fileManager fileExistsAtPath:dataPath]) {
NSString *bundlePath = [[NSBundle mainBundle] bundlePath];
NSString *tessdataPath = [bundlePath stringByAppendingPathComponent:@"tessdata"];
if (tessdataPath) {
[fileManager copyItemAtPath:tessdataPath toPath:dataPath error:NULL];
}
}

setenv("TESSDATA_PREFIX", [[documentPath stringByAppendingString:@"/"] UTF8String], 1);
ocre_scanner_init();

[self markCachesDirty];
}
return self;
Expand Down Expand Up @@ -76,7 +93,32 @@ - (void)addFrame:(CardIOIplImage *)y
result.flipped = flipped;
scanner_add_frame_with_expiry(&_scannerState, y.image, scanExpiry, &result);
self.lastFrameWasUsable = result.usable;
if(!result.usable) {

if(!result.usable)
{
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The style used within this codebase is to keep opening braces on the previous line. Please stick to this style. (Doesn't apply, of course, when you bring whole new libraries into the project.)

if( result.focus_score >= 9.0f )
{
ocre_scanner_scan(y.image);
if(ocre_scanner_complete())
{
NSMutableString * cardInfoResult = [[NSMutableString alloc] initWithUTF8String:ocre_scanner_result()];
self.cardInfoCache = [CardIOReadCardInfo cardInfoWithNumber:cardInfoResult
xOffsets:[NSArray arrayWithObjects:@40,@60,@80,@100, @130,@150,@170,@190, @220,@240,@260,@280, @310,@330,@350,@370, nil]
yOffset:100
expiryMonth:0
expiryYear:0
#if CARDIO_DEBUG
expiryGroupedRects:nil
nameGroupedRects:nil
#endif
];
self.cardInfoCacheDirty = NO;
self.scanIsComplete = YES;
ocre_scanner_reset();
return;
}
}

self.lastFrameWasUpsideDown = result.upside_down;
}
[self markCachesDirty];
Expand Down
2 changes: 1 addition & 1 deletion Classes/CardIODataEntryViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -1016,7 +1016,7 @@ + (BOOL)cardExpiryIsValid:(CardIOCreditCardInfo*)info {
}

// we are under the assumption of a normal US calendar
NSCalendar *cal = [[NSCalendar alloc] initWithCalendarIdentifier:NSCalendarIdentifierGregorian];
NSCalendar *cal = [[NSCalendar alloc] initWithCalendarIdentifier:NSGregorianCalendar];
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.


NSDateComponents *expiryComponents = [[NSDateComponents alloc] init];
[expiryComponents setMonth:info.expiryMonth + 1]; // +1 to account for cards expiring "this month"
Expand Down
4 changes: 2 additions & 2 deletions Classes/CardIOViewController.mm
Original file line number Diff line number Diff line change
Expand Up @@ -504,7 +504,7 @@ - (void)cardIOView:(CardIOView *)cardIOView didScanCard:(CardIOCreditCardInfo *)
dataEntryViewController.manualEntry = self.context.suppressScannedCardImage;

CGPoint newCenter = [self.view convertPoint:cardIOView.transitionView.cardView.center fromView:cardIOView.transitionView];
newCenter.y -= NavigationBarHeightForOrientation([[UIApplication sharedApplication] statusBarOrientation]);
newCenter.y -= NavigationBarHeightForOrientation(self.interfaceOrientation);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Orientation stuff is tricky and often runs into issues with unexpected edge cases. I hope that you've tried every possible experiment!


dataEntryViewController.cardImageCenter = newCenter; // easier to pass this in than to recalculate it!
dataEntryViewController.cardImageSize = CGSizeApplyAffineTransform(cardIOView.transitionView.cardView.bounds.size, cardIOView.transitionView.cardView.transform);
Expand All @@ -529,7 +529,7 @@ - (void)cardIOView:(CardIOView *)cardIOView didScanCard:(CardIOCreditCardInfo *)
floatingCardView.layer.masksToBounds = YES;
floatingCardView.layer.borderColor = [UIColor grayColor].CGColor;
floatingCardView.layer.borderWidth = 2.0f;
floatingCardView.transform = CGAffineTransformMakeRotation(orientationToRotation([[UIApplication sharedApplication] statusBarOrientation]));
floatingCardView.transform = CGAffineTransformMakeRotation(orientationToRotation(self.interfaceOrientation));
floatingCardView.hidden = cardIOView.transitionView.hidden;

[floatingCardWindow addSubview:floatingCardView];
Expand Down
61 changes: 61 additions & 0 deletions icc.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,12 @@
92263E301B83B9B5003FE678 /* mz_ios.h in Headers */ = {isa = PBXBuildFile; fileRef = 849799A6159E5EF400527FF5 /* mz_ios.h */; };
929AD7811B8CA8FD00F6D18E /* CardIODetectionMode.h in Headers */ = {isa = PBXBuildFile; fileRef = 3E587F8A18C7E165000C1D3A /* CardIODetectionMode.h */; settings = {ATTRIBUTES = (Public, ); }; };
929AD7821B8CA8FD00F6D18E /* CardIOUtilities.h in Headers */ = {isa = PBXBuildFile; fileRef = 3ED8A876197DBDA900069761 /* CardIOUtilities.h */; settings = {ATTRIBUTES = (Public, ); }; };
9F7554391D5C152B004A7296 /* ocre.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 9F7554371D5C152B004A7296 /* ocre.cpp */; };
9F75543A1D5C152B004A7296 /* ocre.h in Headers */ = {isa = PBXBuildFile; fileRef = 9F7554381D5C152B004A7296 /* ocre.h */; };
9F75543C1D5C15AB004A7296 /* tessdata in Resources */ = {isa = PBXBuildFile; fileRef = 9F75543B1D5C15AB004A7296 /* tessdata */; };
9F75543D1D5C15AB004A7296 /* tessdata in Resources */ = {isa = PBXBuildFile; fileRef = 9F75543B1D5C15AB004A7296 /* tessdata */; };
9F7554401D5C16D1004A7296 /* liblept.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 9F75543E1D5C16D1004A7296 /* liblept.a */; };
9F7554411D5C16D1004A7296 /* libtesseract_all.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 9F75543F1D5C16D1004A7296 /* libtesseract_all.a */; };
A50A54C51BE306DB00B669FB /* UIImage+ImageEffects.m in Sources */ = {isa = PBXBuildFile; fileRef = 3ED00DA21BD8D60900FD2DB4 /* UIImage+ImageEffects.m */; };
A50A54C61BE3094500B669FB /* Accelerate.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 3ED00DA71BD8D78200FD2DB4 /* Accelerate.framework */; };
A50A54C71BE3095000B669FB /* Accelerate.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 3ED00DA71BD8D78200FD2DB4 /* Accelerate.framework */; };
Expand Down Expand Up @@ -795,6 +801,11 @@
92122C421B8C39D0004D705E /* CoreVideo.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = CoreVideo.framework; path = System/Library/Frameworks/CoreVideo.framework; sourceTree = SDKROOT; };
92263D701B83ACBB003FE678 /* CardIO.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = CardIO.framework; sourceTree = BUILT_PRODUCTS_DIR; };
92263E311B84283D003FE678 /* UIKit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = UIKit.framework; path = System/Library/Frameworks/UIKit.framework; sourceTree = SDKROOT; };
9F7554371D5C152B004A7296 /* ocre.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = ocre.cpp; sourceTree = "<group>"; };
9F7554381D5C152B004A7296 /* ocre.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ocre.h; sourceTree = "<group>"; };
9F75543B1D5C15AB004A7296 /* tessdata */ = {isa = PBXFileReference; lastKnownFileType = folder; path = tessdata; sourceTree = SOURCE_ROOT; };
9F75543E1D5C16D1004A7296 /* liblept.a */ = {isa = PBXFileReference; lastKnownFileType = archive.ar; name = liblept.a; path = tess_lib/liblept.a; sourceTree = "<group>"; };
9F75543F1D5C16D1004A7296 /* libtesseract_all.a */ = {isa = PBXFileReference; lastKnownFileType = archive.ar; name = libtesseract_all.a; path = tess_lib/libtesseract_all.a; sourceTree = "<group>"; };
A50A54AD1BE2F7A800B669FB /* AdHoc.xcconfig */ = {isa = PBXFileReference; lastKnownFileType = text.xcconfig; name = AdHoc.xcconfig; path = build_configs/AdHoc.xcconfig; sourceTree = "<group>"; };
A50A54AE1BE2F7A800B669FB /* CardIO_Static_Library_AdHoc.xcconfig */ = {isa = PBXFileReference; lastKnownFileType = text.xcconfig; name = CardIO_Static_Library_AdHoc.xcconfig; path = build_configs/CardIO_Static_Library_AdHoc.xcconfig; sourceTree = "<group>"; };
A50A54AF1BE2F7A800B669FB /* CardIO_Static_Library_Debug.xcconfig */ = {isa = PBXFileReference; lastKnownFileType = text.xcconfig; name = CardIO_Static_Library_Debug.xcconfig; path = build_configs/CardIO_Static_Library_Debug.xcconfig; sourceTree = "<group>"; };
Expand Down Expand Up @@ -892,6 +903,8 @@
isa = PBXFrameworksBuildPhase;
buildActionMask = 2147483647;
files = (
9F7554401D5C16D1004A7296 /* liblept.a in Frameworks */,
9F7554411D5C16D1004A7296 /* libtesseract_all.a in Frameworks */,
A50A54C61BE3094500B669FB /* Accelerate.framework in Frameworks */,
92122C431B8C39D0004D705E /* CoreVideo.framework in Frameworks */,
92122C411B8C3986004D705E /* CoreGraphics.framework in Frameworks */,
Expand Down Expand Up @@ -1121,6 +1134,9 @@
0346CEDE157D87F500F99613 /* scan */ = {
isa = PBXGroup;
children = (
9F75543B1D5C15AB004A7296 /* tessdata */,
9F7554371D5C152B004A7296 /* ocre.cpp */,
9F7554381D5C152B004A7296 /* ocre.h */,
3ED9F6E11A23CF3200BD07F8 /* expiry_categorize.h */,
3ED9F6E01A23CF3200BD07F8 /* expiry_categorize.cpp */,
3ED9F6E31A23CF3200BD07F8 /* expiry_seg.h */,
Expand Down Expand Up @@ -1814,6 +1830,8 @@
29B97323FDCFA39411CA2CEA /* Frameworks */ = {
isa = PBXGroup;
children = (
9F75543E1D5C16D1004A7296 /* liblept.a */,
9F75543F1D5C16D1004A7296 /* libtesseract_all.a */,
92122C421B8C39D0004D705E /* CoreVideo.framework */,
92122C3F1B8C3976004D705E /* Security.framework */,
92122C3C1B8C395F004D705E /* QuartzCore.framework */,
Expand Down Expand Up @@ -2013,6 +2031,7 @@
isa = PBXHeadersBuildPhase;
buildActionMask = 2147483647;
files = (
9F75543A1D5C152B004A7296 /* ocre.h in Headers */,
929AD7811B8CA8FD00F6D18E /* CardIODetectionMode.h in Headers */,
929AD7821B8CA8FD00F6D18E /* CardIOUtilities.h in Headers */,
92263DCE1B83AD65003FE678 /* CardIO.h in Headers */,
Expand Down Expand Up @@ -2241,6 +2260,7 @@
isa = PBXResourcesBuildPhase;
buildActionMask = 2147483647;
files = (
9F75543D1D5C15AB004A7296 /* tessdata in Resources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand All @@ -2263,6 +2283,7 @@
A553B6F51BE32273006DF551 /* yak_icon~ipad.png in Resources */,
A553B6F61BE32273006DF551 /* card_io_logo_black.png in Resources */,
A553B6F71BE32273006DF551 /* RootViewController~ipad.xib in Resources */,
9F75543C1D5C15AB004A7296 /* tessdata in Resources */,
A553B6F81BE32273006DF551 /* [email protected] in Resources */,
A553B6F91BE32273006DF551 /* Default.png in Resources */,
A553B6FA1BE32273006DF551 /* [email protected] in Resources */,
Expand Down Expand Up @@ -2440,6 +2461,7 @@
92263DDD1B83ADC0003FE678 /* CardIODataEntryViewController.m in Sources */,
92263DFA1B83AE19003FE678 /* CardIOCardOverlay.m in Sources */,
92263DDA1B83ADA3003FE678 /* CardIOCreditCardNumber.mm in Sources */,
9F7554391D5C152B004A7296 /* ocre.cpp in Sources */,
92263E151B83AF13003FE678 /* CardIOCVVTextFieldDelegate.m in Sources */,
92263E191B83AF13003FE678 /* CardIONumbersTextFieldDelegate.m in Sources */,
92263E281B83B897003FE678 /* CardIOSectionBasedTableViewDelegate.m in Sources */,
Expand Down Expand Up @@ -2577,41 +2599,80 @@
isa = XCBuildConfiguration;
baseConfigurationReference = A50A54BE1BE2FEEC00B669FB /* CardIO_Framework_Debug.xcconfig */;
buildSettings = {
HEADER_SEARCH_PATHS = (
"$(SRCROOT)/opencv_device/include",
"$(SRCROOT)/dmz",
"\"$(SRCROOT)/tess_include\"",
);
LIBRARY_SEARCH_PATHS = (
"$(inherited)",
"\"$(SRCROOT)/Classes\"",
"\"$(SRCROOT)/tess_lib\"",
"$(PROJECT_DIR)/tess_lib",
);
OTHER_LDFLAGS = "$(inherited)";
};
name = Debug;
};
92263D771B83ACBB003FE678 /* Release */ = {
isa = XCBuildConfiguration;
baseConfigurationReference = A50A54BF1BE2FEEC00B669FB /* CardIO_Framework_Release.xcconfig */;
buildSettings = {
HEADER_SEARCH_PATHS = (
"$(SRCROOT)/opencv_device/include",
"$(SRCROOT)/dmz",
"\"$(SRCROOT)/tess_include\"",
);
LIBRARY_SEARCH_PATHS = (
"$(inherited)",
"\"$(SRCROOT)/Classes\"",
"\"$(SRCROOT)/tess_lib\"",
"$(PROJECT_DIR)/tess_lib",
);
OTHER_LDFLAGS = "$(inherited)";
};
name = Release;
};
92263D781B83ACBB003FE678 /* AdHoc */ = {
isa = XCBuildConfiguration;
baseConfigurationReference = A50A54BD1BE2FEEC00B669FB /* CardIO_Framework_Adhoc.xcconfig */;
buildSettings = {
HEADER_SEARCH_PATHS = (
"$(SRCROOT)/opencv_device/include",
"$(SRCROOT)/dmz",
"\"$(SRCROOT)/tess_include\"",
);
LIBRARY_SEARCH_PATHS = (
"$(inherited)",
"\"$(SRCROOT)/Classes\"",
"\"$(SRCROOT)/tess_lib\"",
"$(PROJECT_DIR)/tess_lib",
);
OTHER_LDFLAGS = "$(inherited)";
};
name = AdHoc;
};
A553B7111BE32273006DF551 /* Debug */ = {
isa = XCBuildConfiguration;
baseConfigurationReference = A50A54B41BE2F7A800B669FB /* icc_Debug.xcconfig */;
buildSettings = {
ONLY_ACTIVE_ARCH = NO;
};
name = Debug;
};
A553B7121BE32273006DF551 /* Release */ = {
isa = XCBuildConfiguration;
baseConfigurationReference = A50A54B51BE2F7A800B669FB /* icc_Release.xcconfig */;
buildSettings = {
ONLY_ACTIVE_ARCH = NO;
};
name = Release;
};
A553B7131BE32273006DF551 /* AdHoc */ = {
isa = XCBuildConfiguration;
baseConfigurationReference = A50A54B31BE2F7A800B669FB /* icc_AdHoc.xcconfig */;
buildSettings = {
ONLY_ACTIVE_ARCH = NO;
};
name = AdHoc;
};
Expand Down
Loading