Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@lobstrio
Last active November 28, 2023 07:41
Show Gist options
  • Star 4 You must be signed in to star a gist
  • Fork 6 You must be signed in to fork a gist
  • Save lobstrio/8010d0a21c48b8c807f0c3820467ee0c to your computer and use it in GitHub Desktop.
Save lobstrio/8010d0a21c48b8c807f0c3820467ee0c to your computer and use it in GitHub Desktop.
Solving (simple) Captcha, using PyTesseract, PIL, and Python 3
#!/usr/bin/python3
# coding: utf-8
import pytesseract
import os
import argparse
try:
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
Arguments:
path (str):
path to the image to be processed
Return:
'textualized' image
"""
image = Image.open(path).convert('RGB')
image = ImageOps.autocontrast(image)
filename = "{}.png".format(os.getpid())
image.save(filename)
text = pytesseract.image_to_string(Image.open(filename))
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))
@deangelo200
Copy link

im going to try this today loll.

@fnipo
Copy link

fnipo commented Jun 25, 2021

doesn't work even for easy captchas

@elizatlawy
Copy link

Not working

@przemmaj
Copy link

przemmaj commented Oct 9, 2021

Good enough. Working for simple captchas. Thanks.

@whidy
Copy link

whidy commented Nov 28, 2023

Can only recognize some simple graphic/digit numbers, such as

captcha-solver

but, this image below failed:

text

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment