Skip to content

Instantly share code, notes, and snippets.



Last active Sep 11, 2020
What would you like to do?
Solving (simple) Captcha, using PyTesseract, PIL, and Python 3
# coding: utf-8
import pytesseract
import os
import argparse
import Image, ImageOps, ImageEnhance, imread
except ImportError:
from PIL import Image, ImageOps, ImageEnhance
def solve_captcha(path):
Convert a captcha image into a text,
using PyTesseract Python-wrapper for Tesseract
path (str):
path to the image to be processed
'textualized' image
image ='RGB')
image = ImageOps.autocontrast(image)
filename = "{}.png".format(os.getpid())
text = pytesseract.image_to_string(
return text
if __name__ == '__main__':
argparser = argparse.ArgumentParser()
argparser.add_argument("-i", "--image", required=True, help="path to input image to be OCR'd")
args = vars(argparser.parse_args())
path = args["image"]
print('-- Resolving')
captcha_text = solve_captcha(path)
print('-- Result: {}'.format(captcha_text))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.