这段代码是程序的一部分,该程序根据HSV色调范围(此处为180-250)将opencv图像中的像素变为黑色。 是否有人碰巧理解为什么下面的代码会引发错误 exceptions.AttributeError:'tuple'对象在最后一行没有属性? 'image'是一个numpy.ndarray(从opencv cvMat获得np.asarray(image [:,:])
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数组?
答案 0 :(得分:2)
看起来像是错位的牙箍。它应该是
image[np.where((hue2==[0,0,0]).all(axis=2))]=[0,0,0]