【发布时间】:2015-04-30 00:57:38
【问题描述】:
我使用 OpenCV 读取了一张白色图片:
我在它上面应用这个阈值:
import cv2
# Read image
src = cv2.imread("threshold.png", cv2.CV_LOAD_IMAGE_GRAYSCALE)
# Set threshold and maxValue
thresh = 0
maxValue = 255
# Basic threshold example
th, dst = cv2.threshold(src, thresh, maxValue, cv2.THRESH_BINARY);
# Find Contours
contours, hierarchy=cv2.findContours(dst,cv2.RETR_TREE,cv2.CHAIN_APPROX_SIMPLE)
# Draw Contour
cv2.drawContours(dst,countours,-1,(255,255,255),3)
cv2.imshow("Contour",dst)
所以根据cv2.THRESH_BINRARY 阈值类型,我在逻辑上期望得到一张全白的图片。为什么 ?因为我设置了thresh=0和maxValue=255,所以我期望的结果是根据官方文档在这种情况下所说的逻辑:
但结果我得到了一张全黑的图片(dst 的像素设置为 0,即使它们大于src 图片中的thresh)
为什么会这样?我误会了什么?
【问题讨论】:
标签: python image python-2.7 opencv threshold