Skip to content

Commit 3cf2763

Browse files
dizcologyleahecole
authored andcommitted
update streaming samples [(#2215)](#2215)
1 parent 6e1d021 commit 3cf2763

File tree

1 file changed

+25
-12
lines changed

1 file changed

+25
-12
lines changed

videointelligence/samples/analyze/beta_snippets.py

Lines changed: 25 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -339,17 +339,23 @@ def stream_generator():
339339
print(response.error.message)
340340
break
341341

342-
# Get the time offset of the response.
343-
frame = response.annotation_results.label_annotations[0].frames[0]
344-
time_offset = frame.time_offset.seconds + frame.time_offset.nanos / 1e9
345-
print('{}s:'.format(time_offset))
342+
label_annotations = response.annotation_results.label_annotations
343+
344+
# label_annotations could be empty
345+
if not label_annotations:
346+
continue
347+
348+
for annotation in label_annotations:
349+
# Each annotation has one frame, which has a timeoffset.
350+
frame = annotation.frames[0]
351+
time_offset = frame.time_offset.seconds + \
352+
frame.time_offset.nanos / 1e9
346353

347-
for annotation in response.annotation_results.label_annotations:
348354
description = annotation.entity.description
349-
# Every annotation has only one frame
350355
confidence = annotation.frames[0].confidence
351356
# description is in Unicode
352-
print(u'\t{} (confidence: {})'.format(description, confidence))
357+
print(u'{}s: {} (confidence: {})'.format(
358+
time_offset, description, confidence))
353359
# [END video_streaming_label_detection_beta]
354360

355361

@@ -463,19 +469,26 @@ def stream_generator():
463469
print(response.error.message)
464470
break
465471

466-
# Get the time offset of the response.
467-
frame = response.annotation_results.object_annotations[0].frames[0]
468-
time_offset = frame.time_offset.seconds + frame.time_offset.nanos / 1e9
469-
print('{}s:'.format(time_offset))
472+
object_annotations = response.annotation_results.object_annotations
473+
474+
# object_annotations could be empty
475+
if not object_annotations:
476+
continue
477+
478+
for annotation in object_annotations:
479+
# Each annotation has one frame, which has a timeoffset.
480+
frame = annotation.frames[0]
481+
time_offset = frame.time_offset.seconds + \
482+
frame.time_offset.nanos / 1e9
470483

471-
for annotation in response.annotation_results.object_annotations:
472484
description = annotation.entity.description
473485
confidence = annotation.confidence
474486

475487
# track_id tracks the same object in the video.
476488
track_id = annotation.track_id
477489

478490
# description is in Unicode
491+
print('{}s'.format(time_offset))
479492
print(u'\tEntity description: {}'.format(description))
480493
print('\tTrack Id: {}'.format(track_id))
481494
if annotation.entity.entity_id:

0 commit comments

Comments
 (0)