From 248c772c21a7d24bf82b2644ad5d68416bb10612 Mon Sep 17 00:00:00 2001 From: Gus Class Date: Mon, 15 May 2017 14:58:32 -0700 Subject: [PATCH] Address review feedback --- video/cloud-client/analyze/analyze.py | 90 ++++++++++++++++++++++ video/cloud-client/analyze/analyze_test.py | 7 ++ 2 files changed, 97 insertions(+) diff --git a/video/cloud-client/analyze/analyze.py b/video/cloud-client/analyze/analyze.py index 06f182ed7062..f69fb2c3ed6d 100644 --- a/video/cloud-client/analyze/analyze.py +++ b/video/cloud-client/analyze/analyze.py @@ -22,6 +22,11 @@ """ import argparse +<<<<<<< HEAD +======= +import base64 +import io +>>>>>>> 4c58618... Address review feedback import sys import time @@ -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. @@ -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.') @@ -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.') @@ -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.') diff --git a/video/cloud-client/analyze/analyze_test.py b/video/cloud-client/analyze/analyze_test.py index f3178319b363..9c587b473353 100644 --- a/video/cloud-client/analyze/analyze_test.py +++ b/video/cloud-client/analyze/analyze_test.py @@ -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'