Ejemplo n.º 1
0
def get_data(batch_count=10000,
             test_count=1000,
             height=CAPTCHA_HEIGHT,
             width=CAPTCHA_WIDTH):
    """
    获取训练图片组
    :param batch_count: default 60
    :param width: 验证码宽度
    :param height: 验证码高度
    :return: batch_x, batch_yc
    """

    batch_x = np.zeros([batch_count, height, width, CAPTCHA_CHANNEL])
    batch_y = np.zeros([batch_count, CAPTCHA_LEN * LEN])  #60*40

    test_x = np.zeros([test_count, height, width, CAPTCHA_CHANNEL])
    test_y = np.zeros([test_count, CAPTCHA_LEN * LEN])  #60*40
    for i in range(batch_count):  # 生成对应的训练集
        image, text = gen_captcha_text_and_image()

        batch_x[i, :] = image

        batch_y[i, :] = text2vec(text)  # 验证码文本的向量形式
    for i in range(test_count):  # 生成对应的训练集
        image, text = gen_captcha_text_and_image()

        test_x[i, :] = image
        test_y[i, :] = text2vec(text)  # 验证码文本的向量形式

    return batch_x, batch_y, test_x, test_y
Ejemplo n.º 2
0
def wrap_gen_captcha_text_and_image(shape=(40, 100, 3)):  # 修改
    '''
    返回特定shape图片
    :param shape:
    :return:
    '''
    while True:
        t, im = gen_captcha_text_and_image()
        if im.shape == shape: return t, im
Ejemplo n.º 3
0
def wrap_gen_captcha_text_and_image(shape=(60, 160, 3)):
    """
    返回特定shape图片
    :param shape:
    :return:
    """
    while True:
        t, im = gen_captcha_text_and_image()
        if im.shape == shape:
            return t, im
Ejemplo n.º 4
0
    def __init__(self):

        height, width = CAPTCHA_HEIGHT, CAPTCHA_WIDTH
        batch_x = np.zeros([10000, height, width, CAPTCHA_CHANNEL])
        batch_y = np.zeros([10000, CAPTCHA_LEN * LEN])  # 60*40

        test_x = np.zeros([1000, height, width, CAPTCHA_CHANNEL])
        test_y = np.zeros([1000, CAPTCHA_LEN * LEN])  # 60*40
        for i in range(10000):  # 生成对应的训练集
            image, text = gen_captcha_text_and_image()

            batch_x[i, :] = image

            batch_y[i, :] = text2vec(text)  # 验证码文本的向量形式
        for i in range(1000):  # 生成对应的训练集
            image, text = gen_captcha_text_and_image()

            test_x[i, :] = image
            test_y[i, :] = text2vec(text)  # 验证码文本的向量形式

        self.validation_data = test_x
        self.validation_labels = test_y
        self.train_data = batch_x
        self.train_labels = batch_y
Ejemplo n.º 5
0
    :param width:
    :return:
    """
    x = tf.placeholder(tf.float32, [None, height * width])
    keep_prob = tf.placeholder(tf.float32)
    y_conv = cnn_graph(x, keep_prob, (height, width))
    saver = tf.train.Saver()
    with tf.Session() as sess:
        saver.restore(sess, tf.train.latest_checkpoint('model/'))
        predict = tf.argmax(
            tf.reshape(y_conv,
                       [-1, CAPTCHA_LEN, len(CAPTCHA_LIST)]), 2)
        vector_list = sess.run(predict,
                               feed_dict={
                                   x: image_list,
                                   keep_prob: 1
                               })
        vector_list = vector_list.tolist()
        text_list = [vec2text(vector) for vector in vector_list]
        return text_list


if __name__ == '__main__':
    text, image = gen_captcha_text_and_image()
    img = Image.fromarray(image)
    image = convert2gray(image)
    image = image.flatten() / 255
    pre_text = captcha2text([image])
    print("验证码正确值:", text, ' 模型预测值:', pre_text)
    img.show()