Skip to content
This repository has been archived by the owner on Nov 29, 2023. It is now read-only.

docs: add samples from video/cloud-client/labels #49

Merged
merged 43 commits into from Oct 13, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
43 commits
Select commit Hold shift + click to select a range
0b461ae
Adds tutorials using Cloud Client [(#930)](https://github.com/GoogleC…
gguuss May 5, 2017
ab4b78e
Adds new examples, replaces markdown with restructured text [(#945)](…
gguuss May 18, 2017
9bd3074
Updates requirements [(#952)](https://github.com/GoogleCloudPlatform/…
gguuss May 18, 2017
abd615b
Fix README rst links [(#962)](https://github.com/GoogleCloudPlatform/…
waprin May 24, 2017
26583e5
Auto-update dependencies. [(#1093)](https://github.com/GoogleCloudPla…
dpebot Aug 29, 2017
2e034cb
Update all generated readme auth instructions [(#1121)](https://githu…
Sep 18, 2017
cab45cc
Auto-update dependencies. [(#1123)](https://github.com/GoogleCloudPla…
dpebot Sep 19, 2017
c4d1d32
Video v1beta2 [(#1088)](https://github.com/GoogleCloudPlatform/python…
dizcology Sep 19, 2017
bd8edbd
Added Link to Python Setup Guide [(#1158)](https://github.com/GoogleC…
Oct 12, 2017
1489930
Tweak doc/help strings for sample tools [(#1160)](https://github.com…
pstoll Oct 12, 2017
5739425
Auto-update dependencies. [(#1186)](https://github.com/GoogleCloudPla…
dpebot Nov 1, 2017
5132d60
update samples to v1 [(#1221)](https://github.com/GoogleCloudPlatform…
dizcology Nov 29, 2017
c0d1376
Added "Open in Cloud Shell" buttons to README files [(#1254)](https:/…
Dec 7, 2017
00dcf93
Auto-update dependencies. [(#1377)](https://github.com/GoogleCloudPla…
dpebot Mar 5, 2018
abd0c62
Auto-update dependencies.
dpebot Apr 2, 2018
ee189b8
Regenerate the README files and fix the Open in Cloud Shell link for …
Apr 7, 2018
e006b6f
Update READMEs to fix numbering and add git clone [(#1464)](https://g…
frankyn Apr 26, 2018
b16ec66
Resolved conflicts.
michaelawyu Jun 29, 2018
92695d6
Merge branch 'dpebot-repositorygardener' despite flaky dataproc tests
michaelawyu Jun 29, 2018
fae1669
Video Intelligence region tag update [(#1639)](https://github.com/Goo…
alixhami Aug 20, 2018
b89a697
Auto-update dependencies. [(#1658)](https://github.com/GoogleCloudPla…
dpebot Aug 28, 2018
98cbb15
Use explicit URIs for Video Intelligence sample tests [(#1743)](https…
alixhami Oct 10, 2018
835f8fd
Auto-update dependencies. [(#1846)](https://github.com/GoogleCloudPla…
dpebot Nov 20, 2018
76adaf0
Auto-update dependencies. [(#1980)](https://github.com/GoogleCloudPla…
dpebot Feb 6, 2019
0ea6193
replace demomaker with cloud-samples-data/video for video intelligenc…
dizcology May 16, 2019
3c2662c
Adds updates for samples profiler ... vision [(#2439)](https://github…
gguuss Oct 7, 2019
67da47d
Auto-update dependencies. [(#2005)](https://github.com/GoogleCloudPla…
dpebot Dec 21, 2019
c987844
chore(deps): update dependency google-cloud-videointelligence to v1.1…
renovate-bot Mar 27, 2020
8207cfd
Simplify noxfile setup. [(#2806)](https://github.com/GoogleCloudPlatf…
kurtisvg Apr 2, 2020
cd88a29
fix: changes positional to named pararameters in Video samples [(#401…
telpirion Jun 9, 2020
ef8cf11
Update dependency google-cloud-videointelligence to v1.15.0 [(#4041)]…
renovate-bot Jun 16, 2020
1546e82
chore(deps): update dependency pytest to v5.4.3 [(#4279)](https://git…
renovate-bot Jul 12, 2020
56e9a8d
Update dependency pytest to v6 [(#4390)](https://github.com/GoogleClo…
renovate-bot Aug 1, 2020
dad9fee
Merge branch 'labels-samples' into add-labels-samples
danoscarmike Sep 28, 2020
4691390
Merge branch 'master' into add-labels-samples
danoscarmike Sep 30, 2020
4068e16
chore: adds samples templates
danoscarmike Oct 1, 2020
bf01df4
chore: temporarily pins sphinx
danoscarmike Oct 1, 2020
9c4240d
Merge branch 'master' into add-labels-samples
gcf-merge-on-green[bot] Oct 2, 2020
14e5ab3
Merge branch 'master' into add-labels-samples
danoscarmike Oct 2, 2020
6a40913
Merge branch 'master' into add-labels-samples
danoscarmike Oct 8, 2020
84ae1c5
chore: fixes flaky detect_faces tests
danoscarmike Oct 8, 2020
8bcb8b7
Merge branch 'danoscarmike-add-labels-samples' into add-labels-samples
danoscarmike Oct 8, 2020
dbe4db1
Merge branch 'master' into add-labels-samples
danoscarmike Oct 9, 2020
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 6 additions & 0 deletions .kokoro/samples/python3.6/common.cfg
Expand Up @@ -13,6 +13,12 @@ env_vars: {
value: "py-3.6"
}

# Declare build specific Cloud project.
env_vars: {
key: "BUILD_SPECIFIC_GCLOUD_PROJECT"
value: "python-docs-samples-tests-py36"
}

env_vars: {
key: "TRAMPOLINE_BUILD_FILE"
value: "github/python-videointelligence/.kokoro/test-samples.sh"
Expand Down
6 changes: 6 additions & 0 deletions .kokoro/samples/python3.7/common.cfg
Expand Up @@ -13,6 +13,12 @@ env_vars: {
value: "py-3.7"
}

# Declare build specific Cloud project.
env_vars: {
key: "BUILD_SPECIFIC_GCLOUD_PROJECT"
value: "python-docs-samples-tests-py37"
}

env_vars: {
key: "TRAMPOLINE_BUILD_FILE"
value: "github/python-videointelligence/.kokoro/test-samples.sh"
Expand Down
6 changes: 6 additions & 0 deletions .kokoro/samples/python3.8/common.cfg
Expand Up @@ -13,6 +13,12 @@ env_vars: {
value: "py-3.8"
}

# Declare build specific Cloud project.
env_vars: {
key: "BUILD_SPECIFIC_GCLOUD_PROJECT"
value: "python-docs-samples-tests-py38"
}

env_vars: {
key: "TRAMPOLINE_BUILD_FILE"
value: "github/python-videointelligence/.kokoro/test-samples.sh"
Expand Down
2 changes: 1 addition & 1 deletion noxfile.py
Expand Up @@ -149,7 +149,7 @@ def docs(session):
"""Build the docs for this library."""

session.install("-e", ".")
session.install("sphinx", "alabaster", "recommonmark")
session.install("sphinx<3.0.0", "alabaster", "recommonmark")

shutil.rmtree(os.path.join("docs", "_build"), ignore_errors=True)
session.run(
Expand Down
135 changes: 135 additions & 0 deletions samples/labels/README.rst
@@ -0,0 +1,135 @@

.. This file is automatically generated. Do not edit this file directly.

Google Cloud Video Intelligence API Python Samples
===============================================================================

.. image:: https://gstatic.com/cloudssh/images/open-btn.png
:target: https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/GoogleCloudPlatform/python-docs-samples&page=editor&open_in_editor=video/cloud-client/labels/README.rst


This directory contains samples for Google Cloud Video Intelligence API. `Google Cloud Video Intelligence API`_ allows developers to easily integrate feature detection in video.




.. _Google Cloud Video Intelligence API: https://cloud.google.com/video-intelligence/docs


Setup
-------------------------------------------------------------------------------



Authentication
++++++++++++++

This sample requires you to have authentication setup. Refer to the
`Authentication Getting Started Guide`_ for instructions on setting up
credentials for applications.

.. _Authentication Getting Started Guide:
https://cloud.google.com/docs/authentication/getting-started




Install Dependencies
++++++++++++++++++++

#. Clone python-docs-samples and change directory to the sample directory you want to use.

.. code-block:: bash

$ git clone https://github.com/GoogleCloudPlatform/python-docs-samples.git

#. Install `pip`_ and `virtualenv`_ if you do not already have them. You may want to refer to the `Python Development Environment Setup Guide`_ for Google Cloud Platform for instructions.

.. _Python Development Environment Setup Guide:
https://cloud.google.com/python/setup

#. Create a virtualenv. Samples are compatible with Python 3.6+.

.. code-block:: bash

$ virtualenv env
$ source env/bin/activate

#. Install the dependencies needed to run the samples.

.. code-block:: bash

$ pip install -r requirements.txt

.. _pip: https://pip.pypa.io/
.. _virtualenv: https://virtualenv.pypa.io/






Samples
-------------------------------------------------------------------------------


labels
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

.. image:: https://gstatic.com/cloudssh/images/open-btn.png
:target: https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/GoogleCloudPlatform/python-docs-samples&page=editor&open_in_editor=video/cloud-client/labels/labels.py,video/cloud-client/labels/README.rst




To run this sample:

.. code-block:: bash

$ python labels.py


usage: labels.py [-h] path

This application demonstrates how to detect labels from a video
based on the image content with the Google Cloud Video Intelligence
API.

For more information, check out the documentation at
https://cloud.google.com/videointelligence/docs.

Usage Example:

python labels.py gs://cloud-ml-sandbox/video/chicago.mp4

positional arguments:
path GCS file path for label detection.

optional arguments:
-h, --help show this help message and exit









The client library
-------------------------------------------------------------------------------

This sample uses the `Google Cloud Client Library for Python`_.
You can read the documentation for more details on API usage and use GitHub
to `browse the source`_ and `report issues`_.

.. _Google Cloud Client Library for Python:
https://googlecloudplatform.github.io/google-cloud-python/
.. _browse the source:
https://github.com/GoogleCloudPlatform/google-cloud-python
.. _report issues:
https://github.com/GoogleCloudPlatform/google-cloud-python/issues



.. _Google Cloud SDK: https://cloud.google.com/sdk/
22 changes: 22 additions & 0 deletions samples/labels/README.rst.in
@@ -0,0 +1,22 @@
# This file is used to generate README.rst

product:
name: Google Cloud Video Intelligence API
short_name: Cloud Video Intelligence API
url: https://cloud.google.com/video-intelligence/docs
description: >
`Google Cloud Video Intelligence API`_ allows developers to easily
integrate feature detection in video.

setup:
- auth
- install_deps

samples:
- name: labels
file: labels.py
show_help: True

cloud_client_library: true

folder: video/cloud-client/labels
84 changes: 84 additions & 0 deletions samples/labels/labels.py
@@ -0,0 +1,84 @@
#!/usr/bin/env python

# Copyright 2017 Google Inc. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

"""This application demonstrates how to detect labels from a video
based on the image content with the Google Cloud Video Intelligence
API.

For more information, check out the documentation at
https://cloud.google.com/videointelligence/docs.

Usage Example:

python labels.py gs://cloud-ml-sandbox/video/chicago.mp4

"""

# [START video_label_tutorial]
# [START video_label_tutorial_imports]
import argparse

from google.cloud import videointelligence
# [END video_label_tutorial_imports]


def analyze_labels(path):
""" Detects labels given a GCS path. """
# [START video_label_tutorial_construct_request]
video_client = videointelligence.VideoIntelligenceServiceClient()
features = [videointelligence.enums.Feature.LABEL_DETECTION]
operation = video_client.annotate_video(input_uri=path, features=features)
# [END video_label_tutorial_construct_request]
print('\nProcessing video for label annotations:')

# [START video_label_tutorial_check_operation]
result = operation.result(timeout=90)
print('\nFinished processing.')
# [END video_label_tutorial_check_operation]

# [START video_label_tutorial_parse_response]
segment_labels = result.annotation_results[0].segment_label_annotations
for i, segment_label in enumerate(segment_labels):
print('Video label description: {}'.format(
segment_label.entity.description))
for category_entity in segment_label.category_entities:
print('\tLabel category description: {}'.format(
category_entity.description))

for i, segment in enumerate(segment_label.segments):
start_time = (segment.segment.start_time_offset.seconds +
segment.segment.start_time_offset.nanos / 1e9)
end_time = (segment.segment.end_time_offset.seconds +
segment.segment.end_time_offset.nanos / 1e9)
positions = '{}s to {}s'.format(start_time, end_time)
confidence = segment.confidence
print('\tSegment {}: {}'.format(i, positions))
print('\tConfidence: {}'.format(confidence))
print('\n')
# [END video_label_tutorial_parse_response]


if __name__ == '__main__':
# [START video_label_tutorial_run_application]
parser = argparse.ArgumentParser(
description=__doc__,
formatter_class=argparse.RawDescriptionHelpFormatter)
parser.add_argument('path', help='GCS file path for label detection.')
args = parser.parse_args()

analyze_labels(args.path)
# [END video_label_tutorial_run_application]
# [END video_label_tutorial]
26 changes: 26 additions & 0 deletions samples/labels/labels_test.py
@@ -0,0 +1,26 @@
#!/usr/bin/env python

# Copyright 2017 Google, Inc
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

import pytest

import labels


@pytest.mark.slow
def test_feline_video_labels(capsys):
labels.analyze_labels('gs://cloud-samples-data/video/cat.mp4')
out, _ = capsys.readouterr()
assert 'Video label description: cat' in out