gpt4 book ai didi

google-cloud-platform - 如何对 Google Cloud Storage 中存储的文件使用 cv2.imread?

转载 作者:行者123 更新时间:2023-12-02 03:55:05 24 4
gpt4 key购买 nike

假设我在 Google 云存储 gs://example-bucket/testing_data 上的以下 URL 中存储了一张名为 Sunset.jpg 的图片

所以图像的完整 URL 是:

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

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

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

但是,虽然这不会崩溃或失败,但不会加载图像。如何访问/提供 cv2.imread 的正确 URL 来执行此操作?

最佳答案

import cv2
import numpy as np
import urllib

url = "/image/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

关于google-cloud-platform - 如何对 Google Cloud Storage 中存储的文件使用 cv2.imread?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44211221/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com