Skip to content

Commit ef8db57

Browse files
gguussJon Wayne Parrott
authored and
Jon Wayne Parrott
committed
Adds one more tutorial as well as fixes some copy/paste typos. (#933)
1 parent 1fde844 commit ef8db57

File tree

6 files changed

+145
-2
lines changed

6 files changed

+145
-2
lines changed

video/cloud-client/faces/README.md

Lines 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 face 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 faces.py gs://cloudmleap/video/googlework.mp4
29+
```

video/cloud-client/faces/faces.py

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
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 shot change detection 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_faces(path):
37+
# [START construct_request]
38+
""" Detects faces given a GCS path. """
39+
video_client = (video_intelligence_service_client.
40+
VideoIntelligenceServiceClient())
41+
features = [enums.Feature.FACE_DETECTION]
42+
operation = video_client.annotate_video(path, features)
43+
# [END construct_request]
44+
print('\nProcessing video for face 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+
# first result is retrieved because a single video was processed
57+
face_annotations = (operation.result().annotation_results[0].
58+
face_annotations)
59+
60+
for face_id, face in enumerate(face_annotations):
61+
print('Thumbnail size: {}'.format(len(face.thumbnail)))
62+
63+
for segment_id, segment in enumerate(face.segments):
64+
print('Track {}: {} to {}'.format(
65+
segment_id,
66+
segment.start_time_offset,
67+
segment.end_time_offset))
68+
# [END parse_response]
69+
70+
71+
if __name__ == '__main__':
72+
# [START running_app]
73+
parser = argparse.ArgumentParser(
74+
description=__doc__,
75+
formatter_class=argparse.RawDescriptionHelpFormatter)
76+
parser.add_argument('path', help='GCS file path for face detection.')
77+
args = parser.parse_args()
78+
79+
analyze_faces(args.path)
80+
# [END running_app]
81+
# [END full_tutorial]
Lines 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 faces
22+
23+
BUCKET = os.environ['CLOUD_STORAGE_BUCKET']
24+
FACES_FILE_PATH = '/video/googlework.mp4'
25+
26+
27+
@pytest.mark.slow
28+
def test_work_video_faces(capsys):
29+
faces.analyze_faces(
30+
'gs://{}{}'.format(BUCKET, FACES_FILE_PATH))
31+
out, _ = capsys.readouterr()
32+
assert 'Thumbnail' in out
Lines 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

video/cloud-client/shotchange/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Google Cloud Video Intelligence
22

3-
Demonstrates label detection using the Google Cloud Video Intelligence API.
3+
Demonstrates shot change detection using the Google Cloud Video Intelligence API.
44

55
## Setup
66
Please follow the [Set Up Your Project](https://cloud.google.com/video-intelligence/docs/getting-started#set_up_your_project)

video/cloud-client/shotchange/shotchange.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ def analyze_shots(path):
6868
parser = argparse.ArgumentParser(
6969
description=__doc__,
7070
formatter_class=argparse.RawDescriptionHelpFormatter)
71-
parser.add_argument('path', help='GCS file path for label detection.')
71+
parser.add_argument('path', help='GCS path for shot change detection.')
7272
args = parser.parse_args()
7373

7474
analyze_shots(args.path)

0 commit comments

Comments
 (0)