Created
February 21, 2017 03:21
-
-
Save mylamour/1582400ab0e48df72cd46b660f34dfbb to your computer and use it in GitHub Desktop.
make a captcha, jsut use it to generate data for cracking captcha.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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) | |
captcha_text.append(c) | |
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 = Image.open(captcha) | |
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) | |
plt.imshow(image) | |
plt.show() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment