Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

I have an image contain only numbers, and TextRecognize fail to recognize some numbers:

img=enter image description here;

TextRecognize[img]
(*826718*)

The documentation says that "The quality of recognized text may improve by enlarging the image", but no luck on this example

TextRecognize[ImageResize[img, Scaled[2]]]
(*826718*)

also tried different language, also no help

TextRecognize[ImageResize[img, Scaled[2]], Language -> "French"]
(*826718*)

I also tried Walfram|Alpha, it also gave the same results as Mathematica:

enter image description here

Are there some ways to solve the problem?

share|improve this question
1  
After answering, I noticed this is a possible duplicate of this post which has some useful comments attached. –  bobthechemist Jun 15 '13 at 2:00

2 Answers 2

up vote 12 down vote accepted

TextRecognize seems to be a work in progress, consider the following

Rasterize[Graphics[Text[Style["3", 100]]]] // TextRecognize
Rasterize[Graphics[Text[Style["a", 100]]]] // TextRecognize
Rasterize[Graphics[Text[Style["123", 100]]]] // TextRecognize
Rasterize[Graphics[Text[Style["1234", 100]]]] // TextRecognize
Rasterize[Graphics[Text[Style["hello", 100]]]] // TextRecognize
Rasterize[Graphics[Text[Style["hello 3", 100]]]] // TextRecognize

yields the following output

{nothing here}
{nothing here}
{nothing here}
1234
hello
hello 3

For reasons that are entirely unclear, single characters are not recognized as text, nor are numbers small "arrays" of numbers. Oddly enough, small numbers are recognized if preceeded with an actual word, making the following a terrible solution that nonetheless gives you the answer:

n = Import["http://i.stack.imgur.com/cPRrY.png"];
pretext = Rasterize["hello ", RasterSize -> 175, ImageSize -> 40];
Row[{pretext, ImageResize[n, 1000]}] // Rasterize;
t = TextRecognize@ImageResize[%, Scaled[5]];
StringSplit@t

gives the output

{hello,3482671897}

Let's hope someone comes up with a better answer...

share|improve this answer
    
I like the last part. hello –  s0rce Jun 15 '13 at 2:07
    
+1 "work in progress" used to mean "it's currently being worked on"; I suspect it means the opposite in this case... :) –  cormullion Jun 15 '13 at 6:22

It works if you adjust the spacing between characters:

a = Array[1 &, 25]; 
TextRecognize@Image@Transpose[ Transpose@ImageData@Import@"http://i.stack.imgur.com/cPRrY.png" //.
                                                    {x__, Repeated[a, {3, 10}], y__} :> {x, a, a, y}]

(*"3482671897" *)
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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