9

I am using Tesseract in iOS 8 for an OCR based app but it incorrectly converts the division "÷" symbol in the image to a plus "+" sign.

For example, this image

Simple arithmetic expression

always converts to the text string "8+4+4". It should be "8+4÷4".

I've tried using different trained data language files "eng+equ", "ita", adding "÷" to the whitelist, setting the ocr_engine variable to cube, converting image to grayscale or black & white, upsizing the image by 2 and 4 times.

Everything I've tried always returns a plus "+" sign instead of a division "÷" symbol.

I tried using only the "equ" trained data file and that DOES return the division symbol correctly - but all other characters are then garbage.

I've been looking into this (Google, Stackoverflow) for several days and cannot figure it out.

How do I get Tesseract to include and recognize the division "÷" symbol?

UPDATE:

The best I have been able to do is to set the AVCaptureSession preset to high

AVCaptureSession *session = [[AVCaptureSession alloc] init];
session.sessionPreset = AVCaptureSessionPresetHigh;

The captured image above dimensions are then 676 × 405 pixels. Using Tesseract OCR UIImage category (image is named 'source') to binarize the image:

// Binarize the source image to improve contrast (using the UIImage category provided by TesseractOCR)
UIImage *blackAndWhiteImage = [source blackAndWhite];
[self.tesseract setImage:blackAndWhiteImage];

This will usually convert the division symbol to the text "-1-", but I've seen "-:-" and other numbers and uppercase characters between the minus signs.

I can check for that in the returned text. But then it is impossible to know whether to treat the returned text "8-1-2" as a true subtraction or 'maybe' division.

3
  • 3
    Unfortunately OCR is not perfect and Tesseract specifically will "blob" together pixels that it think may be a single character, compensating for poor picture quality at the cost of precision. Essentially Tesseract cannot tell if the division symbol is a poorly-printed "+" or an actual division symbol. Here's more reading on how Tesseract reads text. Nov 16, 2014 at 20:31
  • Thanks Morgan. I had wondered about that but it has no problems detecting and correctly converting characters like "i j : ;". Nov 17, 2014 at 2:55
  • You can try to open an issue here: github.com/gali8/Tesseract-OCR-iOS/issues May be here you'll get an answer.
    – arturdev
    Nov 20, 2014 at 7:46

5 Answers 5

5
+100

Train the or engine wit different fonts.

Here is the tool for training the engine. Have a look on this also

Or you can use JTessBoxEditor

3

Make sure your "white list" includes"÷" sign.

In swift, this will do it: tesseract.setVariableValue("0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ:;,.!-()#&÷", forKey: "tessedit_char_whitelist")

In objective-C, here is the code:

[tesseract setVariableValue:@"0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ:;,.!-()#&÷" forKey:@"tessedit_char_whitelist"];

You can customize the character set based on your needs.

1
  • I have already tried this and got the same results as not using the whitelist at all. Nov 25, 2014 at 13:06
1

It seems that symbol was not included in the existing data. You'd need to train for that symbol, and then use the resultant traineddata in combination with existing ones.

You can use a tool, such as jTessBoxEditor, to assist you in the training process.

0

You can also try and capture this ambiguity via the unicharambigs file. Read more https://github.com/tesseract-ocr/tesseract/blob/master/doc/unicharambigs.5.asc.

1       +       1      ÷    0

Tesseract would read it as "optionally (the trailing 0 in the above config) replace the 1 char sequence '+' with the 1 character sequence '÷'".

2
0

In Swift, changing engineMode works for me

let tesseract = G8Tesseract(language: "eng")!
tesseract.engineMode = .tesseractCubeCombined

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.