本文整理汇总了Python中cv2.FLOODFILL_FIXED_RANGE属性的典型用法代码示例。如果您正苦于以下问题:Python cv2.FLOODFILL_FIXED_RANGE属性的具体用法?Python cv2.FLOODFILL_FIXED_RANGE怎么用?Python cv2.FLOODFILL_FIXED_RANGE使用的例子?那么, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类cv2
的用法示例。
在下文中一共展示了cv2.FLOODFILL_FIXED_RANGE属性的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: update
# 需要导入模块: import cv2 [as 别名]
# 或者: from cv2 import FLOODFILL_FIXED_RANGE [as 别名]
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)
示例2: find_all_results
# 需要导入模块: import cv2 [as 别名]
# 或者: from cv2 import FLOODFILL_FIXED_RANGE [as 别名]
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
示例3: __init__
# 需要导入模块: import cv2 [as 别名]
# 或者: from cv2 import FLOODFILL_FIXED_RANGE [as 别名]
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)
示例4: find_all_template
# 需要导入模块: import cv2 [as 别名]
# 或者: from cv2 import FLOODFILL_FIXED_RANGE [as 别名]
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