当前位置: 首页>>代码示例>>Python>>正文


Python cv2.boxFilter方法代码示例

本文整理汇总了Python中cv2.boxFilter方法的典型用法代码示例。如果您正苦于以下问题:Python cv2.boxFilter方法的具体用法?Python cv2.boxFilter怎么用?Python cv2.boxFilter使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在cv2的用法示例。


在下文中一共展示了cv2.boxFilter方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: niBlackThreshold

# 需要导入模块: import cv2 [as 别名]
# 或者: from cv2 import boxFilter [as 别名]
def niBlackThreshold(  src,  blockSize,  k,  binarizationMethod= 0 ):
    mean = cv2.boxFilter(src,cv2.CV_32F,(blockSize, blockSize),borderType=cv2.BORDER_REPLICATE)
    sqmean = cv2.sqrBoxFilter(src, cv2.CV_32F, (blockSize, blockSize), borderType = cv2.BORDER_REPLICATE)
    variance = sqmean - (mean*mean)
    stddev  = np.sqrt(variance)
    thresh = mean + stddev * float(-k)
    thresh = thresh.astype(src.dtype)
    k = (src>thresh)*255
    k = k.astype(np.uint8)
    return k


# cv2.imshow() 
开发者ID:fanghon,项目名称:lpr,代码行数:15,代码来源:niblack_thresholding.py

示例2: _process

# 需要导入模块: import cv2 [as 别名]
# 或者: from cv2 import boxFilter [as 别名]
def _process(
        self,
        im,
        image_scale: Param(0.5, (0.05, 1.0)),
        filter_size: Param(2, (0, 15)),
        color_invert: Param(True),
        clip: Param(140, (0, 255)),
        **extraparams
    ):
        """ Optionally resizes, smooths and inverts the image

        :param im:
        :param state:
        :param filter_size:
        :param image_scale:
        :param color_invert:
        :return:
        """
        if image_scale != 1:
            im = cv2.resize(
                im, None, fx=image_scale, fy=image_scale, interpolation=cv2.INTER_AREA
            )
        if filter_size > 0:
            im = cv2.boxFilter(im, -1, (filter_size, filter_size))
        if color_invert:
            im = 255 - im
        if clip > 0:
            im = np.maximum(im, clip) - clip

        if self.set_diagnostic == "filtered":
            self.diagnostic_image = im

        return NodeOutput([], im) 
开发者ID:portugueslab,项目名称:stytra,代码行数:35,代码来源:preprocessing.py

示例3: main

# 需要导入模块: import cv2 [as 别名]
# 或者: from cv2 import boxFilter [as 别名]
def main():
    image = cv2.imread("../data/7.1.01.tiff", 1)

    '''
    # Kernal or Convolution matrix for Identity Filter

    kernal = np.array(([0, 0, 0],
                       [0, 1, 0],
                       [0, 0, 0]), np.float32)

    # Kernal or Convolution matrix for Edge Detection

    kernal = np.array(([-1, -1, -1],
                       [-1, 8, -1],
                       [-1, -1, -1]), np.float32)

    '''

    # Kernal or Convolution matrix for Box BLue Filter

    kernal = np.ones((5, 5), np.uint8) / 25
    output = cv2.filter2D(image, -1, kernal)

    # Low pass filters implementation
    box_blur = cv2.boxFilter(image, -1, (31, 31))
    simple_blur = cv2.blur(image, (21, 21))
    gaussian_blur = cv2.GaussianBlur(image, (51, 51), 0)

    cv2.imshow("Orignal Image", image)
    cv2.imshow("Filtered Image", output)

    cv2.imshow("Box Blur", box_blur)
    cv2.imshow("Simple Blur", simple_blur)
    cv2.imshow("Gaussian Blur", gaussian_blur)

    cv2.waitKey(0)
    cv2.destroyAllWindows() 
开发者ID:amarlearning,项目名称:Finger-Detection-and-Tracking,代码行数:39,代码来源:KernalFiltering.py


注:本文中的cv2.boxFilter方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。