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 a75e025

Browse filesBrowse files
dizcologyJon Wayne Parrott
authored andcommitted
Video v1beta2 (GoogleCloudPlatform#1088)
* 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
1 parent b93397f commit a75e025
Copy full SHA for a75e025

File tree

Expand file treeCollapse file tree

11 files changed

+249
-151
lines changed
Filter options
Expand file treeCollapse file tree

11 files changed

+249
-151
lines changed

‎video/cloud-client/analyze/README.rst

Copy file name to clipboardExpand all lines: video/cloud-client/analyze/README.rst
+6-6Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -59,25 +59,25 @@ To run this sample:
5959
6060
$ python analyze.py
6161
62-
usage: analyze.py [-h] {faces,labels,labels_file,safe_search,shots} ...
62+
usage: analyze.py [-h] {faces,labels,labels_file,explicit_content,shots} ...
6363
64-
This application demonstrates face detection, label detection, safe search,
65-
and shot change detection using the Google Cloud API.
64+
This application demonstrates face detection, label detection,
65+
explicit content, and shot change detection using the Google Cloud API.
6666
6767
Usage Examples:
6868
6969
python analyze.py faces gs://demomaker/google_gmail.mp4
7070
python analyze.py labels gs://cloud-ml-sandbox/video/chicago.mp4
7171
python analyze.py labels_file resources/cat.mp4
7272
python analyze.py shots gs://demomaker/gbikes_dinosaur.mp4
73-
python analyze.py safe_search gs://demomaker/gbikes_dinosaur.mp4
73+
python analyze.py explicit_content gs://demomaker/gbikes_dinosaur.mp4
7474
7575
positional arguments:
76-
{faces,labels,labels_file,safe_search,shots}
76+
{faces,labels,labels_file,explicit_content,shots}
7777
faces Detects faces given a GCS path.
7878
labels Detects labels given a GCS path.
7979
labels_file Detects labels given a file path.
80-
safe_search Detects safe search features the GCS path to a video.
80+
explicit_content Detects explicit content from the GCS path to a video.
8181
shots Detects camera shot changes.
8282
8383
optional arguments:

‎video/cloud-client/analyze/analyze.py

Copy file name to clipboardExpand all lines: video/cloud-client/analyze/analyze.py
+169-73Lines changed: 169 additions & 73 deletions
Large diffs are not rendered by default.

‎video/cloud-client/analyze/analyze_test.py

Copy file name to clipboardExpand all lines: video/cloud-client/analyze/analyze_test.py
+11-13Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -15,46 +15,44 @@
1515
# limitations under the License.
1616

1717
import os
18-
19-
import pytest
20-
2118
import analyze
19+
import pytest
2220

2321

2422
BUCKET = os.environ['CLOUD_STORAGE_BUCKET']
2523
LABELS_FILE_PATH = '/video/cat.mp4'
2624
FACES_FILE_PATH = '/video/googlework.mp4'
27-
SAFE_SEARCH_FILE_PATH = '/video/cat.mp4'
25+
EXPLICIT_CONTENT_FILE_PATH = '/video/cat.mp4'
2826
SHOTS_FILE_PATH = '/video/gbikes_dinosaur.mp4'
2927

3028

3129
@pytest.mark.slow
32-
def test_cat_video_shots(capsys):
30+
def test_analyze_shots(capsys):
3331
analyze.analyze_shots(
3432
'gs://{}{}'.format(BUCKET, SHOTS_FILE_PATH))
3533
out, _ = capsys.readouterr()
36-
assert 'Scene 1:' in out
34+
assert 'Shot 1:' in out
3735

3836

3937
@pytest.mark.slow
40-
def test_work_video_faces(capsys):
38+
def test_analyze_faces(capsys):
4139
analyze.analyze_faces(
4240
'gs://{}{}'.format(BUCKET, FACES_FILE_PATH))
4341
out, _ = capsys.readouterr()
4442
assert 'Thumbnail' in out
4543

4644

4745
@pytest.mark.slow
48-
def test_dino_video_labels(capsys):
46+
def test_analyze_labels(capsys):
4947
analyze.analyze_labels(
5048
'gs://{}{}'.format(BUCKET, LABELS_FILE_PATH))
5149
out, _ = capsys.readouterr()
52-
assert 'Whiskers' in out
50+
assert 'label description: cat' in out
5351

5452

5553
@pytest.mark.slow
56-
def test_cat_safe_search(capsys):
57-
analyze.analyze_safe_search(
58-
'gs://{}{}'.format(BUCKET, SAFE_SEARCH_FILE_PATH))
54+
def test_analyze_explicit_content(capsys):
55+
analyze.analyze_explicit_content(
56+
'gs://{}{}'.format(BUCKET, EXPLICIT_CONTENT_FILE_PATH))
5957
out, _ = capsys.readouterr()
60-
assert 'medical' in out
58+
assert 'pornography' in out

‎video/cloud-client/faces/faces.py

Copy file name to clipboardExpand all lines: video/cloud-client/faces/faces.py
+9-9Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -32,17 +32,15 @@
3232
import sys
3333
import time
3434

35-
from google.cloud.gapic.videointelligence.v1beta1 import enums
36-
from google.cloud.gapic.videointelligence.v1beta1 import (
37-
video_intelligence_service_client)
35+
from google.cloud import videointelligence_v1beta2
36+
from google.cloud.videointelligence_v1beta2 import enums
3837
# [END imports]
3938

4039

4140
def analyze_faces(path):
4241
# [START construct_request]
4342
""" Detects faces given a GCS path. """
44-
video_client = (video_intelligence_service_client.
45-
VideoIntelligenceServiceClient())
43+
video_client = videointelligence_v1beta2.VideoIntelligenceServiceClient()
4644
features = [enums.Feature.FACE_DETECTION]
4745
operation = video_client.annotate_video(path, features)
4846
# [END construct_request]
@@ -66,10 +64,12 @@ def analyze_faces(path):
6664
print('Thumbnail size: {}'.format(len(face.thumbnail)))
6765

6866
for segment_id, segment in enumerate(face.segments):
69-
print('Track {}: {} to {}'.format(
70-
segment_id,
71-
segment.start_time_offset,
72-
segment.end_time_offset))
67+
start_time = (segment.segment.start_time_offset.seconds +
68+
segment.segment.start_time_offset.nanos / 1e9)
69+
end_time = (segment.segment.end_time_offset.seconds +
70+
segment.segment.end_time_offset.nanos / 1e9)
71+
positions = '{}s to {}s'.format(start_time, end_time)
72+
print('\tSegment {}: {}'.format(segment_id, positions))
7373
# [END parse_response]
7474

7575

‎video/cloud-client/faces/faces_test.py

Copy file name to clipboardExpand all lines: video/cloud-client/faces/faces_test.py
+1-2Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,9 @@
1515
# limitations under the License.
1616

1717
import os
18-
18+
import faces
1919
import pytest
2020

21-
import faces
2221

2322
BUCKET = os.environ['CLOUD_STORAGE_BUCKET']
2423
FACES_FILE_PATH = '/video/googlework.mp4'

‎video/cloud-client/labels/labels.py

Copy file name to clipboardExpand all lines: video/cloud-client/labels/labels.py
+20-14Lines changed: 20 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -32,17 +32,15 @@
3232
import sys
3333
import time
3434

35-
from google.cloud.gapic.videointelligence.v1beta1 import enums
36-
from google.cloud.gapic.videointelligence.v1beta1 import (
37-
video_intelligence_service_client)
35+
from google.cloud import videointelligence_v1beta2
36+
from google.cloud.videointelligence_v1beta2 import enums
3837
# [END imports]
3938

4039

4140
def analyze_labels(path):
4241
""" Detects labels given a GCS path. """
4342
# [START construct_request]
44-
video_client = (video_intelligence_service_client.
45-
VideoIntelligenceServiceClient())
43+
video_client = videointelligence_v1beta2.VideoIntelligenceServiceClient()
4644
features = [enums.Feature.LABEL_DETECTION]
4745
operation = video_client.annotate_video(path, features)
4846
# [END construct_request]
@@ -60,15 +58,23 @@ def analyze_labels(path):
6058
# [START parse_response]
6159
results = operation.result().annotation_results[0]
6260

63-
for label in results.label_annotations:
64-
print('Label description: {}'.format(label.description))
65-
print('Locations:')
66-
67-
for l, location in enumerate(label.locations):
68-
print('\t{}: {} to {}'.format(
69-
l,
70-
location.segment.start_time_offset,
71-
location.segment.end_time_offset))
61+
for i, segment_label in enumerate(results.segment_label_annotations):
62+
print('Video label description: {}'.format(
63+
segment_label.entity.description))
64+
for category_entity in segment_label.category_entities:
65+
print('\tLabel category description: {}'.format(
66+
category_entity.description))
67+
68+
for i, segment in enumerate(segment_label.segments):
69+
start_time = (segment.segment.start_time_offset.seconds +
70+
segment.segment.start_time_offset.nanos / 1e9)
71+
end_time = (segment.segment.end_time_offset.seconds +
72+
segment.segment.end_time_offset.nanos / 1e9)
73+
positions = '{}s to {}s'.format(start_time, end_time)
74+
confidence = segment.confidence
75+
print('\tSegment {}: {}'.format(i, positions))
76+
print('\tConfidence: {}'.format(confidence))
77+
print('\n')
7278
# [END parse_response]
7379

7480

‎video/cloud-client/labels/labels_test.py

Copy file name to clipboardExpand all lines: video/cloud-client/labels/labels_test.py
+2-3Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,9 @@
1515
# limitations under the License.
1616

1717
import os
18-
18+
import labels
1919
import pytest
2020

21-
import labels
2221

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

‎video/cloud-client/quickstart/quickstart.py

Copy file name to clipboardExpand all lines: video/cloud-client/quickstart/quickstart.py
+18-17Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,10 @@ def run_quickstart():
2626
import sys
2727
import time
2828

29-
from google.cloud.gapic.videointelligence.v1beta1 import enums
30-
from google.cloud.gapic.videointelligence.v1beta1 import (
31-
video_intelligence_service_client)
29+
from google.cloud import videointelligence_v1beta2
30+
from google.cloud.videointelligence_v1beta2 import enums
3231

33-
video_client = (video_intelligence_service_client.
34-
VideoIntelligenceServiceClient())
32+
video_client = videointelligence_v1beta2.VideoIntelligenceServiceClient()
3533
features = [enums.Feature.LABEL_DETECTION]
3634
operation = video_client.annotate_video('gs://demomaker/cat.mp4', features)
3735
print('\nProcessing video for label annotations:')
@@ -46,19 +44,22 @@ def run_quickstart():
4644
# first result is retrieved because a single video was processed
4745
results = operation.result().annotation_results[0]
4846

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))
47+
for i, segment_label in enumerate(results.segment_label_annotations):
48+
print('Video label description: {}'.format(
49+
segment_label.entity.description))
50+
for category_entity in segment_label.category_entities:
51+
print('\tLabel category description: {}'.format(
52+
category_entity.description))
6153

