當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。