【发布时间】:2018-04-04 15:59:57
【问题描述】:
我在 Google Cloud Storage 中有一个图像存储,我希望将它们读入 Datalab 中的 OpenCV。我可以找到有关如何阅读文本文件的信息,但找不到有关如何阅读图像的信息。我该怎么做呢?
【问题讨论】:
标签: python opencv google-cloud-platform google-cloud-storage google-cloud-datalab
我在 Google Cloud Storage 中有一个图像存储,我希望将它们读入 Datalab 中的 OpenCV。我可以找到有关如何阅读文本文件的信息,但找不到有关如何阅读图像的信息。我该怎么做呢?
【问题讨论】:
标签: python opencv google-cloud-platform google-cloud-storage google-cloud-datalab
我对 OpenCV 不是很熟悉,所以让我介绍一下 Datalab ⟷ GCS 部分,我希望这足以让您继续了解 OpenCV 部分。
在 Datalab 中,您可以使用两种不同的方法来访问 Google Cloud Storage 资源。它们都记录在这些 Jupyter 笔记本中(带有工作示例):使用 Storage commands (%%gcs) 访问 GCS 或使用 Storage APIs (google.datalab.storage) 访问 GCS。
我将提供一个使用存储命令的示例,但如果您愿意,请随时将其改编为 Datalab GCS Python 库。
# Imports
from google.datalab import Context
from IPython.display import Image
# Define the bucket and and an example image to read
bucket_path = "gs://BUCKET_NAME"
bucket_object = bucket_path + "/google.png"
# List all the objects in your bucket, and read the example image file
%gcs list --objects $bucket_path
%gcs read --object $bucket_object -v img
# Print the image content (see it is in PNG format) and show it
print(type(img))
img
Image(img)
使用我分享的这段代码,您可以对存储桶中的所有对象执行简单的对象列表,还可以读取示例 PNG 图像。将其内容存储在 Python 变量中,我希望您能够在 OpenCV 中使用它。
【讨论】: