Beispiel #1
0
    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 getInterestBox(self, bkgImage):
     """
     获得感兴趣的区域box,box 是由 (left, upper, right, lower ) pixel coordinate tuple 来表示
     如果没有返回 None
     :param bkgImage: 通过cv2 读进来的图像对象
     """
     boxCornerPoint = self.getInterestBoxCornerPoint(bkgImage)
     if boxCornerPoint is None:
         return None
     box = ImageTool.getBoxFromBoxCorner(boxCornerPoint)
     return box
Beispiel #3
0
    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")