Skip to content

Instantly share code, notes, and snippets.

@ZackAkil
Last active May 20, 2021 17:29
Show Gist options
  • Save ZackAkil/9046427f3a0087b99eabc363f1a43230 to your computer and use it in GitHub Desktop.
Save ZackAkil/9046427f3a0087b99eabc363f1a43230 to your computer and use it in GitHub Desktop.
Google Cloud Function code for Video Object Detection on Storage trigger.
from google.cloud import videointelligence
import time
video_client = videointelligence.VideoIntelligenceServiceClient()
OUTPUT_BUCKET = 'gs://YOUR OUTPUT BUCKET NAME/'
features = [
videointelligence.Feature.OBJECT_TRACKING
]
def hello_gcs(event, context):
print(event)
gcs_uri = 'gs://' + event['bucket'] + '/' + event['name']
just_file_name = event['name'].split('.')[0]
output_uri = OUTPUT_BUCKET + "{} - {}.json".format(just_file_name, time.time())
operation = video_client.annotate_video(
request={"features": features,
"input_uri": gcs_uri,
"output_uri": output_uri}
)
print("\nProcessing video for object detection annotations.")
google-cloud-videointelligence
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment