Пример #1
0
def getPredict(hps, mode, gasmeter_filename, save_file_name):
    xp = tf.placeholder(
        tf.float32,
        [None, captchaBoxHeight * captchaBoxWidth * gen.ImageDepth])
    yp = tf.placeholder(tf.float32,
                        [None, captchaCharacterLength * CHAR_SET_LEN])
    model = ResNetModel.ResNetModel(hps, xp, yp, mode, captchaBoxHeight,
                                    captchaBoxWidth, gen.ImageDepth)
    model.create_graph(captchaCharacterLength)

    with tf.Session(config=tf.ConfigProto(allow_soft_placement=True)) as sess:
        saver = tf.train.Saver()
        saver.restore(sess, save_file_name)

        # image = Image.open(gasmeter_filename)
        # image = image.resize((captchaBoxWidth,captchaBoxHeight), Image.BICUBIC)
        image = cv2.imread(gasmeter_filename)
        image = ImageTool.imageResize(image, captchaBoxWidth, captchaBoxHeight)

        if gen.ImageDepth == 1:
            image = ImageTool.convertImgBGR2Gray(image)
            # image = ImageTool.convertImgRGB2Gray(image)

        ImageTool.showImagePIL(image)

        images = ImageTool.repeatImage2Tensor(image, hps.batch_nums)

        feed_dict = {xp: images, model.is_training_ph: False}

        outputs = sess.run([model.outputs], feed_dict=feed_dict)
        text = get_predict_text(outputs)
    return text
def getPredict(hps, mode, gasmeter_filename, save_file_name):
    xp = tf.placeholder(
        tf.float32,
        [None, captchaBoxHeight * captchaBoxWidth * gen.ImageDepth])
    yp = tf.placeholder(tf.float32,
                        [None, captchaCharacterLength * CHAR_SET_LEN])
    model = ResNetModel.ResNetModel(hps, xp, yp, mode, captchaBoxHeight,
                                    captchaBoxWidth, gen.ImageDepth)
    model.create_graph(captchaCharacterLength)

    with tf.Session(config=tf.ConfigProto(allow_soft_placement=True)) as sess:
        saver = tf.train.Saver()
        saver.restore(sess, save_file_name)

        # images = gen.get_batch_gasmeter_digit_area_from_filename(gasmeter_filename, hps.batch_nums)
        image = cv2.imread(gasmeter_filename)
        # gasmeter = GasmeterStyle0(captchaBoxWidth,captchaBoxHeight,desImageDepth=gen.ImageDepth)
        gasmeter = GasmeterStyle1(captchaBoxWidth,
                                  captchaBoxHeight,
                                  desImageDepth=gen.ImageDepth)
        gasmeter.setImage(image)
        image = gasmeter.getRollerBlackArea()

        ImageTool.showImagePIL(image)

        images = ImageTool.repeatImage2Tensor(image, hps.batch_nums)

        feed_dict = {xp: images, model.is_training_ph: False}

        outputs = sess.run([model.outputs], feed_dict=feed_dict)
        text = get_predict_text(outputs)
    return text
Пример #3
0
def getPredict(hps, mode, save_file_name, gen):
    xp = tf.placeholder(
        tf.float32,
        [None, captchaBoxHeight * captchaBoxWidth * gen.ImageDepth])
    yp = tf.placeholder(tf.float32,
                        [None, captchaCharacterLength * CHAR_SET_LEN])
    model = ResNetModel.ResNetModel(hps, xp, yp, mode, captchaBoxHeight,
                                    captchaBoxWidth, gen.ImageDepth)
    model.create_graph(captchaCharacterLength)

    gen1 = GenImageGasMeterStyle1m1(captchaCharacterLength,
                                    captchaBoxWidth,
                                    captchaBoxHeight,
                                    imageDepth=1)
    gen2 = GenImageGasMeterStyle1m2(captchaCharacterLength,
                                    captchaBoxWidth,
                                    captchaBoxHeight,
                                    imageDepth=1)
    gen3 = GenImageGasMeterStyle1m3(captchaCharacterLength,
                                    captchaBoxWidth,
                                    captchaBoxHeight,
                                    imageDepth=1)

    gens = [gen1, gen2, gen3]

    with tf.Session(config=tf.ConfigProto(allow_soft_placement=True)) as sess:
        saver = tf.train.Saver()
        saver.restore(sess, save_file_name)

        while True:
            gen = random.choice(gens)
            oriText, image = gen.get_text_and_image()
            images = ImageTool.repeatImage2Tensor(image, hps.batch_nums)

            feed_dict = {xp: images, model.is_training_ph: False}

            outputs = sess.run([model.outputs], feed_dict=feed_dict)
            predictText = get_predict_text(outputs)

            title = "text:%s, predict:%s" % (oriText, predictText)

            ImageTool.showImagePIL(image, title)
            print(title)