54+
for i, segment in enumerate(segment_label.segments):
55+
start_time = (segment.segment.start_time_offset.seconds +
56+
segment.segment.start_time_offset.nanos / 1e9)
57+
end_time = (segment.segment.end_time_offset.seconds +
58+
segment.segment.end_time_offset.nanos / 1e9)
59+
positions = '{}s to {}s'.format(start_time, end_time)
60+
confidence = segment.confidence
61+
print('\tSegment {}: {}'.format(i, positions))
62+
print('\tConfidence: {}'.format(confidence))
6263
print('\n')
6364
# [END videointelligence_quickstart]
6465

‎video/cloud-client/quickstart/quickstart_test.py

Copy file name to clipboardExpand all lines: video/cloud-client/quickstart/quickstart_test.py
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,4 +23,4 @@
2323
def test_quickstart(capsys):
2424
quickstart.run_quickstart()
2525
out, _ = capsys.readouterr()
26-
assert 'Whiskers' in out
26+
assert 'Video label description: cat' in out

‎video/cloud-client/shotchange/shotchange.py

Copy file name to clipboardExpand all lines: video/cloud-client/shotchange/shotchange.py
+11-12Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -32,17 +32,15 @@
3232
import sys
3333
import time
3434

35-
from google.cloud.gapic.videointelligence.v1beta1 import enums
36-
from google.cloud.gapic.videointelligence.v1beta1 import (
37-
video_intelligence_service_client)
35+
from google.cloud import videointelligence_v1beta2
36+
from google.cloud.videointelligence_v1beta2 import enums
3837
# [END imports]
3938

