本文整理汇总了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