Skip to content

Commit

Permalink
Address review feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
gguuss committed May 16, 2017
1 parent a6df5b2 commit 248c772
Show file tree
Hide file tree
Showing 2 changed files with 97 additions and 0 deletions.
90 changes: 90 additions & 0 deletions video/cloud-client/analyze/analyze.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,11 @@
"""

import argparse
<<<<<<< HEAD
=======
import base64
import io
>>>>>>> 4c58618... Address review feedback
import sys
import time

Expand All @@ -30,6 +35,40 @@
video_intelligence_service_client)


<<<<<<< HEAD
=======
def analyze_safe_search(path):
""" Detects safe search features the GCS path to a video. """
video_client = (video_intelligence_service_client.
VideoIntelligenceServiceClient())
features = [enums.Feature.SAFE_SEARCH_DETECTION]
operation = video_client.annotate_video(path, features)
print('\nProcessing video for safe search annotations:')

while not operation.done():
sys.stdout.write('.')
sys.stdout.flush()
time.sleep(15)

print('\nFinished processing.')

# first result is retrieved because a single video was processed
safe_annotations = (operation.result().annotation_results[0].
safe_search_annotations)

likely_string = ("Unknown", "Very unlikely", "Unlikely", "Possible",
"Likely", "Very likely")

for note in safe_annotations:
print('Time: {}s').format(note.time_offset / 1000000.0)
print('\tadult: {}').format(likely_string[note.adult])
print('\tspoof: {}').format(likely_string[note.spoof])
print('\tmedical: {}').format(likely_string[note.medical])
print('\tracy: {}').format(likely_string[note.racy])
print('\tviolent: {}\n').format(likely_string[note.violent])


>>>>>>> 4c58618... Address review feedback
def analyze_faces(path):
""" Detects faces given a GCS path. """
video_client = (video_intelligence_service_client.
Expand All @@ -41,7 +80,11 @@ def analyze_faces(path):
while not operation.done():
sys.stdout.write('.')
sys.stdout.flush()
<<<<<<< HEAD
time.sleep(20)
=======
time.sleep(15)
>>>>>>> 4c58618... Address review feedback

print('\nFinished processing.')

Expand Down Expand Up @@ -70,7 +113,50 @@ def analyze_labels(path):
while not operation.done():
sys.stdout.write('.')
sys.stdout.flush()
<<<<<<< HEAD
time.sleep(20)
=======
time.sleep(15)

print('\nFinished processing.')

# first result is retrieved because a single video was processed
results = operation.result().annotation_results[0]

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

for l, location in enumerate(label.locations):
positions = 'Entire video'
if (location.segment.start_time_offset != -1 or
location.segment.end_time_offset != -1):
positions = '{}s to {}s'.format(
location.segment.start_time_offset / 1000000.0,
location.segment.end_time_offset / 1000000.0)
print('\t{}: {}'.format(l, positions))

print('\n')


def analyze_labels_file(path):
""" Detects labels given a file path. """
video_client = (video_intelligence_service_client.
VideoIntelligenceServiceClient())
features = [enums.Feature.LABEL_DETECTION]

with io.open(path, "rb") as movie:
content_base64 = base64.b64encode(movie.read())

operation = video_client.annotate_video(
'', features, input_content=content_base64)
print('\nProcessing video for label annotations:')

while not operation.done():
sys.stdout.write('.')
sys.stdout.flush()
time.sleep(15)
>>>>>>> 4c58618... Address review feedback

print('\nFinished processing.')

Expand Down Expand Up @@ -99,7 +185,11 @@ def analyze_shots(path):
while not operation.done():
sys.stdout.write('.')
sys.stdout.flush()
<<<<<<< HEAD
time.sleep(20)
=======
time.sleep(15)
>>>>>>> 4c58618... Address review feedback

print('\nFinished processing.')

Expand Down
7 changes: 7 additions & 0 deletions video/cloud-client/analyze/analyze_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,16 @@

import os

<<<<<<< HEAD
import pytest

import analyze
=======
import analyze

import pytest

>>>>>>> 4c58618... Address review feedback

BUCKET = os.environ['CLOUD_STORAGE_BUCKET']
LABELS_FILE_PATH = '/video/cat.mp4'
Expand Down

0 comments on commit 248c772

Please sign in to comment.