Exemplo n.º 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
Exemplo n.º 2
0
    def getRollerBlackArea(self):
        rollerBox = self.getRollerBox()
        rollerImage = ImageTool.getCropImageByBox(self._image, rollerBox)

        rollerImage = ImageTool.imageResize(rollerImage, self._desWidth,
                                            self._desHeight)

        if self._desImageDepth == 1:
            rollerImage = ImageTool.convertImgBGR2Gray(rollerImage)
        self._rollerImage = rollerImage

        return self._rollerImage
    def getRollerBlackArea(self):
        if self._image is None:
            raise ValueError("应先通过setImage()函数设置image,然后获取感兴趣数据")

        blackMask = MaskTool.getBlackMaskBGR()
        blackImage = blackMask.getInterestImageAreaData(self._image)

        redMask = MaskTool.getRedMaskBGR()
        redBox = redMask.getInterestBox(blackImage)

        if redBox is not None:
            rollerBlackArea = ImageTool.removeRightArea(blackImage, redBox[0])
        else:
            rollerBlackArea = blackImage

        rollerBlackArea = ImageTool.imageResize(rollerBlackArea,
                                                self._desWidth,
                                                self._desHeight)
        if self._desImageDepth == 1:
            rollerBlackArea = ImageTool.convertImgBGR2Gray(rollerBlackArea)

        return rollerBlackArea