forked from gali8/Tesseract-OCR-iOS
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
nsoperation: Add simple implementation for RecognitionOperation
- Loading branch information
Showing
9 changed files
with
144 additions
and
26 deletions.
There are no files selected for viewing
23 changes: 23 additions & 0 deletions
23
Products/TesseractOCR.framework/Versions/A/Headers/RecognitionOperation.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
// | ||
// RecognitionOperation.h | ||
// Tesseract OCR iOS | ||
// | ||
// Created by Nikolay Volosatov on 12.12.14. | ||
// Copyright (c) 2014 Daniele Galiotto - www.g8production.com. All rights reserved. | ||
// | ||
|
||
#import <Foundation/Foundation.h> | ||
#import "TesseractOCR.h" | ||
|
||
typedef void(^RecognitionOperationComplete)(Tesseract *tesseract); | ||
|
||
@interface RecognitionOperation : NSOperation | ||
|
||
@property (nonatomic, strong, readonly) Tesseract *tesseract; | ||
@property (nonatomic, weak) id<TesseractDelegate> delegate; | ||
|
||
@property (nonatomic, assign, readonly) CGFloat progress; | ||
|
||
@property (nonatomic, copy) RecognitionOperationComplete recognitionCompleteBlock; | ||
|
||
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,5 +10,6 @@ | |
#define Tesseract_OCR_iOS_TesseractOCR_h | ||
|
||
#import "Tesseract.h" | ||
#import "RecognitionOperation.h" | ||
|
||
#endif |
Binary file modified
BIN
+9 Bytes
(100%)
Products/TesseractOCR.framework/Versions/A/Resources/Info.plist
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
// | ||
// RecognitionOperation.h | ||
// Tesseract OCR iOS | ||
// | ||
// Created by Nikolay Volosatov on 12.12.14. | ||
// Copyright (c) 2014 Daniele Galiotto - www.g8production.com. All rights reserved. | ||
// | ||
|
||
#import <Foundation/Foundation.h> | ||
#import "TesseractOCR.h" | ||
|
||
typedef void(^RecognitionOperationComplete)(Tesseract *tesseract); | ||
|
||
@interface RecognitionOperation : NSOperation | ||
|
||
@property (nonatomic, strong, readonly) Tesseract *tesseract; | ||
@property (nonatomic, weak) id<TesseractDelegate> delegate; | ||
|
||
@property (nonatomic, assign, readonly) CGFloat progress; | ||
|
||
@property (nonatomic, copy) RecognitionOperationComplete recognitionCompleteBlock; | ||
|
||
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
// | ||
// RecognitionOperation.m | ||
// Tesseract OCR iOS | ||
// | ||
// Created by Nikolay Volosatov on 12.12.14. | ||
// Copyright (c) 2014 Daniele Galiotto - www.g8production.com. All rights reserved. | ||
// | ||
|
||
#import "RecognitionOperation.h" | ||
|
||
@interface RecognitionOperation() <TesseractDelegate> | ||
|
||
@property (nonatomic, strong, readwrite) Tesseract *tesseract; | ||
@property (nonatomic, assign, readwrite) CGFloat progress; | ||
|
||
@end | ||
|
||
@implementation RecognitionOperation | ||
|
||
- (id)init | ||
{ | ||
self = [super init]; | ||
if (self != nil) { | ||
_tesseract = [[Tesseract alloc] init]; | ||
_tesseract.delegate = self; | ||
|
||
__weak __typeof(self) weakSelf = self; | ||
self.completionBlock = ^{ | ||
__strong __typeof(weakSelf) strongSelf = weakSelf; | ||
|
||
if (strongSelf.recognitionCompleteBlock != nil) { | ||
[[NSOperationQueue mainQueue] addOperationWithBlock:^{ | ||
strongSelf.recognitionCompleteBlock(strongSelf.tesseract); | ||
}]; | ||
} | ||
}; | ||
} | ||
return self; | ||
} | ||
|
||
- (void)main | ||
{ | ||
[self.tesseract recognize]; | ||
} | ||
|
||
- (void)progressImageRecognitionForTesseract:(Tesseract*)tesseract | ||
{ | ||
self.progress = self.tesseract.progress / 100.0f; | ||
if ([self.delegate respondsToSelector:@selector(progressImageRecognitionForTesseract:)]) { | ||
[self.delegate progressImageRecognitionForTesseract:tesseract]; | ||
} | ||
} | ||
|
||
- (BOOL)shouldCancelImageRecognitionForTesseract:(Tesseract*)tesseract | ||
{ | ||
BOOL canceled = self.cancelled; | ||
if ([self.delegate respondsToSelector:@selector(shouldCancelImageRecognitionForTesseract:)]) { | ||
canceled = canceled || [self.delegate shouldCancelImageRecognitionForTesseract:tesseract]; | ||
} | ||
return canceled; | ||
} | ||
|
||
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,5 +10,6 @@ | |
#define Tesseract_OCR_iOS_TesseractOCR_h | ||
|
||
#import "Tesseract.h" | ||
#import "RecognitionOperation.h" | ||
|
||
#endif |