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


Python cv2.pyrMeanShiftFiltering方法代码示例

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


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

示例1: hough_circles

# 需要导入模块: import cv2 [as 别名]
# 或者: from cv2 import pyrMeanShiftFiltering [as 别名]
def hough_circles(self):
        src = self.cv_read_img(self.src_file)
        if src is None:
            return

        dst = cv.pyrMeanShiftFiltering(src, 10, 100)
        cimage = cv.cvtColor(dst, cv.COLOR_BGR2GRAY)
        circles = cv.HoughCircles(cimage, cv.HOUGH_GRADIENT, 1, 20, param1=50, param2=30, minRadius=0, maxRadius=0)
        circles = np.uint16(np.around(circles))
        for i in circles[0, :]:
            cv.circle(src, (i[0], i[1]), i[2], (0, 0, 255), 2)
            cv.circle(src, (i[0], i[1]), 2, (255, 0, 255), 2)

        self.decode_and_show_dst(src)

    # 轮廓发现 
开发者ID:itisyang,项目名称:ImageMiniLab,代码行数:18,代码来源:ImageMiniLab.py

示例2: roiMask

# 需要导入模块: import cv2 [as 别名]
# 或者: from cv2 import pyrMeanShiftFiltering [as 别名]
def roiMask(image, boundaries):
    scale = max([1.0, np.average(np.array(image.shape)[0:2] / 400.0)])
    shape = (int(round(image.shape[1] / scale)), int(round(image.shape[0] / scale)))

    small_color = cv2.resize(image, shape, interpolation=cv2.INTER_LINEAR)

    # reduce details and remove noise for better edge detection
    small_color = cv2.bilateralFilter(small_color, 8, 64, 64)
    small_color = cv2.pyrMeanShiftFiltering(small_color, 8, 64, maxLevel=1)
    small = cv2.cvtColor(small_color, cv2.COLOR_BGR2HSV)

    hue = small[::, ::, 0]
    intensity = cv2.cvtColor(small_color, cv2.COLOR_BGR2GRAY)

    edges = extractEdges(hue, intensity)
    roi = roiFromEdges(edges)
    weight_map = weightMap(hue, intensity, edges, roi)

    _, final_mask = cv2.threshold(roi, 5, 255, cv2.THRESH_BINARY)
    small = cv2.bitwise_and(small, small, mask=final_mask)

    kernel = cv2.getStructuringElement(cv2.MORPH_ELLIPSE, (4, 4))

    for (lower, upper) in boundaries:
        lower = np.array([lower, 80, 50], dtype="uint8")
        upper = np.array([upper, 255, 255], dtype="uint8")

        # find the colors within the specified boundaries and apply
        # the mask
        mask = cv2.inRange(small, lower, upper)
        mask = cv2.morphologyEx(mask, cv2.MORPH_CLOSE, kernel, iterations=3)
        mask = cv2.morphologyEx(mask, cv2.MORPH_OPEN, kernel, iterations=1)
        final_mask = cv2.bitwise_and(final_mask, mask)

    # blur the mask for better contour extraction
    final_mask = cv2.GaussianBlur(final_mask, (5, 5), 0)
    return (final_mask, weight_map, scale) 
开发者ID:AVGInnovationLabs,项目名称:DoNotSnap,代码行数:39,代码来源:RegionOfInterest.py

示例3: mean_shift_filter

# 需要导入模块: import cv2 [as 别名]
# 或者: from cv2 import pyrMeanShiftFiltering [as 别名]
def mean_shift_filter(self):
        src = self.cv_read_img(self.src_file)
        if src is None:
            return

        dst = cv.pyrMeanShiftFiltering(src, 10, 50)  # 均值偏移滤波
        self.decode_and_show_dst(dst)

    # 图像二值化 
开发者ID:itisyang,项目名称:ImageMiniLab,代码行数:11,代码来源:ImageMiniLab.py


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