Skip to content

Commit

Permalink
update streaming samples [(#2215)](#2215)
Browse files Browse the repository at this point in the history
  • Loading branch information
dizcology authored and leahecole committed Sep 15, 2023
1 parent 6e1d021 commit 3cf2763
Showing 1 changed file with 25 additions and 12 deletions.
37 changes: 25 additions & 12 deletions videointelligence/samples/analyze/beta_snippets.py
Original file line number Diff line number Diff line change
Expand Up @@ -339,17 +339,23 @@ def stream_generator():
print(response.error.message)
break

# Get the time offset of the response.
frame = response.annotation_results.label_annotations[0].frames[0]
time_offset = frame.time_offset.seconds + frame.time_offset.nanos / 1e9
print('{}s:'.format(time_offset))
label_annotations = response.annotation_results.label_annotations

# label_annotations could be empty
if not label_annotations:
continue

for annotation in label_annotations:
# Each annotation has one frame, which has a timeoffset.
frame = annotation.frames[0]
time_offset = frame.time_offset.seconds + \
frame.time_offset.nanos / 1e9

for annotation in response.annotation_results.label_annotations:
description = annotation.entity.description
# Every annotation has only one frame
confidence = annotation.frames[0].confidence
# description is in Unicode
print(u'\t{} (confidence: {})'.format(description, confidence))
print(u'{}s: {} (confidence: {})'.format(
time_offset, description, confidence))
# [END video_streaming_label_detection_beta]


Expand Down Expand Up @@ -463,19 +469,26 @@ def stream_generator():
print(response.error.message)
break

# Get the time offset of the response.
frame = response.annotation_results.object_annotations[0].frames[0]
time_offset = frame.time_offset.seconds + frame.time_offset.nanos / 1e9
print('{}s:'.format(time_offset))
object_annotations = response.annotation_results.object_annotations

# object_annotations could be empty
if not object_annotations:
continue

for annotation in object_annotations:
# Each annotation has one frame, which has a timeoffset.
frame = annotation.frames[0]
time_offset = frame.time_offset.seconds + \
frame.time_offset.nanos / 1e9

for annotation in response.annotation_results.object_annotations:
description = annotation.entity.description
confidence = annotation.confidence

# track_id tracks the same object in the video.
track_id = annotation.track_id

# description is in Unicode
print('{}s'.format(time_offset))
print(u'\tEntity description: {}'.format(description))
print('\tTrack Id: {}'.format(track_id))
if annotation.entity.entity_id:
Expand Down

0 comments on commit 3cf2763

Please sign in to comment.