Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
make a captcha, jsut use it to generate data for cracking captcha.
#!/usr/bin/env python
# coding: utf-8
import string,random
import numpy as np
from captcha.image import ImageCaptcha
import matplotlib.pyplot as plt
from PIL import Image
number = [str(i) for i in range(0,10)]
loweralpha = [ _ for _ in string.lowercase[:26]]
upperalpha = [ _ for _ in string.uppercase[:26]]
def random_captcha_text( source = number+loweralpha+upperalpha, size=4):
captcha_text = []
for _ in range(size):
c = random.choice(source)
return captcha_text
def generate_captch_text_and_image():
image = ImageCaptcha()
captcha_text = random_captcha_text()
captcha_text = ''.join(captcha_text)
captcha = image.generate(captcha_text)
captcha_image =
captcha_image = np.array(captcha_image)
return captcha_text, captcha_image
if __name__ == '__main__':
text, image = generate_captch_text_and_image()
f = plt.figure()
ax = f.add_subplot(111)
ax.text(0.1,0.9,text,ha='center', va='center', transform=ax.transAxes)
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.