如何解决Python中的Google Cloud Video Intelligence API-无法对文件夹中的多个视频运行对象跟踪
我正在尝试在包含多个视频的文件夹上运行对象跟踪。我的存储桶中有5个视频,根据此处的文档,它建议使用通配符(*)。但是,当我运行整个脚本时,只有1个视频被注释,而不是包含5个视频的整个文件夹。另外,在我的GCS存储桶中没有将response2.json创建为output_uri。
要标识多个视频,视频URI可能在对象ID中包含通配符。支持的通配符:'*'匹配0个或多个字符; ‘?’以匹配1个字符。 https://googleapis.dev/python/videointelligence/latest/gapic/v1/types.html
这是我在input_uri代码中所做的:
gcs_uri = 'gs://video_intel/*'
如果您查看屏幕截图,它应该是存储区ID名称,并在同一文件夹中显示多个视频。
任何人都可以帮助解决这个问题。谢谢。
完整脚本:
import os
os.environ['GOOGLE_APPLICATION_CREDENTIALS']='poc-video-intelligence-da5d4d52cb97.json'
"""Object tracking in a video stored on GCS."""
from google.cloud import videointelligence
video_client = videointelligence.VideoIntelligenceServiceClient()
features = [videointelligence.enums.Feature.OBJECT_TRACKING]
gcs_uri = 'gs://video_intel/*'
output_uri = 'gs://video_intel/response2.json'
operation = video_client.annotate_video(input_uri=gcs_uri,features=features,output_uri=output_uri)
print("\nProcessing video for object annotations.")
result = operation.result(timeout=300)
print("\nFinished processing.\n")
# The first result is retrieved because a single video was processed.
object_annotations = result.annotation_results[0].object_annotations
for object_annotation in object_annotations:
print("Entity description: {}".format(object_annotation.entity.description))
if object_annotation.entity.entity_id:
print("Entity id: {}".format(object_annotation.entity.entity_id))
print(
"Segment: {}s to {}s".format(
object_annotation.segment.start_time_offset.seconds
+ object_annotation.segment.start_time_offset.nanos / 1e9,object_annotation.segment.end_time_offset.seconds
+ object_annotation.segment.end_time_offset.nanos / 1e9,)
)
print("Confidence: {}".format(object_annotation.confidence))
# Here we print only the bounding box of the first frame in the segment
frame = object_annotation.frames[0]
box = frame.normalized_bounding_box
print(
"Time offset of the first frame: {}s".format(
frame.time_offset.seconds + frame.time_offset.nanos / 1e9
)
)
print("Bounding box position:")
print("\tleft : {}".format(box.left))
print("\ttop : {}".format(box.top))
print("\tright : {}".format(box.right))
print("\tbottom: {}".format(box.bottom))
print("\n")
解决方法
请修改'gcs_uri ='gs:// video_intel / ''到gcs_uri ='gs:// video_intel / 。*'
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。