Posts

Showing posts from November, 2012

Easy read capcha with Python

I need crack some easy captcha, so i written one script to do that. I used PIL lib to edit images, convert background to whitem character to black. And Pytesster used to make OCR: Optical Character Recognition.

from PIL import Image

img = Image.open('a.jpeg') # 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'…