-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行。哪行代碼是這個,你想在這裏做什麼? –