-
Notifications
You must be signed in to change notification settings - Fork 6.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Adds one more tutorial as well as fixes some copy/paste typos. #933
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
# Google Cloud Video Intelligence | ||
|
||
Demonstrates face detection using the Google Cloud Video Intelligence API. | ||
|
||
## Setup | ||
Please follow the [Set Up Your Project](https://cloud.google.com/video-intelligence/docs/getting-started#set_up_your_project) | ||
steps in the Quickstart doc to create a project and enable the Google Cloud | ||
Video Intelligence API. Following those steps, make sure that you | ||
[Set Up a Service Account](https://cloud.google.com/video-intelligence/docs/common/auth#set_up_a_service_account), | ||
and export the following environment variable: | ||
|
||
``` | ||
export GOOGLE_APPLICATION_CREDENTIALS=/path/to/your-project-credentials.json | ||
``` | ||
|
||
## Run the sample | ||
|
||
Install [pip](https://pip.pypa.io/en/stable/installing) if not already installed. | ||
|
||
Install the necessary libraries using pip: | ||
|
||
```sh | ||
$ pip install -r requirements.txt | ||
``` | ||
|
||
Run the sample, for example: | ||
``` | ||
python faces.py gs://cloudmleap/video/googlework.mp4 | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
#!/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 perform shot change detection with the | ||
Google Cloud Video Intelligence API. | ||
|
||
For more information, check out the documentation at | ||
https://cloud.google.com/videointelligence/docs. | ||
""" | ||
|
||
# [START full_tutorial] | ||
# [START imports] | ||
import argparse | ||
import sys | ||
import time | ||
|
||
from google.cloud.gapic.videointelligence.v1beta1 import enums | ||
from google.cloud.gapic.videointelligence.v1beta1 import ( | ||
video_intelligence_service_client) | ||
# [END imports] | ||
|
||
|
||
def analyze_faces(path): | ||
# [START construct_request] | ||
""" Detects faces given a GCS path. """ | ||
video_client = (video_intelligence_service_client. | ||
VideoIntelligenceServiceClient()) | ||
features = [enums.Feature.FACE_DETECTION] | ||
operation = video_client.annotate_video(path, features) | ||
# [END construct_request] | ||
print('\nProcessing video for face annotations:') | ||
|
||
# [START check_operation] | ||
while not operation.done(): | ||
sys.stdout.write('.') | ||
sys.stdout.flush() | ||
time.sleep(20) | ||
|
||
print('\nFinished processing.') | ||
# [END check_operation] | ||
|
||
# [START parse_response] | ||
# first result is retrieved because a single video was processed | ||
face_annotations = (operation.result().annotation_results[0]. | ||
face_annotations) | ||
|
||
for face_id, face in enumerate(face_annotations): | ||
print('Thumbnail size: {}'.format(len(face.thumbnail))) | ||
|
||
for segment_id, segment in enumerate(face.segments): | ||
print('Track {}: {} to {}'.format( | ||
segment_id, | ||
segment.start_time_offset, | ||
segment.end_time_offset)) | ||
# [END parse_response] | ||
|
||
|
||
if __name__ == '__main__': | ||
# [START running_app] | ||
parser = argparse.ArgumentParser( | ||
description=__doc__, | ||
formatter_class=argparse.RawDescriptionHelpFormatter) | ||
parser.add_argument('path', help='GCS file path for face detection.') | ||
args = parser.parse_args() | ||
|
||
analyze_faces(args.path) | ||
# [END running_app] | ||
# [END full_tutorial] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
#!/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 os | ||
|
||
import pytest | ||
|
||
import faces | ||
|
||
BUCKET = os.environ['CLOUD_STORAGE_BUCKET'] | ||
FACES_FILE_PATH = '/video/googlework.mp4' | ||
|
||
|
||
@pytest.mark.slow | ||
def test_work_video_faces(capsys): | ||
faces.analyze_faces( | ||
'gs://{}{}'.format(BUCKET, FACES_FILE_PATH)) | ||
out, _ = capsys.readouterr() | ||
assert 'Thumbnail' in out |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
https://storage.googleapis.com/videointelligence-alpha/videointelligence-python.zip |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I just noticed you haven't been using the README generator. For shame!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
True, true! Bug filed.