top of page

Python - Text CAPTCHA - captcha


CAPTCHA / Completely Automated Public Turing test to tell Computers and Humans Apart / package is for authentication, provides entry to websites only for humans and blocks bots and machine learning attacks. It belongs to the theory of computational complexity, has been invented in 1997. It is used by banks, paypal, Google, digitalization of Newspapers, etc. There are many types and tests of CAPTCHA, text based, audio, mathematical, RE, image based, 3D. This example works with textual CAPTCHA example.


# install needed captcha package


pip install captcha


Requirement already satisfied: captcha in /srv/conda/envs/notebook/lib/python3.7/site-packages (0.3)

Requirement already satisfied: Pillow in /srv/conda/envs/notebook/lib/python3.7/site-packages (from captcha) (8.3.2)

Note: you may need to restart the kernel to use updated packages.


from captcha.image import ImageCaptcha


image = ImageCaptcha(width=280,height=90)


# generate captcha text


data = image.generate('MINIMUM')


image.write('MINIMUM', 'out.p')


'out.png'


'out.png'


# use the standard matplotlib package to display generated captcha, in grey


%pylab inline

import matplotlib.pyplot as plt

import matplotlib.image as mpimg

img = mpimg.imread('out.png')

# imgplot = plt.imshow(img)

# plt.show()


Populating the interactive namespace from numpy and matplotlib


from PIL import Image

img = Image.open('out.png').convert('LA')

img.save('greyscale.png')

img = mpimg.imread('greyscale.png')

imgplot = plt.imshow(img)

plt.show()









Resources:







24 views0 comments

Recent Posts

See All

Comments


bottom of page