-1
我想要的图像检索的平均RGB值元组索引必须是整数,而不是元组
def DetectColour((x ,y) ,n, image):
r, g, b = 0, 0, 0
count = 0
for s in range(x, x+n+1):
for t in range(y, y+n+1):
pixlr, pixlg, pixlb = image[s, t]
r += pixlr
g += pixlg
b += pixlb
count += 1
return((r/count), (g/count), (b/count))
我估计,在东西此代码的问题,但我不知道该怎么修复
有问题的错误:
Traceback (most recent call last):
File "C:\Python27\Sound-o-Colour.py", line 74, in <module>
r, g, b = DetectColour((25, 25) ,5 ,image) #finds the average colour in the frame
File "C:\Python27\Sound-o-Colour.py", line 19, in DetectColour
pixlr, pixlg, pixlb = image[s, t] #Counts the pixels of each colour, red, green and blue
TypeError: tuple indices must be integers, not tuple
'image'似乎是一个元组,而不是你所期望的。检查如何调用此函数。 – user2357112
你期望索引'[s,t]'代表什么? – deceze
该消息告诉你问题发生在第19行。哪行代码是这个,你想在这里做什么? –