本文整理匯總了Python中cv2.THRESH_TOZERO_INV屬性的典型用法代碼示例。如果您正苦於以下問題:Python cv2.THRESH_TOZERO_INV屬性的具體用法?Python cv2.THRESH_TOZERO_INV怎麽用?Python cv2.THRESH_TOZERO_INV使用的例子?那麽, 這裏精選的屬性代碼示例或許可以為您提供幫助。您也可以進一步了解該屬性所在類cv2
的用法示例。
在下文中一共展示了cv2.THRESH_TOZERO_INV屬性的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: binary_image
# 需要導入模塊: import cv2 [as 別名]
# 或者: from cv2 import THRESH_TOZERO_INV [as 別名]
def binary_image(self,img):
# 應用5種不同的閾值方法
# ret, th1 = cv2.threshold(img_gray, 127, 255, cv2.THRESH_BINARY)
# ret, th2 = cv2.threshold(img_gray, 127, 255, cv2.THRESH_BINARY_INV)
# ret, th3 = cv2.threshold(img_gray, 127, 255, cv2.THRESH_TRUNC)
# ret, th4 = cv2.threshold(img_gray, 127, 255, cv2.THRESH_TOZERO)
# ret, th5 = cv2.threshold(img_gray, 127, 255, cv2.THRESH_TOZERO_INV)
# titles = ['Gray', 'BINARY', 'BINARY_INV', 'TRUNC', 'TOZERO', 'TOZERO_INV']
# images = [img_gray, th1, th2, th3, th4, th5]
# 使用Matplotlib顯示
# for i in range(6):
# plt.subplot(2, 3, i + 1)
# plt.imshow(images[i], 'gray')
# plt.title(titles[i], fontsize=8)
# plt.xticks([]), plt.yticks([]) # 隱藏坐標軸
# plt.show()
# Otsu閾值
_, th = cv2.threshold(img, 0, 255, cv2.THRESH_TOZERO + cv2.THRESH_OTSU)
cv2.imshow('Binary image', th)
return th
# 邊緣檢測
示例2: main
# 需要導入模塊: import cv2 [as 別名]
# 或者: from cv2 import THRESH_TOZERO_INV [as 別名]
def main():
threshold = 0
max_value = 255
image = cv2.imread("../data/7.1.08.tiff", 0)
# when applying OTSU threshold, set threshold to 0.
_, output1 = cv2.threshold(image, threshold, max_value, cv2.THRESH_BINARY + cv2.THRESH_OTSU)
_, output2 = cv2.threshold(image, threshold, max_value, cv2.THRESH_BINARY_INV + cv2.THRESH_OTSU)
_, output3 = cv2.threshold(image, threshold, max_value, cv2.THRESH_TOZERO + cv2.THRESH_OTSU)
_, output4 = cv2.threshold(image, threshold, max_value, cv2.THRESH_TOZERO_INV + cv2.THRESH_OTSU)
_, output5 = cv2.threshold(image, threshold, max_value, cv2.THRESH_TRUNC + cv2.THRESH_OTSU)
images = [image, output1, output2, output3, output4, output5]
titles = ["Orignals", "Binary", "Binary Inverse", "TOZERO", "TOZERO INV", "TRUNC"]
for i in range(6):
plt.subplot(3, 2, i + 1)
plt.imshow(images[i], cmap='gray')
plt.title(titles[i])
plt.show()
示例3: extract_color
# 需要導入模塊: import cv2 [as 別名]
# 或者: from cv2 import THRESH_TOZERO_INV [as 別名]
def extract_color( src, h_th_low, h_th_up, s_th, v_th ):
hsv = cv2.cvtColor(src, cv2.COLOR_BGR2HSV)
h, s, v = cv2.split(hsv)
if h_th_low > h_th_up:
ret, h_dst_1 = cv2.threshold(h, h_th_low, 255, cv2.THRESH_BINARY)
ret, h_dst_2 = cv2.threshold(h, h_th_up, 255, cv2.THRESH_BINARY_INV)
dst = cv2.bitwise_or(h_dst_1, h_dst_2)
else:
ret, dst = cv2.threshold(h, h_th_low, 255, cv2.THRESH_TOZERO)
ret, dst = cv2.threshold(dst, h_th_up, 255, cv2.THRESH_TOZERO_INV)
ret, dst = cv2.threshold(dst, 0, 255, cv2.THRESH_BINARY)
ret, s_dst = cv2.threshold(s, s_th, 255, cv2.THRESH_BINARY)
ret, v_dst = cv2.threshold(v, v_th, 255, cv2.THRESH_BINARY)
dst = cv2.bitwise_and(dst, s_dst)
dst = cv2.bitwise_and(dst, v_dst)
return dst
示例4: find_from_targeted
# 需要導入模塊: import cv2 [as 別名]
# 或者: from cv2 import THRESH_TOZERO_INV [as 別名]
def find_from_targeted(self, left, right):
# @TODO ignore red target - it is attacked and dead
template = cv2.imread('img/template_target.png', 0)
# print template.shape
roi = get_screen(
self.window_info["x"],
self.window_info["y"],
self.window_info["x"] + self.window_info["width"],
self.window_info["y"] + self.window_info["height"] - 300
)
roi = cv2.cvtColor(roi, cv2.COLOR_BGR2GRAY)
ret, th1 = cv2.threshold(roi, 224, 255, cv2.THRESH_TOZERO_INV)
ret, th2 = cv2.threshold(th1, 135, 255, cv2.THRESH_BINARY)
ret, tp1 = cv2.threshold(template, 224, 255, cv2.THRESH_TOZERO_INV)
ret, tp2 = cv2.threshold(tp1, 135, 255, cv2.THRESH_BINARY)
if not hasattr(th2, 'shape'):
return False
wth, hth = th2.shape
wtp, htp = tp2.shape
if wth > wtp and hth > htp:
res = cv2.matchTemplate(th2, tp2, cv2.TM_CCORR_NORMED)
if res.any():
min_val, max_val, min_loc, max_loc = cv2.minMaxLoc(res)
if max_val > 0.7:
return True
else:
return False
return False
示例5: mask_depth_image
# 需要導入模塊: import cv2 [as 別名]
# 或者: from cv2 import THRESH_TOZERO_INV [as 別名]
def mask_depth_image(depth_image, min_depth, max_depth):
""" mask out-of-range pixel to zero """
# print ('mask min max', min_depth, max_depth)
ret, depth_image = cv2.threshold(depth_image, min_depth, 100000, cv2.THRESH_TOZERO)
ret, depth_image = cv2.threshold(depth_image, max_depth, 100000, cv2.THRESH_TOZERO_INV)
depth_image = np.expand_dims(depth_image, 2)
return depth_image