title: Improving OCR performance on multi-paragraph scans
body: <p>I'm working on a project that involves extracting text scientific papers stored in PDF format.  For most papers, this is accomplished quite easily using PDFMiner, but some older papers store their text as large images.  In essence, a paper is scanned and that image file (typically PNG or JPEG) comprises the entire page.</p>
  
  <p>I tried using the Tesseract engine through it's <a href="http://code.google.com/p/python-tesseract/">python-tesseract</a> bindings, but the results are quite disappointing.</p>
  
  <p>Before diving into the questions I have with this library, I would like to mention that I'm open to suggestions for OCR libraries.  There seem to be few native python solutions.</p>
  
  <p><a href="http://dl.dropbox.com/u/6160029/1_Im0.jpeg">Here</a> is one such image (JPEG) on which I am trying to extract text.  I the exact code provided in the example snippets on the python-tesseract google code page I linked to above.  I should mention that the documentation is a bit sparse, so it's quite possible that one of the many options in my code is misconfigured.  Any advice (or links to in-depth tutorials) would be much appreciated.</p>
  
  <p><a href="http://dl.dropbox.com/u/6160029/1_Im0.txt">Here</a> is the output from my attempt at OCR.</p>
  
  <p><strong>My questions are as follows:</strong></p>
  
  <ol>
  <li>Is there anything suboptimal in the code I'm using?  Is there a better way of doing this?  A different library perhaps?</li>
  <li>What kind of preprocessing can I perform to improve detection?  The images are all B&amp;W, but should I perhaps set a threshold and set anything above it to a single-value black color  and everything below it to a null-value white color?  Anything else?</li>
  <li>A more specific question:  can performance be improved by performing OCR on single words?  If so, can anyone suggest a way of delimiting single words in an image file (e.g.: the one linked above) and extracting them into separate images which can be treated independently?</li>
  <li>Can the presence of graphs and other images embedded in the PDF page image interfere with OCR?  Should I remove these?  If so, can anyone suggest a method for removing them automatically?</li>
  </ol>
  
  <p><strong>EDIT:</strong>
  For simplicity, here is the code I used.</p>
  
  <pre><code>import tesseract
  api = tesseract.TessBaseAPI()
  api.Init(".","eng",tesseract.OEM_DEFAULT)
  api.SetPageSegMode(tesseract.PSM_AUTO)
  
  mImgFile = "eurotext.jpg"
  mBuffer=open(mImgFile,"rb").read()
  result = tesseract.ProcessPagesBuffer(mBuffer,len(mBuffer),api)
  print "result(ProcessPagesBuffer)=",result
  </code></pre>
  
  <p>And here is the alterative code (whose results are not shown in this question, although the performance appears to be quite similar).</p>
  
  <pre><code>import cv2.cv as cv
  import tesseract
  
  api = tesseract.TessBaseAPI()
  api.Init(".","eng",tesseract.OEM_DEFAULT)
  api.SetPageSegMode(tesseract.PSM_AUTO)
  
  image=cv.LoadImage("eurotext.jpg", cv.CV_LOAD_IMAGE_GRAYSCALE)
  tesseract.SetCvImage(image,api)
  text=api.GetUTF8Text()
  conf=api.MeanTextConf()
  </code></pre>
  
  <p>Could anyone explain the differences between these two snippets?</p>