Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 29b0060

Browse filesBrowse files
gguussJon Wayne Parrott
authored andcommitted
Adds tutorials using Cloud Client (GoogleCloudPlatform#930)
* Adds tutorials. * Removes unused enumerate
1 parent 10b9a90 commit 29b0060
Copy full SHA for 29b0060

File tree

Expand file treeCollapse file tree

12 files changed

+281
-1
lines changed
Filter options
Expand file treeCollapse file tree

12 files changed

+281
-1
lines changed
File renamed without changes.

‎video/cloud-client/analyze.py renamed to ‎video/cloud-client/analyze/analyze.py

Copy file name to clipboardExpand all lines: video/cloud-client/analyze/analyze.py
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ def analyze_labels(path):
7777
# first result is retrieved because a single video was processed
7878
results = operation.result().annotation_results[0]
7979

80-
for i, label in enumerate(results.label_annotations):
80+
for label in results.label_annotations:
8181
print('Label description: {}'.format(label.description))
8282
print('Locations:')
8383

‎video/cloud-client/labels/README.md

Copy file name to clipboard
+29Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
# Google Cloud Video Intelligence
2+
3+
Demonstrates label detection using the Google Cloud Video Intelligence API.
4+
5+
## Setup
6+
Please follow the [Set Up Your Project](https://cloud.google.com/video-intelligence/docs/getting-started#set_up_your_project)
7+
steps in the Quickstart doc to create a project and enable the Google Cloud
8+
Video Intelligence API. Following those steps, make sure that you
9+
[Set Up a Service Account](https://cloud.google.com/video-intelligence/docs/common/auth#set_up_a_service_account),
10+
and export the following environment variable:
11+
12+
```
13+
export GOOGLE_APPLICATION_CREDENTIALS=/path/to/your-project-credentials.json
14+
```
15+
16+
## Run the sample
17+
18+
Install [pip](https://pip.pypa.io/en/stable/installing) if not already installed.
19+
20+
Install the necessary libraries using pip:
21+
22+
```sh
23+
$ pip install -r requirements.txt
24+
```
25+
26+
Run the sample, for example:
27+
```
28+
python labels.py gs://cloud-ml-sandbox/video/chicago.mp4
29+
```

‎video/cloud-client/labels/labels.py

Copy file name to clipboard
+80Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
#!/usr/bin/env python
2+
3+
# Copyright 2017 Google Inc. All Rights Reserved.
4+
#
5+
# Licensed under the Apache License, Version 2.0 (the "License");
6+
# you may not use this file except in compliance with the License.
7+
# You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing, software
12+
# distributed under the License is distributed on an "AS IS" BASIS,
13+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
# See the License for the specific language governing permissions and
15+
# limitations under the License.
16+
17+
"""This application demonstrates how to perform basic operations with the
18+
Google Cloud Video Intelligence API.
19+
20+
For more information, check out the documentation at
21+
https://cloud.google.com/videointelligence/docs.
22+
"""
23+
24+
# [START full_tutorial]
25+
# [START imports]
26+
import argparse
27+
import sys
28+
import time
29+
30+
from google.cloud.gapic.videointelligence.v1beta1 import enums
31+
from google.cloud.gapic.videointelligence.v1beta1 import (
32+
video_intelligence_service_client)
33+
# [END imports]
34+
35+
36+
def analyze_labels(path):
37+
""" Detects labels given a GCS path. """
38+
# [START construct_request]
39+
video_client = (video_intelligence_service_client.
40+
VideoIntelligenceServiceClient())
41+
features = [enums.Feature.LABEL_DETECTION]
42+
operation = video_client.annotate_video(path, features)
43+
# [END construct_request]
44+
print('\nProcessing video for label annotations:')
45+
46+
# [START check_operation]
47+
while not operation.done():
48+
sys.stdout.write('.')
49+
sys.stdout.flush()
50+
time.sleep(20)
51+
52+
print('\nFinished processing.')
53+
# [END check_operation]
54+
55+
# [START parse_response]
56+
results = operation.result().annotation_results[0]
57+
58+
for label in results.label_annotations:
59+
print('Label description: {}'.format(label.description))
60+
print('Locations:')
61+
62+
for l, location in enumerate(label.locations):
63+
print('\t{}: {} to {}'.format(
64+
l,
65+
location.segment.start_time_offset,
66+
location.segment.end_time_offset))
67+
# [END parse_response]
68+
69+
70+
if __name__ == '__main__':
71+
# [START running_app]
72+
parser = argparse.ArgumentParser(
73+
description=__doc__,
74+
formatter_class=argparse.RawDescriptionHelpFormatter)
75+
parser.add_argument('path', help='GCS file path for label detection.')
76+
args = parser.parse_args()
77+
78+
analyze_labels(args.path)
79+
# [END running_app]
80+
# [END full_tutorial]
+32Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
#!/usr/bin/env python
2+
3+
# Copyright 2017 Google, Inc
4+
#
5+
# Licensed under the Apache License, Version 2.0 (the "License");
6+
# you may not use this file except in compliance with the License.
7+
# You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing, software
12+
# distributed under the License is distributed on an "AS IS" BASIS,
13+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
# See the License for the specific language governing permissions and
15+
# limitations under the License.
16+
17+
import os
18+
19+
import pytest
20+
21+
import labels
22+
23+
BUCKET = os.environ['CLOUD_STORAGE_BUCKET']
24+
LABELS_FILE_PATH = '/video/cat.mp4'
25+
26+
27+
@pytest.mark.slow
28+
def test_feline_video_labels(capsys):
29+
labels.analyze_labels(
30+
'gs://{}{}'.format(BUCKET, LABELS_FILE_PATH))
31+
out, _ = capsys.readouterr()
32+
assert 'Whiskers' in out
+1Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
https://storage.googleapis.com/videointelligence-alpha/videointelligence-python.zip
+29Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
# Google Cloud Video Intelligence
2+
3+
Demonstrates label detection using the Google Cloud Video Intelligence API.
4+
5+
## Setup
6+
Please follow the [Set Up Your Project](https://cloud.google.com/video-intelligence/docs/getting-started#set_up_your_project)
7+
steps in the Quickstart doc to create a project and enable the Google Cloud
8+
Video Intelligence API. Following those steps, make sure that you
9+
[Set Up a Service Account](https://cloud.google.com/video-intelligence/docs/common/auth#set_up_a_service_account),
10+
and export the following environment variable:
11+
12+
```
13+
export GOOGLE_APPLICATION_CREDENTIALS=/path/to/your-project-credentials.json
14+
```
15+
16+
## Run the sample
17+
18+
Install [pip](https://pip.pypa.io/en/stable/installing) if not already installed.
19+
20+
Install the necessary libraries using pip:
21+
22+
```sh
23+
$ pip install -r requirements.txt
24+
```
25+
26+
Run the sample, for example:
27+
```
28+
python shotchange.py gs://cloudmleap/video/googlework.mp4
29+
```
+1Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
https://storage.googleapis.com/videointelligence-alpha/videointelligence-python.zip
+76Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
#!/usr/bin/env python
2+
3+
# Copyright 2017 Google Inc. All Rights Reserved.
4+
#
5+
# Licensed under the Apache License, Version 2.0 (the "License");
6+
# you may not use this file except in compliance with the License.
7+
# You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing, software
12+
# distributed under the License is distributed on an "AS IS" BASIS,
13+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
# See the License for the specific language governing permissions and
15+
# limitations under the License.
16+
17+
"""This application demonstrates how to perform basic operations with the
18+
Google Cloud Video Intelligence API.
19+
20+
For more information, check out the documentation at
21+
https://cloud.google.com/videointelligence/docs.
22+
"""
23+
24+
# [START full_tutorial]
25+
# [START imports]
26+
import argparse
27+
import sys
28+
import time
29+
30+
from google.cloud.gapic.videointelligence.v1beta1 import enums
31+
from google.cloud.gapic.videointelligence.v1beta1 import (
32+
video_intelligence_service_client)
33+
# [END imports]
34+
35+
36+
def analyze_shots(path):
37+
""" Detects camera shot changes. """
38+
# [START construct_request]
39+
video_client = (video_intelligence_service_client.
40+
VideoIntelligenceServiceClient())
41+
features = [enums.Feature.SHOT_CHANGE_DETECTION]
42+
operation = video_client.annotate_video(path, features)
43+
# [END construct_request]
44+
print('\nProcessing video for shot change annotations:')
45+
46+
# [START check_operation]
47+
while not operation.done():
48+
sys.stdout.write('.')
49+
sys.stdout.flush()
50+
time.sleep(20)
51+
52+
print('\nFinished processing.')
53+
# [END check_operation]
54+
55+
# [START parse_response]
56+
shots = operation.result().annotation_results[0]
57+
58+
for note, shot in enumerate(shots.shot_annotations):
59+
print('Scene {}: {} to {}'.format(
60+
note,
61+
shot.start_time_offset,
62+
shot.end_time_offset))
63+
# [END parse_response]
64+
65+
66+
if __name__ == '__main__':
67+
# [START running_app]
68+
parser = argparse.ArgumentParser(
69+
description=__doc__,
70+
formatter_class=argparse.RawDescriptionHelpFormatter)
71+
parser.add_argument('path', help='GCS file path for label detection.')
72+
args = parser.parse_args()
73+
74+
analyze_shots(args.path)
75+
# [END running_app]
76+
# [END full_tutorial]
+32Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
#!/usr/bin/env python
2+
3+
# Copyright 2017 Google, Inc
4+
#
5+
# Licensed under the Apache License, Version 2.0 (the "License");
6+
# you may not use this file except in compliance with the License.
7+
# You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing, software
12+
# distributed under the License is distributed on an "AS IS" BASIS,
13+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
# See the License for the specific language governing permissions and
15+
# limitations under the License.
16+
17+
import os
18+
19+
import pytest
20+
21+
import shotchange
22+
23+
BUCKET = os.environ['CLOUD_STORAGE_BUCKET']
24+
SHOTS_FILE_PATH = '/video/gbikes_dinosaur.mp4'
25+
26+
27+
@pytest.mark.slow
28+
def test_shots_dino(capsys):
29+
shotchange.analyze_shots(
30+
'gs://{}{}'.format(BUCKET, SHOTS_FILE_PATH))
31+
out, _ = capsys.readouterr()
32+
assert 'Scene 1:' in out

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.