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

相關問題