Python cv2.FLOODFILL_FIXED_RANGE Examples
The following are 6
code examples of cv2.FLOODFILL_FIXED_RANGE().
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: floodfill.py From OpenCV-Python-Tutorial with MIT License | 5 votes |
def update(dummy=None): if seed_pt is None: cv2.imshow('floodfill', img) return flooded = img.copy() mask[:] = 0 lo = cv2.getTrackbarPos('lo', 'floodfill') hi = cv2.getTrackbarPos('hi', 'floodfill') flags = connectivity if fixed_range: flags |= cv2.FLOODFILL_FIXED_RANGE cv2.floodFill(flooded, mask, seed_pt, (255, 255, 255), (lo,)*3, (hi,)*3, flags) cv2.circle(flooded, seed_pt, 2, (0, 0, 255), -1) cv2.imshow('floodfill', flooded)
Example #2
Source File: __init__.py From magicwand with MIT License | 5 votes |
def __init__(self, img, name="Magic Wand Selector", connectivity=4, tolerance=32): self.name = name h, w = img.shape[:2] self.img = img self.mask = np.zeros((h, w), dtype=np.uint8) self._flood_mask = np.zeros((h + 2, w + 2), dtype=np.uint8) self._flood_fill_flags = ( connectivity | cv.FLOODFILL_FIXED_RANGE | cv.FLOODFILL_MASK_ONLY | 255 << 8 ) # 255 << 8 tells to fill with the value 255 cv.namedWindow(self.name) self.tolerance = (tolerance,) * 3 cv.createTrackbar( "Tolerance", self.name, tolerance, 255, self._trackbar_callback ) cv.setMouseCallback(self.name, self._mouse_callback)
Example #3
Source File: floodfill.py From PyCV-time with MIT License | 5 votes |
def update(dummy=None): if seed_pt is None: cv2.imshow('floodfill', img) return flooded = img.copy() mask[:] = 0 lo = cv2.getTrackbarPos('lo', 'floodfill') hi = cv2.getTrackbarPos('hi', 'floodfill') flags = connectivity if fixed_range: flags |= cv2.FLOODFILL_FIXED_RANGE cv2.floodFill(flooded, mask, seed_pt, (255, 255, 255), (lo,)*3, (hi,)*3, flags) cv2.circle(flooded, seed_pt, 2, (0, 0, 255), -1) cv2.imshow('floodfill', flooded)
Example #4
Source File: floodfill.py From PyCV-time with MIT License | 5 votes |
def update(dummy=None): if seed_pt is None: cv2.imshow('floodfill', img) return flooded = img.copy() mask[:] = 0 lo = cv2.getTrackbarPos('lo', 'floodfill') hi = cv2.getTrackbarPos('hi', 'floodfill') flags = connectivity if fixed_range: flags |= cv2.FLOODFILL_FIXED_RANGE cv2.floodFill(flooded, mask, seed_pt, (255, 255, 255), (lo,)*3, (hi,)*3, flags) cv2.circle(flooded, seed_pt, 2, (0, 0, 255), -1) cv2.imshow('floodfill', flooded)
Example #5
Source File: template.py From Airtest with Apache License 2.0 | 4 votes |
def find_all_template(im_source, im_search, threshold=0.8, rgb=False, max_count=10): """根据输入图片和参数设置,返回所有的图像识别结果.""" # 第一步:校验图像输入 check_source_larger_than_search(im_source, im_search) # 第二步:计算模板匹配的结果矩阵res res = _get_template_result_matrix(im_source, im_search) # 第三步:依次获取匹配结果 result = [] h, w = im_search.shape[:2] while True: # 本次循环中,取出当前结果矩阵中的最优值 min_val, max_val, min_loc, max_loc = cv2.minMaxLoc(res) # 求取可信度: confidence = _get_confidence_from_matrix(im_source, im_search, max_loc, max_val, w, h, rgb) if confidence < threshold or len(result) > max_count: break # 求取识别位置: 目标中心 + 目标区域: middle_point, rectangle = _get_target_rectangle(max_loc, w, h) one_good_match = generate_result(middle_point, rectangle, confidence) result.append(one_good_match) # 屏蔽已经取出的最优结果,进入下轮循环继续寻找: # cv2.floodFill(res, None, max_loc, (-1000,), max(max_val, 0), flags=cv2.FLOODFILL_FIXED_RANGE) cv2.rectangle(res, (int(max_loc[0] - w / 2), int(max_loc[1] - h / 2)), (int(max_loc[0] + w / 2), int(max_loc[1] + h / 2)), (0, 0, 0), -1) return result if result else None
Example #6
Source File: template_matching.py From Airtest with Apache License 2.0 | 4 votes |
def find_all_results(self): """基于模板匹配查找多个目标区域的方法.""" # 第一步:校验图像输入 check_source_larger_than_search(self.im_source, self.im_search) # 第二步:计算模板匹配的结果矩阵res res = self._get_template_result_matrix() # 第三步:依次获取匹配结果 result = [] h, w = self.im_search.shape[:2] while True: # 本次循环中,取出当前结果矩阵中的最优值 min_val, max_val, min_loc, max_loc = cv2.minMaxLoc(res) # 求取可信度: confidence = self._get_confidence_from_matrix(max_loc, max_val, w, h) if confidence < self.threshold or len(result) > self.MAX_RESULT_COUNT: break # 求取识别位置: 目标中心 + 目标区域: middle_point, rectangle = self._get_target_rectangle(max_loc, w, h) one_good_match = generate_result(middle_point, rectangle, confidence) result.append(one_good_match) # 屏蔽已经取出的最优结果,进入下轮循环继续寻找: # cv2.floodFill(res, None, max_loc, (-1000,), max(max_val, 0), flags=cv2.FLOODFILL_FIXED_RANGE) cv2.rectangle(res, (int(max_loc[0] - w / 2), int(max_loc[1] - h / 2)), (int(max_loc[0] + w / 2), int(max_loc[1] + h / 2)), (0, 0, 0), -1) return result if result else None