此代码段是程序的一部分,该程序根据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数组?

最佳答案

看起来好像放错了牙套。它应该是

image[np.where((hue2==[0,0,0]).all(axis=2))]=[0,0,0]

08-24 22:40
查看更多