gpt4 book ai didi

python opencv。我想获得 r=b=g 的像素值

转载 作者:太空宇宙 更新时间:2023-11-03 21:25:46 24 4
gpt4 key购买 nike

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

关于python opencv。我想获得 r=b=g 的像素值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40648852/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com