OpenCV:src不是数字元组 [英] OpenCV:src is not a numerical tuple

查看:222
本文介绍了OpenCV:src不是数字元组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经编写了一个有关使用python进行颜色检测的程序.但是,侵蚀"一词总是有错误.这是我程序的一部分.谢谢.

I've written a program about color detection by using python. But always there's an error around the 'Erode' sentence. Here's part of my program. Thank you.

# 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

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

您错过了第二个值dst,省略了表达式中的内容,您只会得到不是图像的retval值.

You miss the second value dst, omitting that in the expression, you're only getting the retval value which is not an image.

这篇关于OpenCV:src不是数字元组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