My favorites | Sign in
Project Home Downloads Wiki Issues Source
Search
for
README  
Contents of README from package
Featured
Updated Feb 4, 2010 by moke...@gmail.com
Introduction:
============
PyTesser is an Optical Character Recognition module for Python. It takes 
as input an image or image file and outputs a string.

PyTesser uses the Tesseract OCR engine (an Open Source project at Google), 
converting images to an accepted format and calling the Tesseract 
executable as an external script. A Windows executable is provided 
along with the Python scripts. The scripts should work in Linux as well. 

PyTesser:
http://code.google.com/p/pytesser/
Tesseract:
http://code.google.com/p/tesseract-ocr/


Dependencies:
=============
PIL is required to work with images in memory. PyTesser has been tested with Python 2.4 in Windows XP. 
http://www.pythonware.com/products/pil/


Installation:
==============
PyTesser has no installation functionality in this release.  Extract pytesser.zip
into directory with other scripts.  Necessary files are listed in File Dependencies below.  


Usage:
================================
>>> from pytesser import *
>>> im = Image.open('phototest.tif')
>>> text = image_to_string(im)
>>> print text
This is a lot of 12 point text to test the
ocr code and see if it works on all types
of file format.
The quick brown dog jumped over the
lazy fox. The quick brown dog jumped
over the lazy fox. The quick brown dog
jumped over the lazy fox. The quick
brown dog jumped over the lazy fox.

>>> try:
... 	text = image_file_to_string('fnord.tif', graceful_errors=False)
... except errors.Tesser_General_Exception, value:
... 	print "fnord.tif is incompatible filetype.  Try graceful_errors=True"
... 	print value
... 	
fnord.tif is incompatible filetype.  Try graceful_errors=True
Tesseract Open Source OCR Engine
read_tif_image:Error:Illegal image format:Compression
Tessedit:Error:Read of file failed:fnord.tif
Signal_exit 31 ABORT. LocCode: 3  AbortCode: 3

>>> text = image_file_to_string('fnord.tif', graceful_errors=True)
>>> print "fnord.tif contents:", text
fnord.tif contents: fnord

>>> text = image_file_to_string('fonts_test.png', graceful_errors=True)
>>> print text
12 pt
And Arnazwngw few dwscotheques provwde jukeboxes
Tames Amazmgly few dnscotheques pmvxde Jukeboxes
24 pt:
Arial: Amazingly few discotheques
provide jul<ebo><es.
Courier: Ama zimgly few
discotheque S provide
j u k e b ox e S .
Times: Amazingly few discotheques provide
jukeboxes.


File Dependencies:
============================================
pytesser.py	Main module for importing
util.py		Utility functions used by pytesser.py
errors.py	Interprets exceptions thrown by Tesseract
tesseract.exe	Executable called by pytesser.py
tessdata/	Resources used by tesseract.exe
Comment by LKinse...@gmail.com, Sep 11, 2007

awesome way to go

Comment by jjconti@gmail.com, May 20, 2010

Does it works on Linux?

Comment by ross.hen...@gmail.com, Jun 14, 2010

I don't believe so

Comment by abdulbi...@gmail.com, Jan 19, 2011

On Linux:

print image_to_string(image) Traceback (most recent call last):

File "<stdin>", line 1, in <module> File "pytesser.py", line 31, in image_to_string
call_tesseract(scratch_image_name, scratch_text_name_root)
File "pytesser.py", line 21, in call_tesseract
proc = subprocess.Popen(args)
File "/usr/lib/python2.6/subprocess.py", line 623, in init
errread, errwrite)
File "/usr/lib/python2.6/subprocess.py", line 1141, in execute_child
raise child_exception
OSError: 2? No such file or directory

Comment by Miles.w...@gmail.com, Jan 20, 2011

how to build & run on ubuntu 9.04: http://wenyue.me/blog/282 and PIL installation guide: http://wenyue.me/blog/278

It's less accurate when recognizing some simple pics, like this: http://ssh.iwenda.net/t.php

Comment by jasondho...@gmail.com, Apr 14, 2011

works fine for me on Ubuntu... you have to point to the full directory path of the image...

Comment by jffiori...@gmail.com, Aug 24, 2011

i got the same error than abdulbi...@gmail.com!

OSError 2 No sush file or directory

Exception

Comment by Neale.Ma...@gmail.com, Sep 11, 2011

Does it work on OS 10.6?

Comment by jabba.l...@gmail.com, Jan 23, 2012

Thanks, works great for me on Ubuntu. Only problem is Tesseract outputs the line "Tesseract Open Source OCR Engine" to the stderr. Here is a patch to suppress it. Modified lines are marked with '# Jabba':

def call_tesseract(input_filename, output_filename):
    devnull = open(os.devnull, 'w')    # Jabba
    args = [tesseract_exe_name, input_filename, output_filename]
    proc = subprocess.Popen(args, stderr=devnull)    # Jabba
    retcode = proc.wait()
    if retcode!=0:
        errors.check_for_errors()

Simply, stderr is redirected to /dev/null.


Sign in to add a comment
Powered by Google Project Hosting