コード例 #1
0
    def wrap_gen_captcha_text_and_image():
        while True:
            text, image = gen_captcha_text_and_image_new()

            if image.shape == image_shape:
                return text, image
コード例 #2
0
# -*- coding:utf-8 -*-
from gen_check_code import gen_captcha_text_and_image_new, gen_captcha_text_and_image
from gen_check_code import number
from test_check_code import get_test_captcha_text_and_image
import numpy as np
import tensorflow as tf

text, image = gen_captcha_text_and_image_new()
print("验证码图像channel:", image.shape)  # (60, 160, 3)
# 图像大小
IMAGE_HEIGHT = image.shape[0]
IMAGE_WIDTH = image.shape[1]
image_shape = image.shape
MAX_CAPTCHA = len(text)
print("验证码文本最长字符数", MAX_CAPTCHA)  # 验证码最长4字符; 我全部固定为4,可以不固定. 如果验证码长度小于4,用'_'补齐


# 把彩色图像转为灰度图像(色彩对识别验证码没有什么用)
# 度化是将三分量转化成一样数值的过程
def convert2gray(img):
    if len(img.shape) > 2:
        gray = np.mean(img, -1)
        # 上面的转法较快,正规转法如下
        # r, g, b = img[:,:,0], img[:,:,1], img[:,:,2]
        # gray = 0.2989 * r + 0.5870 * g + 0.1140 * b
        # int gray = (int) (0.3 * r + 0.59 * g + 0.11 * b);
        return gray
    else:
        return img