我正在使用Opencv和python 3.6 我有一个具有此尺寸的图像:
depth = depth[0:240, 96:320]
所以是(240,224(的图像。图像是灰度的,我不想考虑像素强度的 2 个极值 0/255。
我的脚本中已经有一个循环。我认为我必须添加一行,像这样去除这些像素:
for b in depth: #cicle already existing
if b < 255 and b > 0: #added line
a = a+1
if a <= 121 and a >= 118:
for f in range(25, 223):
#print((x+b)%33)
soundArr[int((f-25)/6)] = soundArr[int((f-25)/6)]+b[f]
但我得到错误:
The truth value of an array with more than one element is ambiguous. Use a.any() or a.all()
那么如何删除这些像素呢?
如果我正确理解了这个问题,您可以使用numpy.where在深度图像中找到0和255的索引。然后,当您遍历图像时,您可以忽略来自numpy.where的结果。