img = cv2.imread('/home/Desktop/image/findgray1.jpg')
b = 0
g = 0
r = 0
count = 0
for i in range (img.shape[0]):
for j in range (img.shape[1]):
for c in range(img.shape[2]):
if img[i][j]==[[b],[g],[r]]:
count+=1
b+=1
g+=1
r+=1
print(count)
这是我的代码。我想获取 r=g=b
的像素值,例如:(0,0,0)
,(1,1,1)
.......(255,255,255)
值。
ValueError: The truth value of an array with more than one element is ambiguous. Use a.any() or a.all()
此代码运行无误并计算灰色像素:
import cv2
img = cv2.imread('test.png')
count = 0
for i in range(img.shape[0]):
for j in range(img.shape[1]):
if img[i][j][0] == img[i][j][1] == img[i][j][2]:
count+=1
print count
我是一名优秀的程序员,十分优秀!