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
def getRollerBox(self): """ 获得黑底白字滚轮区域box,并将该 box 赋值给 self._rollerBox """ rollerBoxWidthMax = 425 shape = self._image.shape mid = int(shape[0] / 2) quarter = int(shape[0] / 4) splitImageBox = (70, quarter, 170, mid) splitImageGray = ImageTool.getCropImageByBox(self._grayImage, splitImageBox) retval, otsuImage = ImageTool.getOTSUGrayImage(splitImageGray) otsuImage = ImageTool.convertImgGray2BGR(otsuImage) lower = (250, 250, 250) upper = (255, 255, 255) splitBoxCorner = ImageTool.getInterestBoxCornerPointByColor( otsuImage, lower, upper) splitBox = ImageTool.getBoxFromBoxCorner(splitBoxCorner) rollerBoxUp = int(quarter + splitBox[1]) rollerBoxDown = int(quarter + splitBox[3]) trollerBox = (0, rollerBoxUp, shape[1], rollerBoxDown) rollerImageGray = ImageTool.getCropImageByBox(self._grayImage, trollerBox) retval, otsuImage = ImageTool.getOTSUGrayImage(rollerImageGray) otsuImage = ImageTool.convertImgGray2BGR(otsuImage) trollerBoxCorner = ImageTool.getInterestBoxCornerPointByColor( otsuImage, lower, upper) trollerBox = ImageTool.getBoxFromBoxCorner(trollerBoxCorner) rollerBox = (trollerBox[0], rollerBoxUp + 1, trollerBox[2], rollerBoxDown - 1) getWidth = rollerBox[2] - rollerBox[0] if rollerBoxWidthMax < getWidth: rollerBox = (rollerBox[0], rollerBox[1], rollerBox[0] + rollerBoxWidthMax, rollerBox[3]) right = int(rollerBox[2] * 5 / 8) + 20 rollerBox = (rollerBox[0], rollerBox[1], right, rollerBox[3]) # ImageTool.showBoxInImageByBox(self._image,rollerBox) self._rollerBox = rollerBox return rollerBox
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 getLCDBox(self): """ """ shape = self._image.shape mid = int(shape[0] / 2) splitImageBox = (0, mid, shape[1], shape[0]) splitImageGray = ImageTool.getCropImageByBox(self._grayImage, splitImageBox) ImageTool.showImagePIL(splitImageGray) splitImage = ImageTool.getCropImageByBox(self._image, splitImageBox) retval, otsuImage = ImageTool.getOTSUGrayImage(splitImageGray) otsuImage = ImageTool.convertImgGray2BGR(otsuImage) lower = (250, 250, 250) upper = (255, 255, 255) lcdBoxCorner = ImageTool.getInterestBoxCornerPointByColor( otsuImage, lower, upper) lcdBox = ImageTool.getBoxFromBoxCorner(lcdBoxCorner) self._lcdBox = lcdBox ImageTool.showBoxInImageByBoxCornerPoint(splitImage, lcdBoxCorner, "lcd")