Skip to content

Instantly share code, notes, and snippets.

@SaschaHeyer
Created February 7, 2025 12:49
Show Gist options
  • Save SaschaHeyer/3a2da5ee0df76ee9570e583cebb54bdd to your computer and use it in GitHub Desktop.
Save SaschaHeyer/3a2da5ee0df76ee9570e583cebb54bdd to your computer and use it in GitHub Desktop.

Revisions

  1. SaschaHeyer created this gist Feb 7, 2025.
    23 changes: 23 additions & 0 deletions loadimagefromgs.py
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,23 @@
    from google.cloud import storage
    import cv2
    import tempfile

    # Initialize Cloud Storage client
    storage_client = storage.Client()
    bucket_name = "your-bucket-name"
    blob_name = "path/to/image.jpg"

    # Download to a temporary file
    bucket = storage_client.bucket(bucket_name)
    blob = bucket.blob(blob_name)

    with tempfile.NamedTemporaryFile(delete=True, suffix=".jpg") as temp_file:
    blob.download_to_filename(temp_file.name)

    # Read the image with cv2
    image = cv2.imread(temp_file.name)

    # Display or process the image
    cv2.imshow("Image", image)
    cv2.waitKey(0)
    cv2.destroyAllWindows()