2

I'm using the https://github.com/gali8/Tesseract-OCR-iOS/ to make an app that detects text on business cards.

I'm stuck at making the Tesseract detect the text in image.

If I pass the image through code, Tesseract is able to detect it. If I provide the image taken from the camera, tesseract is not able to recognize it.

-(void)startTess:(UIImage *)img{

 G8Tesseract *tesseract = [[G8Tesseract alloc] initWithLanguage:@"eng"];
 tesseract.delegate = self;
 tesseract.engineMode=G8OCREngineModeTesseractCubeCombined;

 // Optional: Limit the character set Tesseract should try to recognize from
 tesseract.charWhitelist = @"@.,()-,abcdefghijklmnopqrstuvwxyz0123456789";

 // Specify the image Tesseract should recognize on
 tesseract.image = [img g8_blackAndWhite];

 // Optional: Limit the area of the image Tesseract should recognize on to a rectangle
 CGRect tessRect = CGRectMake(0, 0, img.size.width, img.size.height);
 tesseract.rect = tessRect;

 // Optional: Limit recognition time with a few seconds
 tesseract.maximumRecognitionTime = 4.0;

 // Start the recognition
 [tesseract recognize];

 // Retrieve the recognized text
 NSLog(@"text %@", [tesseract recognizedText]);

 // You could retrieve more information about recognized text with that methods:
 NSArray *characterBoxes = [tesseract recognizedBlocksByIteratorLevel:G8PageIteratorLevelSymbol];
 NSArray *paragraphs = [tesseract recognizedBlocksByIteratorLevel:G8PageIteratorLevelParagraph];
 NSArray *characterChoices = tesseract.characterChoices;
 UIImage *imageWithBlocks = [tesseract imageWithBlocks:characterBoxes drawText:YES thresholded:NO];

 self.imgView.image = imageWithBlocks;

 NSString * result = [[characterBoxes valueForKey:@"description"] componentsJoinedByString:@"\n"];

 _txtView.text=result;


}

Result when image provided from .xcassets:

enter image description here

Result when image taken directly from the camera:

enter image description here

In both the cases, Tesseract is recognizing the empty space with some random characters. I marked that area in both the images (top-left portion of image).

I made sure that image taken from device camera has the orientation up, as some reported Tesseract doesn't recognize the image taken from camera as it has 180 degree shift.

UIImage *chosenImage = info[UIImagePickerControllerOriginalImage];

// Redraw the image (if necessary) so it has the corrent orientation:
if (chosenImage.imageOrientation != UIImageOrientationUp) {
    UIGraphicsBeginImageContextWithOptions(chosenImage.size, NO, chosenImage.scale);
    [chosenImage drawInRect:(CGRect){0, 0, chosenImage.size}];
    chosenImage = UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();
}

What is the best way of debugging this and going forward ?

I submitted an issue at git: https://github.com/gali8/Tesseract-OCR-iOS/issues/358

Edit:

I have changed the iterator level to G8PageIteratorLevelTextline, and now the image taken by device camera gives the following output:

enter image description here

Still it is not accurate. If someone can point out on how to improve this, it would be nice.

3
  • 1
    I suspect lack of preprocessing being the issue (have you tried github.com/tesseract-ocr/tesseract/wiki/ImproveQuality ?) What if you save your camera image and use it as input from xassets, would results be bad too? I believe if you will add at least binarization step into preprocessing - results would be much better. Commented Dec 23, 2017 at 9:34
  • thanks for the link, i will look into it! Commented Dec 25, 2017 at 16:50
  • Hi Teja, i didn't find the latest version of Tesseract,can you please share the sample of the above or steps to get Tesseract. Commented Aug 14, 2018 at 10:56

1 Answer 1

0

On the official github source of tesseract there are various preprocessing methods mentioned and along with those measures I would suggest using .tiff images instead of .jpg or .png because using any other kind of image other than tiff compresses the image and reduces it binarizing quality.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.