title: Extracting code from photograph of T-shirt via OCR
body: <p>I recently saw someone with a T-shirt with some Perl code on the back. I took a photograph of it and cropped out the code:</p>
  
  <p><img src="https://i.imgur.com/FS7oo.jpg" alt="alt text"></p>
  
  <p>Next I tried to extract the code from the image via OCR, so I installed <a href="http://code.google.com/p/tesseract-ocr/" rel="noreferrer">Tesseract OCR</a> and the Python bindings for it, <a href="http://code.google.com/p/pytesser/" rel="noreferrer">pytesser</a>.</p>
  
  <p>Pytesser only works on TIFF images, so I converted the image in Gimp and entered the following code (Ubuntu 9.10):</p>
  
  <pre><code>&gt;&gt;&gt; from pytesser import *
  &gt;&gt;&gt; image = Image.open('code.tif')
  &gt;&gt;&gt; print image_to_string(image)
  Traceback (most recent call last):
    File "&lt;stdin&gt;", line 1, in &lt;module&gt;
    File "pytesser.py", line 30, in image_to_string
      util.image_to_scratch(im, scratch_image_name)
    File "util.py", line 7, in image_to_scratch
      im.save(scratch_image_name, dpi=(200,200))
    File "/usr/lib/python2.6/dist-packages/PIL/Image.py", line 1406, in save
      save_handler(self, fp, filename)
    File "/usr/lib/python2.6/dist-packages/PIL/BmpImagePlugin.py", line 197, in _save
      raise IOError("cannot write mode %s as BMP" % im.mode)
  IOError: cannot write mode RGBA as BMP
  &gt;&gt;&gt; r,g,b,a = image.split()
  &gt;&gt;&gt; img = Image.merge("RGB", (r,g,b))
  &gt;&gt;&gt; print image_to_string(img)
  Tesseract Open Source OCR Engine
  
       éi     _   l_` _ t  
    ’   ‘" fY`  
    {  W       IKQW
    ·  __·_  ‘ ·-»·      
         :W   Z  
    ··  I  A n   1   
             ;f        
       `    `      
  `T     .' V   _ ‘  
  I  {Z.; » ;,. , ;  y i-   4 : %:,,    
        `· »    V; ` ?    
  ‘,—·.    
  H***li¥v·•·}I§¢   ` _  »¢is5#__·¤G$++}§;“»‘7·
    71   ’    Q  {  NH IQ
    ytéggygi {     ;g¤qg;gm·;,g(g,,3) {3;;+-
     § {Jf**$d$ }‘$p•¢L#d¤ Sc}
    »   i `  i A1:
  </code></pre>
  
  <p>That's clearly gibberish that comes out of the OCR engine. So, my question is:</p>
  
  <ul>
  <li>What do I have to do to get better OCR results out of Tesseract?</li>
  <li>Or, does anybody else have better luck extracting the code from the above image in another way?</li>
  </ul>