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:
https://en.wikipedia.org/wiki/CAPTCHA
https://eprints.lancs.ac.uk/id/eprint/126984/1/ccs18.pdf
https://link.springer.com/content/pdf/10.1007/3-540-39200-9_18.pdf
https://prowebscraper.com/blog/top-10-captcha-solving-services-compared/
https://www.w3.org/TR/turingtest/#the-captcha-context
https://pypi.org/project/captcha/
Comments