本文整理匯總了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