如何解决在 Python 中迭代 Google Cloud Storage 对象
我在一个云存储桶中有大约 40,000 张图像,我需要使用 Python 检索它们以便从图像中制作视频。目前我在 Python 中使用 for 循环,40k 图像需要 2-3 小时。如何使用多处理来加快速度?
当前伪代码:
import cv2
from google.cloud import storage
frameSize = (1920,1080)
storage_client = storage.Client()
bucket_name = "name-of-my-bucket"
out = cv2.VideoWriter('output_video.mp4',cv2.VideoWriter_fourcc(*'MPEG'),2,frameSize,True)
blobs = storage_client.list_blobs(bucket_name)
for blob in blobs:
image_string = blob.download_as_text()
# Pre-processing the base64 string
image_string = image_string.split(",",1)[1]
# Decoding base64 string
nparr = np.frombuffer(base64.b64decode(image_string),np.uint8)
image = cv2.imdecode(nparr,cv2.IMREAD_COLOR)
image = cv2.rotate(image,cv2.ROTATE_180)
# Writing image to VideoWriter
out.write(image)
out.release()
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。