Skip to content

Instantly share code, notes, and snippets.

@lobstrio
Created April 14, 2023 19:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save lobstrio/da95d31bff3f83a5e95ee9daeb253107 to your computer and use it in GitHub Desktop.
Save lobstrio/da95d31bff3f83a5e95ee9daeb253107 to your computer and use it in GitHub Desktop.
Bypass a (simple) CAPTCHA with Python3 and pytesseract 🤖
import cv2
from pytesseract import image_to_string
# pip3 install opencv-python
# pip3 install pytesseract
# brew install tesseract
filename = 'lobstr.jpeg'
img = cv2.imread(filename)
gry = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
(h, w) = gry.shape[:2]
gry = cv2.resize(gry, (w*2, h*2))
cls = cv2.morphologyEx(gry, cv2.MORPH_CLOSE, None)
thr = cv2.threshold(cls, 0, 255, cv2.THRESH_BINARY | cv2.THRESH_OTSU)[1]
txt = image_to_string(thr)
print(txt)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment