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 2659c6b

Browse filesBrowse files
gguussJon Wayne Parrott
authored andcommitted
Adds quickstart (GoogleCloudPlatform#964)
1 parent 47c6a93 commit 2659c6b
Copy full SHA for 2659c6b

File tree

Expand file treeCollapse file tree

5 files changed

+215
-0
lines changed
Filter options
Expand file treeCollapse file tree

5 files changed

+215
-0
lines changed
+102Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
.. This file is automatically generated. Do not edit this file directly.
2+
3+
Google Cloud Video Intelligence API Python Samples
4+
===============================================================================
5+
6+
This directory contains samples for Google Cloud Video Intelligence API. `Google Cloud Video Intelligence API`_ allows developers to easily integrate feature detection in video.
7+
8+
9+
10+
11+
.. _Google Cloud Video Intelligence API: https://cloud.google.com/video-intelligence/docs
12+
13+
Setup
14+
-------------------------------------------------------------------------------
15+
16+
17+
Authentication
18+
++++++++++++++
19+
20+
Authentication is typically done through `Application Default Credentials`_,
21+
which means you do not have to change the code to authenticate as long as
22+
your environment has credentials. You have a few options for setting up
23+
authentication:
24+
25+
#. When running locally, use the `Google Cloud SDK`_
26+
27+
.. code-block:: bash
28+
29+
gcloud auth application-default login
30+
31+
32+
#. When running on App Engine or Compute Engine, credentials are already
33+
set-up. However, you may need to configure your Compute Engine instance
34+
with `additional scopes`_.
35+
36+
#. You can create a `Service Account key file`_. This file can be used to
37+
authenticate to Google Cloud Platform services from any environment. To use
38+
the file, set the ``GOOGLE_APPLICATION_CREDENTIALS`` environment variable to
39+
the path to the key file, for example:
40+
41+
.. code-block:: bash
42+
43+
export GOOGLE_APPLICATION_CREDENTIALS=/path/to/service_account.json
44+
45+
.. _Application Default Credentials: https://cloud.google.com/docs/authentication#getting_credentials_for_server-centric_flow
46+
.. _additional scopes: https://cloud.google.com/compute/docs/authentication#using
47+
.. _Service Account key file: https://developers.google.com/identity/protocols/OAuth2ServiceAccount#creatinganaccount
48+
49+
Install Dependencies
50+
++++++++++++++++++++
51+
52+
#. Install `pip`_ and `virtualenv`_ if you do not already have them.
53+
54+
#. Create a virtualenv. Samples are compatible with Python 2.7 and 3.4+.
55+
56+
.. code-block:: bash
57+
58+
$ virtualenv env
59+
$ source env/bin/activate
60+
61+
#. Install the dependencies needed to run the samples.
62+
63+
.. code-block:: bash
64+
65+
$ pip install -r requirements.txt
66+
67+
.. _pip: https://pip.pypa.io/
68+
.. _virtualenv: https://virtualenv.pypa.io/
69+
70+
Samples
71+
-------------------------------------------------------------------------------
72+
73+
quickstart
74+
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
75+
76+
77+
78+
To run this sample:
79+
80+
.. code-block:: bash
81+
82+
$ python quickstart.py
83+
84+
85+
86+
87+
The client library
88+
-------------------------------------------------------------------------------
89+
90+
This sample uses the `Google Cloud Client Library for Python`_.
91+
You can read the documentation for more details on API usage and use GitHub
92+
to `browse the source`_ and `report issues`_.
93+
94+
.. _Google Cloud Client Library for Python:
95+
https://googlecloudplatform.github.io/google-cloud-python/
96+
.. _browse the source:
97+
https://github.com/GoogleCloudPlatform/google-cloud-python
98+
.. _report issues:
99+
https://github.com/GoogleCloudPlatform/google-cloud-python/issues
100+
101+
102+
.. _Google Cloud SDK: https://cloud.google.com/sdk/
+19Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# This file is used to generate README.rst
2+
3+
product:
4+
name: Google Cloud Video Intelligence API
5+
short_name: Cloud Video Intelligence API
6+
url: https://cloud.google.com/video-intelligence/docs
7+
description: >
8+
`Google Cloud Video Intelligence API`_ allows developers to easily
9+
integrate feature detection in video.
10+
11+
setup:
12+
- auth
13+
- install_deps
14+
15+
samples:
16+
- name: quickstart
17+
file: quickstart.py
18+
19+
cloud_client_library: true
+67Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
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 label detection using the Google Cloud API.
18+
19+
Usage:
20+
python quickstart.py
21+
"""
22+
23+
24+
def run_quickstart():
25+
# [START videointelligence_quickstart]
26+
import sys
27+
import time
28+
29+
from google.cloud.gapic.videointelligence.v1beta1 import enums
30+
from google.cloud.gapic.videointelligence.v1beta1 import (
31+
video_intelligence_service_client)
32+
33+
video_client = (video_intelligence_service_client.
34+
VideoIntelligenceServiceClient())
35+
features = [enums.Feature.LABEL_DETECTION]
36+
operation = video_client.annotate_video('gs://demomaker/cat.mp4', features)
37+
print('\nProcessing video for label annotations:')
38+
39+
while not operation.done():
40+
sys.stdout.write('.')
41+
sys.stdout.flush()
42+
time.sleep(15)
43+
44+
print('\nFinished processing.')
45+
46+
# first result is retrieved because a single video was processed
47+
results = operation.result().annotation_results[0]
48+
49+
for label in results.label_annotations:
50+
print('Label description: {}'.format(label.description))
51+
print('Locations:')
52+
53+
for l, location in enumerate(label.locations):
54+
positions = 'Entire video'
55+
if (location.segment.start_time_offset != -1 or
56+
location.segment.end_time_offset != -1):
57+
positions = '{} to {}'.format(
58+
location.segment.start_time_offset / 1000000.0,
59+
location.segment.end_time_offset / 1000000.0)
60+
print('\t{}: {}'.format(l, positions))
61+
62+
print('\n')
63+
# [END videointelligence_quickstart]
64+
65+
66+
if __name__ == '__main__':
67+
run_quickstart()
+26Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
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 pytest
18+
19+
import quickstart
20+
21+
22+
@pytest.mark.slow
23+
def test_quickstart(capsys):
24+
quickstart.run_quickstart()
25+
out, _ = capsys.readouterr()
26+
assert 'Whiskers' in out
+1Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
google-cloud-videointelligence==0.25.0

0 commit comments

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