Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

OpenCV:src is not a numerical tuple

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)
like image 721
user3910024 Avatar asked Aug 05 '14 10:08

user3910024


1 Answers

Try:

_,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 returns two values: http://docs.opencv.org/modules/imgproc/doc/miscellaneous_transformations.html#cv2.threshold

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

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

like image 123
patel deven Avatar answered Oct 21 '22 02:10

patel deven