问题
Say I have a picture titled sunset.jpg stored at the following URL on google cloud storage gs://example-bucket/testing_data
so the full URL for the image is:
gs://example-bucket/testing_data/sunset.jpg
If I then do something like:
image = cv2.imread('gs://example-bucket/testing_data/sunset.jpg')
But while this doesn't crash or fail no image is loaded. How do I access/provide the right URL to cv2.imread to do this??
回答1:
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)
To convert gs to normal URL.
bucket = 'example-bucket'
file = 'sunset.jpg'
gcs_url = 'https://%(bucket)s.storage.googleapis.com/%(file)s' % {'bucket':bucket, 'file':file}
print gcs_url
来源:https://stackoverflow.com/questions/44211221/how-do-i-use-cv2-imread-on-a-file-stored-in-google-cloud-storage