Ejemplo 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
Ejemplo n.º 2
0
    def getLCDAreaData(image):
        """
        获取 LCD 区域图片数据
        :param image: cv2 读进来的图片对象
        """
        image = ImageTool.preProcessImage(image)
        blackMask = MaskTool.getBlackMaskBGR()
        image = blackMask.getInterestImageAreaData(image)

        shape = image.shape
        grayImage = ImageTool.convertImgBGR2Gray(image)
        mid = int(shape[0] / 2)
        splitImageBox = (0, mid, shape[1], shape[0])
        splitImageGray = ImageTool.getCropImageByBox(grayImage, splitImageBox)
        splitImage = ImageTool.getCropImageByBox(image, splitImageBox)

        # 显示剪切的 lcd 屏所在的下半屏灰度图
        ImageTool.showImagePIL(splitImageGray, "splitImageGray")

        retval, otsuImage = ImageTool.getOTSUGrayImage(splitImageGray)
        otsuImage = ImageTool.convertImgGray2BGR(otsuImage)

        lower = (250, 250, 250)
        upper = (255, 255, 255)
        lcdBoxCorner = ImageTool.getInterestBoxCornerPointByColor(
            otsuImage, lower, upper)
        lcdBox = LCDLightDetect.getMinBox(lcdBoxCorner)
        # ImageTool.showBoxInImageByBox(splitImage, lcdBox)

        lcdImage = ImageTool.getCropImageByBox(splitImage, lcdBox)
        return lcdImage
Ejemplo n.º 3
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
Ejemplo n.º 4
0
    def setImage(self, image):
        """
        设置要处理的图片
        :param image: 是cv2读进来的图片对象
        提取表头黑色背景区域图片保存到 self._image 域中,方便以后提取条形码、液晶屏、黑底白字滚轮区域数字
        """
        if image is None:
            raise ValueError("image is None")

        image = ImageTool.preProcessImage(image)

        # ImageTool.showImagePIL(image)

        super(GasmeterStyle1, self).setImage(image)
        blackMask = MaskTool.getBlackMaskBGR()
        self._image = blackMask.getInterestImageAreaData(self._image)

        self._grayImage = ImageTool.convertImgBGR2Gray(self._image)
Ejemplo n.º 5
0
    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
Ejemplo n.º 6
0
    def lcdLighted(lcdImage):
        """
        检测lcd 区域图片是否点亮,如果亮返回True,如果不亮返回False
        :param lcdImage: cv2 读进来的图片对象
        """
        lower = (0, 0, 0)
        upper = (50, 50, 50)

        blackBoxCorner = ImageTool.getInterestBoxCornerPointByColor(
            lcdImage, lower, upper)
        # 如果获得的 lcd 区域有黑色区域,说明没有点亮。
        if blackBoxCorner is not None:
            return False

        lcdImageGray = ImageTool.convertImgBGR2Gray(lcdImage)

        retval, otsuImage = ImageTool.getOTSUGrayImage(lcdImageGray)
        otsuImage = ImageTool.convertImgGray2BGR(otsuImage)

        notLcdBoxCorner = ImageTool.getInterestBoxCornerPointByColor(
            otsuImage, lower, upper)
        ImageTool.showImagePIL(lcdImage, "lcdimage")

        return notLcdBoxCorner is None