4039

4140
def analyze_shots(path):
4241
""" Detects camera shot changes. """
4342
# [START construct_request]
44-
video_client = (video_intelligence_service_client.
45-
VideoIntelligenceServiceClient())
43+
video_client = videointelligence_v1beta2.VideoIntelligenceServiceClient()
4644
features = [enums.Feature.SHOT_CHANGE_DETECTION]
4745
operation = video_client.annotate_video(path, features)
4846
# [END construct_request]
@@ -58,13 +56,14 @@ def analyze_shots(path):
5856
# [END check_operation]
5957

6058
# [START parse_response]
61-
shots = operation.result().annotation_results[0]
62-
63-
for note, shot in enumerate(shots.shot_annotations):
64-
print('Scene {}: {} to {}'.format(
65-
note,
66-
shot.start_time_offset,
67-
shot.end_time_offset))
59+
shots = operation.result().annotation_results[0].shot_annotations
60+
61+
for i, shot in enumerate(shots):
62+
start_time = (shot.start_time_offset.seconds +
63+
shot.start_time_offset.nanos / 1e9)
64+
end_time = (shot.end_time_offset.seconds +
65+
shot.end_time_offset.nanos / 1e9)
66+
print('\tShot {}: {} to {}'.format(i, start_time, end_time))
6867
# [END parse_response]
6968

7069

‎video/cloud-client/shotchange/shotchange_test.py

Copy file name to clipboardExpand all lines: video/cloud-client/shotchange/shotchange_test.py
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,4 +29,4 @@ def test_shots_dino(capsys):
2929
shotchange.analyze_shots(
3030
'gs://{}{}'.format(BUCKET, SHOTS_FILE_PATH))
3131
out, _ = capsys.readouterr()
32-
assert 'Scene 1:' in out
32+
assert 'Shot 1:' in out

0 commit comments

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