gpt4 book ai didi

python - OpenCV:src 不是数字元组

转载 作者:太空狗 更新时间:2023-10-29 20:10:56 25 4
gpt4 key购买 nike

我用 python 编写了一个关于颜色检测的程序。但是“Erode”这句话总是有错误。这是我的程序的一部分。谢谢。

# Convert the image to a Numpy array since most cv2 functions
# require Numpy arrays.
frame = np.array(frame, dtype=np.uint8)

threshold = 0.05
#blur the image
frame=cv2.blur(frame, (5,5))
#Convert from BGR to HSV
hsv = cv2.cvtColor(frame, cv2.COLOR_BGR2HSV)
#split into 3
h, s, v= cv2.split(hsv)
#red color
s = cv2.threshold(h, 15, 1, cv2.THRESH_BINARY_INV)#1-15,x>15 y=0
h = cv2.threshold(h, 245, 1, cv2.THRESH_BINARY)#245-255 x>245 y=1
h = h + s
kernel = cv2.getStructuringElement(cv2.MORPH_RECT,(3, 3))
h = cv2.erode(h, kernel)
v = cv2.sumElems(h)

最佳答案

尝试:

_,h = cv2.threshold(h, 245, 1, cv2.THRESH_BINARY) #245-255 x>245 y=1
_,s = cv2.threshold(h, 15, 1, cv2.THRESH_BINARY_INV) #1-15,x>15 y=0

cv2.threshold 返回两个值: http://docs.opencv.org/modules/imgproc/doc/miscellaneous_transformations.html#cv2.threshold

cv2.threshold(src, thresh, maxval, type[, dst]) → retval, dst

您错过了第二个值 dst,在表达式中省略了它,您只会得到 retval 值,它不是图像。

关于python - OpenCV:src 不是数字元组,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25137163/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com