我正在尝试从 URL 读取图像(由 Google 的静态地图 API 提供)。
图像在浏览器中显示正常。
但是当我尝试使用 misc.imread 将它加载到数组中时,它似乎最终成为一个二维数组(即扁平化,没有 RGB 颜色)。
这是我正在使用的代码(我隐藏了我的 API 密钥):
from scipy import ndimage
from scipy import misc
import urllib2
import cStringIO
url = \
"https://maps.googleapis.com/maps/api/staticmap?maptype=satellite&" \
"center=37.530101,38.600062&" \
"zoom=14&" \
"size=256x278&" \
"key=...."
file = cStringIO.StringIO(urllib2.urlopen(url).read())
image = misc.imread(file)
print image.shape
(278, 256)
我所期望的是一个 3-d 形状数组 (278, 256, 3)。
也许它没有正确读取文件?
In [29]:
file.read()[:30]
Out[29]:
'\x89PNG\r\n\x1a\n\x00\x00\x00\rIHDR\x00\x00\x01\x00\x00\x00\x01\x16\x08\x03\x00\x00\x00\xbe'