from PIL import Image
img = Image.open('1.gif') # Your image here!
img = img.convert("RGBA")
width, height = img.size
pixdata = img.load()
# Make the letters bolder for easier recognition
for y in xrange(img.size[1]):
for x in xrange(img.size[0]):
if pixdata[x, y][0] < 90:
pixdata[x, y] = (0, 0, 0, 255)
for y in xrange(img.size[1]):
for x in xrange(img.size[0]):
if pixdata[x, y][1] < 136:
pixdata[x, y] = (0, 0, 0, 255)
for y in xrange(img.size[1]):
for x in xrange(img.size[0]):
if pixdata[x, y][2] > 0:
pixdata[x, y] = (255, 255, 255, 255)
img.save("input-black.gif", "GIF")
# Make the image bigger (needed for OCR)
im_orig = Image.open('input-black.gif')
big = im_orig.resize((width, height), Image.NEAREST)
ext = ".tif"
big.save("input-NEAREST" + ext)
# Pytesser
from pytesser import *
image = Image.open('input-NEAREST.tif')
print image_to_string(image)
Error:
Traceback (most recent call last):
File "C:\Users\user\Desktop\ten\ten.py", line 37, in <module>
print image_to_string(image)
File "C:\Python27\lib\site-packages\pytesser.py", line 31, in image_to_string
call_tesseract(scratch_image_name, scratch_text_name_root)
File "C:\Python27\lib\site-packages\pytesser.py", line 21, in call_tesseract
proc = subprocess.Popen(args)
File "C:\Python27\lib\subprocess.py", line 709, in __init__
errread, errwrite)
File "C:\Python27\lib\subprocess.py", line 957, in _execute_child
startupinfo)
WindowsError: [Error 2] The system cannot find the file specified