0
$\begingroup$

Why am I getting blank output from TextRecognize for the following image? Is it because of the size of the image?

Neither am I getting output for this code:

x = Import["http://i.stack.imgur.com/RbqrD.jpg"];
TextRecognize[x]

nor for this one:

x = Import["http://i.stack.imgur.com/RbqrD.jpg"];
img = ImagePartition[x, {50, 69}];
MatrixForm[img];
p=img[[4,1]];
TextRecognize[p]

enter image description here

$\endgroup$
  • 1
    $\begingroup$ The way TextRecognize works is that it looks for groups of letters and guesses what the word is. So it's better for complete sentences, it's not good for individual letters. In this image especially the letters have a spatial arrangement TextRecognize cannot make sense of, so you are better off using ImageCorrelate and some sample letters (there are other Q&As about this). $\endgroup$ – C. E. Jul 9 '14 at 9:55
  • $\begingroup$ This is what you need. $\endgroup$ – C. E. Jul 9 '14 at 10:04
  • $\begingroup$ @Pickett This was also my first thought, but please see the section recognizing random characters from my answer. It's far from a complete answer though. $\endgroup$ – Jacob Akkerboom Jul 9 '14 at 17:48
  • $\begingroup$ @JacobAkkerboom I've seen TextRecognize being used like this before, for example here, but it's just not very good at it. For varying spatial distributions it is a much safer bet to use image correlation. $\endgroup$ – C. E. Jul 9 '14 at 18:25
  • $\begingroup$ If talking about spatial distribution then my second code should work properly in there this whole image is partitioned in 228 images of size 50x69 even there its not working $\endgroup$ – Abdullah Sorathia Jul 10 '14 at 3:22
2
$\begingroup$

It does not seem to recognise a single character in isolation. Even when I make it easier

y1 = ImageCrop[
   ImageCrop[img1, {100, 225}, {Left, Bottom}], {20, 25}, {Left, Top}];
y2 = ImageResize[y1, Scaled[10]];
y3 = Sharpen[y2];
y4 = Binarize[y3]

enter image description here

We still have that

TextRecognize@y4

gives "" . But there is hope, see the next section.

Recognizing multiple random characters

TextRecognize can find characters that do not make up words (I'm not sure if sentences matter here). A key element here is that the characters are regularly spaced. Let's get an example from the docs

wolframImg =
 ImageCrop[
  ImageCrop[
   ImageResize[
    Import[
     "http://reference.wolfram.com/language/ref/Files/TextRecognize.\
en/I_20.gif"]
    ,
    Scaled[5]
    ]
   ,
   {434, 240}
   ,
   {Left, Bottom}
   ]
  ,
  {408, Full}
  ,
  {Right, Top}
  ]

![enter image description here][2]

TextRecognize works reasonably well on this, as advertised.

TextRecognize[wolframImg]
ZSI-IC  
HSKRN  
CHKRVD

TextRecognize actually often gives quite a few false positives, when it is confident about a lot of (other) characters. This gave me the (silly) idea to compose this image with characters from your example.

y4Copies = Table[y4, {2}, {5}];
y5 = ImageAssemble[y4Copies];
y6 = ImageResize[y5, First@ImageDimensions@wolframImg];
compoImg = ImageAssemble[{{y6}, {wolframImg}}]

enter image description here

Now we can do

TextRecognize[compoImg]

which gives

EEEEE  
EEEEE  
ZSHC  
HSKRN  
CHKRVD
$\endgroup$
  • $\begingroup$ Yes Recognizes it successfully but tesseract in mathematica does not recognize single character it requires a whole word be it a random or logical..Still on my way to make it recognize single character $\endgroup$ – Abdullah Sorathia Jul 10 '14 at 3:56
1
$\begingroup$

Here is a shorter implementation of the idea of Jacob Akkerboom to assemble the characters in a line:

$Version
i = Import["https://i.stack.imgur.com/RbqrD.jpg"];
c = ComponentMeasurements[ColorNegate@Binarize@i, "Image", #"ConvexCoverage" < .9 &];
row = ImageAssemble[{ImagePad[ImageResize[#, {Automatic, 200}], 10] & /@ c[[;; , 2]]}]
TextRecognize[row]
"11.1.0 for Microsoft Windows (64-bit) (March 13, 2017)"

image

"ESEEEEEEEEEEEEEAAAAAAHHHHA"

The parameters 200 and 10 were carefully chosen by trial and error for achieving best possible recognition quality. And the latter is still leaves much to be desired. :(

Such poor quality of TextRecognize is especially surprising considering that Tesseract (which TextRecognize uses under the hood) shows excellent quality and does not require any assistance at all, as it can be checked for example using its Windows GUI gImageReader.

$\endgroup$
  • $\begingroup$ Actually I have given a report last time,but don't get any response till now. $\endgroup$ – yode Apr 3 '17 at 7:04
  • $\begingroup$ @yode Please inform us if you receive an answer from the tech support. I was playing with the image from this question in the hope that improvements of TextRecognize in version 11.1 make recognition of individual characters straightforward. But I see that it is not the case: RecognitionPrior -> "Character" improves nothing as well as the other option choices! It is a shame that WRI can't properly integrate Tesseract into Mathematica... $\endgroup$ – Alexey Popkov Apr 3 '17 at 7:52

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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