【发布时间】:2020-12-23 05:36:15
【问题描述】:
我想从网上下载这张图片。 Julia中有没有办法避免将文件下载到磁盘然后将其重新加载,并将其直接加载到内存中? 例子: https://www.google.com/images/branding/googlelogo/2x/googlelogo_color_272x92dp.png
目前我可以做到这一点,这需要我将数据写入磁盘,然后将其加载回内存:
Using Images
Using HTTP
download("https://www.google.com/images/branding/googlelogo/2x/googlelogo_color_272x92dp.png", "google.png")
img = load("google.png")
julia> typeof(img)
Array{RGB{Normed{UInt8,8}},2}
我可以看到我期望的类型是一个 RGB 值数组
但是,如果我尝试直接使用 HTTP 发出请求,我会得到一个矢量,它似乎不容易转换为图像数组格式
r = HTTP.get("https://www.google.com/images/branding/googlelogo/2x/googlelogo_color_272x92dp.png")
julia> r.body
13504-element Array{UInt8,1}:
0x89
0x50
0x4e
0x47
0x0d
0x0a
0x1a
⋮
0x45
0x4e
0x44
0xae
0x42
0x60
0x82
直接将此图像数据转换为正确图像格式的最佳方法是什么?
【问题讨论】:
标签: arrays image io julia http-get