Last active
August 29, 2015 14:08
-
-
Save ajtulloch/6fa88d68c1de4fd0bdd3 to your computer and use it in GitHub Desktop.
This file contains 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
from PIL import Image | |
import pyocr | |
import pyocr.builders | |
import re | |
def captcha(image, question): | |
tool = pyocr.get_available_tools()[0] | |
lang = tool.get_available_languages()[0] | |
img = Image.open(image).quantize(colors=6) | |
txt = tool.image_to_string(img, lang=lang, builder=pyocr.builders.TextBuilder()) | |
return re.search(question, txt).group(1) | |
IMAGE = '/Users/tulloch/img.png' | |
PREFIX = "Please enter: (.*)" | |
print captcha(IMAGE, PREFIX) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment