Question

This snippet of code is part of a program that turns pixels to black in an opencv image based on an HSV hue range (here, 180-250). Does somebody happen to understand why the code below raises the error exceptions.AttributeError:'tuple' object has no attribute all on the last line? 'image' is a numpy.ndarray (obtained with np.asarray(image[:,:]) from an opencv cvMat)

image=np.asarray(image[:,:])
hue=np.resize(image,(480,640,1))
hue[hue < 180]=0
hue[hue > 250]=0
hue2=np.resize(hue,(480,640,3))
image[np.where(hue2==[0,0,0]).all(axis=2)]=[0,0,0]

While the code

image=np.asarray(image[:,:])
image[np.where((np.not_equal(image,[0,0,0])).all(axis=2))]=[0,0,0]

works perfectly, since 'hue2' and 'image' are two numpy arrays of exact same dimensions?

Was it helpful?

Solution

It looks like misplaced braces. It should be

image[np.where((hue2==[0,0,0]).all(axis=2))]=[0,0,0]
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top