Python cv2.pyrMeanShiftFiltering() Examples
The following are 3
code examples of cv2.pyrMeanShiftFiltering().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
cv2
, or try the search function
.
Example #1
Source File: ImageMiniLab.py From ImageMiniLab with GNU General Public License v3.0 | 6 votes |
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) # 轮廓发现
Example #2
Source File: RegionOfInterest.py From DoNotSnap with GNU General Public License v3.0 | 5 votes |
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)
Example #3
Source File: ImageMiniLab.py From ImageMiniLab with GNU General Public License v3.0 | 5 votes |
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) # 图像二值化