python - 根据 HSV 色调范围将选定像素转为黑色

标签 python opencv image-processing numpy hsv

这段代码是一个程序的一部分,该程序根据 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/

相关文章:

python - 如何使用 pybind11 进行绑定(bind)?

python - 实现我自己的算法以缩放和旋转python中的图像

opencv - 在 openCv 中写入像素值大于 1 的浮点图像

c++ - cv::viz::Widget 是否可点击? (OpenCV C++)

python - 使用python将图像转换为矩阵

python - 通过复制 TesserCap 的斩波滤波器去除验证码图像的背景噪声

python - 尝试运行 Tornado main.py 时出现语法错误

python - 自定义 django-admin 模板

python - 将视频帧传送到 OpenCV 图像,然后传送到 FFmpeg

matlab - 扩展matlab中的subplot函数