小编Pra*_*war的帖子

将 ndarray(OpenCV 中的图像)作为 .jpg 或 .png 上传到谷歌云存储

我有一个类似的问题,例如How to upload a bytes image on Google Cloud Storage from a Python script

我试过这个

from google.cloud import storage
import cv2
from tempfile import TemporaryFile
import google.auth
credentials, project = google.auth.default()
client = storage.Client()
# https://console.cloud.google.com/storage/browser/[bucket-id]/
bucket = client.get_bucket('document')
# Then do other things...
image=cv2.imread('/Users/santhoshdc/Documents/Realtest/15.jpg')
with TemporaryFile() as gcs_image:
    image.tofile(gcs_image)
    blob = bucket.get_blob(gcs_image)
    print(blob.download_as_string())
    blob.upload_from_string('New contents!')
    blob2 = bucket.blob('document/operations/15.png')

    blob2.upload_from_filename(filename='gcs_image')
Run Code Online (Sandbox Code Playgroud)

这是构成的错误

> Traceback (most recent call last):   File
> "/Users/santhoshdc/Documents/ImageShapeSize/imageGcloudStorageUpload.py",
> line 13, in <module>
>     blob = …
Run Code Online (Sandbox Code Playgroud)

python google-cloud-storage google-cloud-platform opencv3.0

3
推荐指数
1
解决办法
2119
查看次数