File structure of the ocr folder:

config ← Global config file

images: ← A possible storage area for the images

layoutfiles: ← Default storage area for the layout info of the forms generated

ocrforms: ← Default storage area for the xml forms

parseddata: ← Stores the parsed data

README ← Explains the howto


      | <- A class to parse the images and dump the data 
      | <- A class to handle the xforms and print them to pdf
      | <- A module with all the necessary functions for this entire ocr module
      | <- A script to parse the forms
      | <- A class to handle the reportlab api to print forms
      | <- A Class which describes a region in an image
      | <- A script to upload the files
      | <- A module which augments urllib2's functionality to upload files
      | <- Converts xforms to pdfs and uses the classes from formhandler and printform

tessdata: ← A folder where the necessary training info is stored to parse the scanned forms



      | <- Generates the training form
      | <- Trains the engine and stores the training data in the tessdata folder
      |-datafiles: <- Contains the input to generate training form and also the training form layout info files
      |-printedpdfs: <- Printed trainging forms reside here 



  1. Reportlab
  2. Core xml libs like xml.dom.minidom and xml.sax
  3. sane on unix and twain on Windows to support scanning
  4. Imaging-sane ( on Unix , not necessary on windows )
  5. urllib
  6. urllib2
  7. PIL >= 1.6

NOTE 1: All scripts have to be run from their respective directories at the moment.

NOTE 2: All the images used are to be provided in the .tif format.


Setting up the config file :


url =

The url to which data could be uploaded to


tessdata = ../

The folder from the sahanahcr folder where the tessdata folder is located

Step 1: The form generation The forms could be generated using the using the syntax as mentioned below. Incase the pdfname is not mentioned, it uses the uuid.pdf format to save the files. They are stored in the OCRforms folder in the main directory structure.

  Usage: python <xforminput> <OPTIONAL -> pdfoutput>

Step 2: Automated training Generation of the training forms. Uses the datainput.txt located in the “Training” folder which contains the necessary characters that are needed in the Training folder to generate the form and prints out the location details of the characters in a file, this goes into the 'Training' folder too but with the name “Trainingform.pdf” and a layout file with the name “Traininglayoutinfo”. The training form file is used for the automated boxfile generation

  Usage: python

The automation of the tesseract stores the necessary files in the tessdata folder with a <user> mentioned as prefix (which is generally the language) so that the while parsing the forms, when <user> is mentioned the specific trained data is used. They are stored as user_alph.* for the alphabet training and user_num.* for the numeral training

  Usage: python <trainingimage> <layout info of the form which is generally training form> <user>

Step 3: Scan the Image or Add the Image The Images could either be added to the folder images as described in the files structure (or be scanned directly) and the parsing of the images takes place with accordance to the the layout files located in the layout folder. The layout is chosen as per the uuid mentioned on the form as the layout file is stored in the form uuid_page.xml so everytime a page is scanned, the page number has to be specified too. <user> mentioned is the user whose training data has to be used.

  Usage: python <imageinput> <uuid of the form> <pagenumber> <user>

The parsed data is stored in the form of an xml in the folder parseddata in the global file structure. It is stored in the <uuid> folder in the parseddata folder. The images of the text are also cut out and stored. The images and text are also uploaded to a web folder via the url mentioned in the config file.


  1. Implement option parser instead of the regular files
  2. Someway to deal with the files with multiple pages, a way to store the data instead of the present way of storing data in two different xmls
  3. Do windows specific improvements and tests
  4. Barcodes on each page
  5. Make generic for all languages
  6. Improve the xforms parsing to use all the attributes of bind
  7. Check the improvement due to parsing digits and alphabets independently
  8. Try to check if individual character reading improves the accuracy rather than reading the entire string
  9. Should check if multiple fields have been selected for a select1 element


  • Just works with capital letters and digits now.
  • Cant really use the restricted attribute of bind in xforms for example, a question like are you pregnant is valid only for females and should be improve to use it and other attributes of bind.
  • Not accurate parsing.
  • Selects the field related to the first darkened bubble for a select1 element.

QR Code
QR Code ocr_userguidelines (generated for current page)