这段代码是一个程序的一部分,该程序根据 HSV 色调范围(此处为 180-250)将 opencv 图像中的像素变成黑色。 有人碰巧明白为什么下面的代码会在最后一行引发错误 exceptions.AttributeError:'tuple' object has no attribute all 吗? 'image' 是一个 numpy.ndarray (使用 np.asarray(image[:,:]) 从 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]
虽然代码
image=np.asarray(image[:,:])
image[np.where((np.not_equal(image,[0,0,0])).all(axis=2))]=[0,0,0]
工作完美,因为“hue2”和“image”是两个尺寸完全相同的 numpy 数组?
最佳答案
看起来像是错位的牙套。应该是
image[np.where((hue2==[0,0,0]).all(axis=2))]=[0,0,0]
关于python - 根据 HSV 色调范围将选定像素转为黑色,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16878761/