|
30 | 30 | # [START full_tutorial] |
31 | 31 | # [START imports] |
32 | 32 | import argparse |
33 | | -import sys |
34 | | -import time |
35 | 33 |
|
36 | | -from google.cloud import videointelligence_v1beta2 |
37 | | -from google.cloud.videointelligence_v1beta2 import enums |
| 34 | +from google.cloud import videointelligence |
38 | 35 | # [END imports] |
39 | 36 |
|
40 | 37 |
|
41 | 38 | def analyze_labels(path): |
42 | 39 | """ Detects labels given a GCS path. """ |
43 | 40 | # [START construct_request] |
44 | | - video_client = videointelligence_v1beta2.VideoIntelligenceServiceClient() |
45 | | - features = [enums.Feature.LABEL_DETECTION] |
46 | | - operation = video_client.annotate_video(path, features) |
| 41 | + video_client = videointelligence.VideoIntelligenceServiceClient() |
| 42 | + features = [videointelligence.enums.Feature.LABEL_DETECTION] |
| 43 | + operation = video_client.annotate_video(path, features=features) |
47 | 44 | # [END construct_request] |
48 | 45 | print('\nProcessing video for label annotations:') |
49 | 46 |
|
50 | 47 | # [START check_operation] |
51 | | - while not operation.done(): |
52 | | - sys.stdout.write('.') |
53 | | - sys.stdout.flush() |
54 | | - time.sleep(20) |
55 | | - |
| 48 | + result = operation.result(timeout=90) |
56 | 49 | print('\nFinished processing.') |
57 | 50 | # [END check_operation] |
58 | 51 |
|
59 | 52 | # [START parse_response] |
60 | | - results = operation.result().annotation_results[0] |
61 | | - |
62 | | - for i, segment_label in enumerate(results.segment_label_annotations): |
| 53 | + segment_labels = result.annotation_results[0].segment_label_annotations |
| 54 | + for i, segment_label in enumerate(segment_labels): |
63 | 55 | print('Video label description: {}'.format( |
64 | 56 | segment_label.entity.description)) |
65 | 57 | for category_entity in segment_label.category_entities: |
|
0 commit comments