我運行此代碼如何從位圖圖像的RGB值獲取數組?
from PIL import Image
import numpy as np
im = Image.open("/Users/Hugo/green_leaves.jpg")
im.load()
height, widht = im.size
p = np.array([0,0,0])
for row in range(height):
for col in range(widht):
a = im.getpixel((row,col))
p = np.append(a.asarray())
但我收到以下錯誤
Traceback (most recent call last):
File "/Users/hugo/PycharmProjects/Meteo API/image.py", line 17, in <module>
p = np.append(a.asarray())
AttributeError: 'tuple' object has no attribute 'asarray'
你能幫助我嗎?
我不知道numpy,但'a'是內建的'tuple'類型,並沒有這樣的方法。它是一個數組的python等價物。 – 2rs2ts