Created
February 23, 2010 22:11
-
-
Save ntulip/312779 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#http://www.bonsai-sec.com/blog/index.php/breaking-weak-captcha-in-26-lines-of-code/ | |
from PIL import Image | |
img = Image.open('input.gif') | |
img = img.convert("RGBA") | |
pixdata = img.load() | |
# Clean the background noise, if color != black, then set to white. | |
for y in xrange(img.size[1]): | |
for x in xrange(img.size[0]): | |
if pixdata[x, y] != (0, 0, 0, 255): | |
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((116, 56), Image.NEAREST) | |
ext = ".tif" | |
big.save("input-NEAREST" + ext) | |
# Perform OCR using pytesser library | |
from pytesser import * | |
image = Image.open('input-NEAREST.tif') | |
print image_to_string(image) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment