0

说我有存储在对谷歌云存储GS以下URL画面标题sunset.jpg://例如桶/ testing_data如何在存储在Google云端存储中的文件上使用cv2.imread?

所以对于图像的完整URL为:

gs://example-bucket/testing_data/sunset.jpg 

如果然后我做类似的事情:

image = cv2.imread('gs://example-bucket/testing_data/sunset.jpg') 

但是,虽然这不会崩溃或失败没有图像加载。如何访问/提供正确的URL到cv2.imread来做到这一点?

回答

0
import cv2 
import numpy as np 
import urllib 

url = "https://i.stack.imgur.com/AVWX7.jpg"; 
resp = urllib.urlopen(url) 
image = np.asarray(bytearray(resp.read()), dtype="uint8") 
image = cv2.imdecode(image, cv2.IMREAD_COLOR) 

将gs转换为正常的URL。

bucket = 'example-bucket' 
file = 'sunset.jpg' 

gcs_url = 'https://%(bucket)s.storage.googleapis.com/%(file)s' % {'bucket':bucket, 'file':file} 

print gcs_url 
+0

不幸的是,这是行不通的。我的网址不只是任何网址,而是格式为“gs://”的谷歌云存储网址,所以当我尝试做这个建议时崩溃并且说IOError:[Errno url error]未知的url类型:'gs ' –

+0

@majorcoder - 尝试更新。 – VK321

相关问题