Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
* update analyze_safe_search

* update analyze_shots

* update explicit_content_detection and test

* update fece detection

* update label detection (path)

* update label detection (file)

* flake

* safe search --> explicit content

* update faces tutorial

* update client library quickstart

* update shotchange tutorial

* update labels tutorial

* correct spelling

* correction start_time_offset

* import order

* rebased
  • Loading branch information
dizcology authored and Jon Wayne Parrott committed Sep 19, 2017
1 parent cab45cc commit c4d1d32
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 17 deletions.
34 changes: 20 additions & 14 deletions samples/labels/labels.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,17 +32,15 @@
import sys
import time

from google.cloud.gapic.videointelligence.v1beta1 import enums
from google.cloud.gapic.videointelligence.v1beta1 import (
video_intelligence_service_client)
from google.cloud import videointelligence_v1beta2
from google.cloud.videointelligence_v1beta2 import enums
# [END imports]


def analyze_labels(path):
""" Detects labels given a GCS path. """
# [START construct_request]
video_client = (video_intelligence_service_client.
VideoIntelligenceServiceClient())
video_client = videointelligence_v1beta2.VideoIntelligenceServiceClient()
features = [enums.Feature.LABEL_DETECTION]
operation = video_client.annotate_video(path, features)
# [END construct_request]
Expand All @@ -60,15 +58,23 @@ def analyze_labels(path):
# [START parse_response]
results = operation.result().annotation_results[0]

for label in results.label_annotations:
print('Label description: {}'.format(label.description))
print('Locations:')

for l, location in enumerate(label.locations):
print('\t{}: {} to {}'.format(
l,
location.segment.start_time_offset,
location.segment.end_time_offset))
for i, segment_label in enumerate(results.segment_label_annotations):
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 parse_response]


Expand Down
5 changes: 2 additions & 3 deletions samples/labels/labels_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,9 @@
# limitations under the License.

import os

import labels
import pytest

import labels

BUCKET = os.environ['CLOUD_STORAGE_BUCKET']
LABELS_FILE_PATH = '/video/cat.mp4'
Expand All @@ -29,4 +28,4 @@ def test_feline_video_labels(capsys):
labels.analyze_labels(
'gs://{}{}'.format(BUCKET, LABELS_FILE_PATH))
out, _ = capsys.readouterr()
assert 'Whiskers' in out
assert 'Video label description: cat' in out

0 comments on commit c4d1d32

Please sign in to comment.