Skip to content

Commit

Permalink
2.3 another bug fixing
Browse files Browse the repository at this point in the history
  • Loading branch information
Daniele authored and Daniele committed Jul 31, 2014
1 parent a788240 commit 8904c03
Show file tree
Hide file tree
Showing 8 changed files with 17 additions and 47 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,7 @@
//

#import <UIKit/UIKit.h>

typedef NS_ENUM(NSUInteger, RecognizeImageType) {
RecognizeImageTypeOriginal,
RecognizeImageTypeBlackAndWhite,
RecognizeImageTypeGrayScale
};
#import "UIImage+Filters.h"

@class Tesseract;

Expand All @@ -26,8 +21,6 @@ typedef NS_ENUM(NSUInteger, RecognizeImageType) {
@interface Tesseract : NSObject
+ (NSString *)version;

@property (nonatomic) RecognizeImageType recognizeImageType;

@property (nonatomic, strong) NSString* language;

@property (nonatomic, strong) UIImage *image;
Expand Down
Binary file modified Products/TesseractOCR.framework/Versions/A/TesseractOCR
Binary file not shown.
5 changes: 2 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -77,9 +77,8 @@ How to use
Tesseract* tesseract = [[Tesseract alloc] initWithLanguage:@"eng+ita"];
tesseract.delegate = self;

[tesseract setRecognizeImageType:RecognizeImageTypeBlackAndWhite]; //convert img to the RecognizeImageType
[tesseract setVariableValue:@"0123456789" forKey:@"tessedit_char_whitelist"]; //limit search
[tesseract setImage:[UIImage imageNamed:@"image_sample.jpg"]]; //image to check
[tesseract setImage:[[UIImage imageNamed:@"image_sample.jpg"] blackAndWhite]]; //image to check
[tesseract setRect:CGRectMake(20, 20, 100, 100)]; //optional: set the rectangle to recognize text in the image
[tesseract recognize];

Expand Down Expand Up @@ -108,7 +107,7 @@ Updates in this version

- Bug fixing.

- CoreImage filters: use <code>[tesseract setRecognizeImageType:RecognizeImageTypeBlackAndWhite];</code> to convert the UIImage to recognize into a RecognizeImageType
- CoreImage filters: use <code>[img blackAndWhite];</code> to convert the UIImage to recognize into a RecognizeImageType

- Rect: use <code>[tesseract setRect:CGRectMake(20, 20, 100, 100)]</code> to define the rect where the text must be recognized

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
//

#import "G8ViewController.h"
#import <TesseractOCR/UIImage+Filters.h>

@interface G8ViewController ()
{
Expand Down Expand Up @@ -52,22 +51,23 @@ - (void)viewDidLoad

-(void)recognizeImageWithTesseract:(UIImage *)img
{
//only for test//
UIImage *testb = [img blackAndWhite];

dispatch_async(dispatch_get_main_queue(), ^{
[self.activityIndicator startAnimating];

//only for test//
UIImage *testb = [img blackAndWhite];
self.imageToRecognize.image = testb;
//only for test//
});

Tesseract* tesseract = [[Tesseract alloc] initWithLanguage:@"eng+ita"];
Tesseract* tesseract = [[Tesseract alloc] initWithLanguage:@"ita"];
tesseract.delegate = self;

[tesseract setRecognizeImageType:RecognizeImageTypeBlackAndWhite]; //convert img to the RecognizeImageType
[tesseract setVariableValue:@"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ" forKey:@"tessedit_char_whitelist"]; //limit search

[tesseract setImage:img]; //image to check
[tesseract setImage:[img blackAndWhite]]; //image to check
//[tesseract setRect:CGRectMake(20, 20, 100, 100)]; //optional: set the rectangle to recognize text in the image
[tesseract recognize];

Expand Down
2 changes: 2 additions & 0 deletions Tesseract OCR iOS.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,7 @@
646772C318083B5600C85662 /* README.md */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; name = README.md; path = ../README.md; sourceTree = "<group>"; };
6490748A198A5A5600D728CC /* UIImage+Filters.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "UIImage+Filters.h"; sourceTree = "<group>"; };
6490748B198A5A5600D728CC /* UIImage+Filters.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "UIImage+Filters.m"; sourceTree = "<group>"; };
64907492198A6B9E00D728CC /* CoreImage.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = CoreImage.framework; path = System/Library/Frameworks/CoreImage.framework; sourceTree = SDKROOT; };
64A0292C17307C1D002B12E7 /* TesseractOCR.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = TesseractOCR.framework; sourceTree = BUILT_PRODUCTS_DIR; };
64A0292D17307C1D002B12E7 /* CoreFoundation.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = CoreFoundation.framework; path = System/Library/Frameworks/CoreFoundation.framework; sourceTree = SDKROOT; };
64A0293117307C1D002B12E7 /* TesseractOCR-Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = "TesseractOCR-Info.plist"; sourceTree = "<group>"; };
Expand Down Expand Up @@ -595,6 +596,7 @@
64F74CCB172FD75F0068E657 /* Frameworks */ = {
isa = PBXGroup;
children = (
64907492198A6B9E00D728CC /* CoreImage.framework */,
64F74D77172FD8E90068E657 /* UIKit.framework */,
64F74CCC172FD75F0068E657 /* Foundation.framework */,
64A0292D17307C1D002B12E7 /* CoreFoundation.framework */,
Expand Down
9 changes: 1 addition & 8 deletions TesseractOCR/Tesseract.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,7 @@
//

#import <UIKit/UIKit.h>

typedef NS_ENUM(NSUInteger, RecognizeImageType) {
RecognizeImageTypeOriginal,
RecognizeImageTypeBlackAndWhite,
RecognizeImageTypeGrayScale
};
#import "UIImage+Filters.h"

@class Tesseract;

Expand All @@ -26,8 +21,6 @@ typedef NS_ENUM(NSUInteger, RecognizeImageType) {
@interface Tesseract : NSObject
+ (NSString *)version;

@property (nonatomic) RecognizeImageType recognizeImageType;

@property (nonatomic, strong) NSString* language;

@property (nonatomic, strong) UIImage *image;
Expand Down
27 changes: 5 additions & 22 deletions TesseractOCR/Tesseract.mm
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,6 @@
#import "pix.h"
#import "ocrclass.h"

#import "UIImage+Filters.h"

namespace tesseract {
class TessBaseAPI;
};
Expand Down Expand Up @@ -195,31 +193,16 @@ - (void)setLanguage:(NSString *)language {

- (void)setImage:(UIImage *)image {

CGSize size = image.size;
int width = size.width;
int height = size.height;

if (width <= 0 || height <= 0) {
if (image == nil || image.size.width <= 0 || image.size.height <= 0) {
NSLog(@"WARNING: Image has not size!");
return;
}

UIImage *recognizeImage = nil;

switch (self.recognizeImageType) {
case RecognizeImageTypeBlackAndWhite:
recognizeImage = [image blackAndWhite];
break;
case RecognizeImageTypeGrayScale:
recognizeImage = [image grayScale];
break;
case RecognizeImageTypeOriginal:
default:
recognizeImage = image;
break;
}
self.imageSize = image.size; //self.imageSize used in the characterBoxes method
int width = self.imageSize.width;
int height = self.imageSize.height;

CGImage *cgImage = recognizeImage.CGImage;
CGImage *cgImage = image.CGImage;
CFDataRef data = CGDataProviderCopyData(CGImageGetDataProvider(cgImage));
_pixels = CFDataGetBytePtr(data);

Expand Down
2 changes: 1 addition & 1 deletion TesseractOCR/UIImage+Filters.m
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ @implementation UIImage (Filters)
-(UIImage *)blackAndWhite
{
CIImage *beginImage = [CIImage imageWithCGImage:self.CGImage];

CIImage *blackAndWhite = [CIFilter filterWithName:@"CIColorControls" keysAndValues:kCIInputImageKey, beginImage, @"inputBrightness", @0.0, @"inputContrast", @1.1, @"inputSaturation", @0.0, nil].outputImage;
CIImage *output = [CIFilter filterWithName:@"CIExposureAdjust" keysAndValues:kCIInputImageKey, blackAndWhite, @"inputEV", @0.7, nil].outputImage;

Expand Down

0 comments on commit 8904c03

Please sign in to comment.