From b85c44e36be95ee1030b43dd6b3e8506178eaff2 Mon Sep 17 00:00:00 2001 From: Mike Ganbold Date: Thu, 12 Mar 2020 16:19:46 -0700 Subject: [PATCH 01/14] Draft. adding GA samples for Logo detection --- .../java/com/example/video/LogoDetection.java | 138 ++++++++++++++++++ .../com/example/video/LogoDetectionGcs.java | 131 +++++++++++++++++ .../test/java/com/example/video/DetectIT.java | 39 ++++- 3 files changed, 301 insertions(+), 7 deletions(-) create mode 100644 video/cloud-client/src/main/java/com/example/video/LogoDetection.java create mode 100644 video/cloud-client/src/main/java/com/example/video/LogoDetectionGcs.java diff --git a/video/cloud-client/src/main/java/com/example/video/LogoDetection.java b/video/cloud-client/src/main/java/com/example/video/LogoDetection.java new file mode 100644 index 00000000000..a5a0f4da1f3 --- /dev/null +++ b/video/cloud-client/src/main/java/com/example/video/LogoDetection.java @@ -0,0 +1,138 @@ +/* + * Copyright 2020 Google LLC + * + * 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. + */ + +package com.example.video; + +import com.google.api.gax.longrunning.OperationFuture; +import com.google.cloud.videointelligence.v1.AnnotateVideoProgress; +import com.google.cloud.videointelligence.v1.AnnotateVideoRequest; +import com.google.cloud.videointelligence.v1.AnnotateVideoResponse; +import com.google.cloud.videointelligence.v1.DetectedAttribute; +import com.google.cloud.videointelligence.v1.Entity; +import com.google.cloud.videointelligence.v1.Feature; +import com.google.cloud.videointelligence.v1.LogoRecognitionAnnotation; +import com.google.cloud.videointelligence.v1.NormalizedBoundingBox; +import com.google.cloud.videointelligence.v1.TimestampedObject; +import com.google.cloud.videointelligence.v1.Track; +import com.google.cloud.videointelligence.v1.VideoAnnotationResults; +import com.google.cloud.videointelligence.v1.VideoIntelligenceServiceClient; +import com.google.cloud.videointelligence.v1.VideoSegment; +import com.google.protobuf.ByteString; +import com.google.protobuf.Duration; + +import java.nio.file.Files; +import java.nio.file.Path; +import java.nio.file.Paths; +import java.util.concurrent.TimeUnit; + +public class LogoDetection { + + public static void detectLogo() throws Exception { + // TODO(developer): Replace these variables before running the sample. + String localFilePath = "resources/googlework_short.mp4"; + detectLogo(localFilePath); + } + + // [START video_detect_logo] + public static void detectLogo(String filePath) throws Exception { + try (VideoIntelligenceServiceClient client = VideoIntelligenceServiceClient.create()) { + // Read file + Path path = Paths.get(filePath); + byte[] data = Files.readAllBytes(path); + // Create the request + AnnotateVideoRequest request = AnnotateVideoRequest.newBuilder() + .setInputContent(ByteString.copyFrom(data)) + .addFeatures(Feature.LOGO_RECOGNITION) + .build(); + + // asynchronously perform object tracking on videos + OperationFuture future = + client.annotateVideoAsync(request); + + System.out.println("Waiting for operation to complete..."); + // The first result is retrieved because a single video was processed. + AnnotateVideoResponse response = future.get(300, TimeUnit.SECONDS); + VideoAnnotationResults annotationResult = response.getAnnotationResults(0); + + // Annotations for list of logos detected, tracked and recognized in video. + for (LogoRecognitionAnnotation logoRecognitionAnnotation : + annotationResult.getLogoRecognitionAnnotationsList()) { + Entity entity = logoRecognitionAnnotation.getEntity(); + // Opaque entity ID. Some IDs may be available in + // [Google Knowledge Graph Search API](https://developers.google.com/knowledge-graph/). + System.out.printf("Entity Id : %s\n", entity.getEntityId()); + // Textual description, e.g. `Google`. + System.out.printf("Description : %s\n", entity.getDescription()); + // All logo tracks where the recognized logo appears. Each track corresponds + // to one logo instance appearing in consecutive frames. + for (Track track : logoRecognitionAnnotation.getTracksList()) { + // Video segment of a track. + VideoSegment segment = track.getSegment(); + Duration segmentStartTimeOffset = segment.getStartTimeOffset(); + System.out.printf( + "\n\tStart Time Offset : %s.%s\n", + segmentStartTimeOffset.getSeconds(), segmentStartTimeOffset.getNanos()); + Duration segmentEndTimeOffset = segment.getEndTimeOffset(); + System.out.printf( + "\tEnd Time Offset : %s.%s\n", + segmentEndTimeOffset.getSeconds(), segmentEndTimeOffset.getNanos()); + System.out.printf("\tConfidence : %s\n", track.getConfidence()); + // The object with timestamp and attributes per frame in the track. + for (TimestampedObject timestampedObject : track.getTimestampedObjectsList()) { + // Normalized Bounding box in a frame, where the object is located. + NormalizedBoundingBox normalizedBoundingBox = + timestampedObject.getNormalizedBoundingBox(); + System.out.printf("\n\t\tLeft : %s\n", normalizedBoundingBox.getLeft()); + System.out.printf("\t\tTop : %s\n", normalizedBoundingBox.getTop()); + System.out.printf("\t\tRight : %s\n", normalizedBoundingBox.getRight()); + System.out.printf("\t\tBottom : %s\n", normalizedBoundingBox.getBottom()); + // Optional. The attributes of the object in the bounding box. + for (DetectedAttribute attribute : timestampedObject.getAttributesList()) { + System.out.printf("\n\t\t\tName : %s\n", attribute.getName()); + System.out.printf("\t\t\tConfidence : %s\n", attribute.getConfidence()); + System.out.printf("\t\t\tValue : %s\n", attribute.getValue()); + } + } + // Optional. Attributes in the track level. + for (DetectedAttribute trackAttribute : track.getAttributesList()) { + System.out.printf("\n\t\tName : %s\n", trackAttribute.getName()); + System.out.printf("\t\tConfidence : %s\n", trackAttribute.getConfidence()); + System.out.printf("\t\tValue : %s\n", trackAttribute.getValue()); + } + } + // All video segments where the recognized logo appears. + // There might be multiple instances of the same logo class appearing in one VideoSegment. + for (VideoSegment logoRecognitionAnnotationSegment : + logoRecognitionAnnotation.getSegmentsList()) { + Duration logoRecognitionAnnotationSegmentStartTimeOffset = + logoRecognitionAnnotationSegment.getStartTimeOffset(); + System.out.printf( + "\n\tStart Time Offset : %s.%s\n", + logoRecognitionAnnotationSegmentStartTimeOffset.getSeconds(), + logoRecognitionAnnotationSegmentStartTimeOffset.getNanos()); + Duration logoRecognitionAnnotationSegmentEndTimeOffset = + logoRecognitionAnnotationSegment.getEndTimeOffset(); + System.out.printf( + "\tEnd Time Offset : %s.%s\n", + logoRecognitionAnnotationSegmentEndTimeOffset.getSeconds(), + logoRecognitionAnnotationSegmentEndTimeOffset.getNanos()); + } + } + } + } + // [END video_detect_logo] +} + diff --git a/video/cloud-client/src/main/java/com/example/video/LogoDetectionGcs.java b/video/cloud-client/src/main/java/com/example/video/LogoDetectionGcs.java new file mode 100644 index 00000000000..6c29b22a36d --- /dev/null +++ b/video/cloud-client/src/main/java/com/example/video/LogoDetectionGcs.java @@ -0,0 +1,131 @@ +/* + * Copyright 2020 Google LLC + * + * 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. + */ + +package com.example.video; + +import com.google.api.gax.longrunning.OperationFuture; +import com.google.cloud.videointelligence.v1.AnnotateVideoProgress; +import com.google.cloud.videointelligence.v1.AnnotateVideoRequest; +import com.google.cloud.videointelligence.v1.AnnotateVideoResponse; +import com.google.cloud.videointelligence.v1.DetectedAttribute; +import com.google.cloud.videointelligence.v1.Entity; +import com.google.cloud.videointelligence.v1.Feature; +import com.google.cloud.videointelligence.v1.LogoRecognitionAnnotation; +import com.google.cloud.videointelligence.v1.NormalizedBoundingBox; +import com.google.cloud.videointelligence.v1.TimestampedObject; +import com.google.cloud.videointelligence.v1.Track; +import com.google.cloud.videointelligence.v1.VideoAnnotationResults; +import com.google.cloud.videointelligence.v1.VideoIntelligenceServiceClient; +import com.google.cloud.videointelligence.v1.VideoSegment; +import com.google.protobuf.Duration; + +import java.util.concurrent.TimeUnit; + +public class LogoDetectionGcs { + + public static void detectLogoGcs() throws Exception { + // TODO(developer): Replace these variables before running the sample. + String gcsUri = "gs://cloud-samples-data/video/googlework_short.mp4"; + detectLogoGcs(gcsUri); + } + + // [START video_detect_logo_gcs] + public static void detectLogoGcs(String inputUri) throws Exception { + try (VideoIntelligenceServiceClient client = VideoIntelligenceServiceClient.create()) { + // Create the request + AnnotateVideoRequest request = AnnotateVideoRequest.newBuilder() + .setInputUri(inputUri) + .addFeatures(Feature.LOGO_RECOGNITION) + .build(); + + // asynchronously perform object tracking on videos + OperationFuture future = + client.annotateVideoAsync(request); + + System.out.println("Waiting for operation to complete..."); + // The first result is retrieved because a single video was processed. + AnnotateVideoResponse response = future.get(300, TimeUnit.SECONDS); + VideoAnnotationResults annotationResult = response.getAnnotationResults(0); + + // Annotations for list of logos detected, tracked and recognized in video. + for (LogoRecognitionAnnotation logoRecognitionAnnotation : + annotationResult.getLogoRecognitionAnnotationsList()) { + Entity entity = logoRecognitionAnnotation.getEntity(); + // Opaque entity ID. Some IDs may be available in + // [Google Knowledge Graph Search API](https://developers.google.com/knowledge-graph/). + System.out.printf("Entity Id : %s\n", entity.getEntityId()); + // Textual description, e.g. `Google`. + System.out.printf("Description : %s\n", entity.getDescription()); + // All logo tracks where the recognized logo appears. Each track corresponds + // to one logo instance appearing in consecutive frames. + for (Track track : logoRecognitionAnnotation.getTracksList()) { + // Video segment of a track. + VideoSegment segment = track.getSegment(); + Duration segmentStartTimeOffset = segment.getStartTimeOffset(); + System.out.printf( + "\n\tStart Time Offset : %s.%s\n", + segmentStartTimeOffset.getSeconds(), segmentStartTimeOffset.getNanos()); + Duration segmentEndTimeOffset = segment.getEndTimeOffset(); + System.out.printf( + "\tEnd Time Offset : %s.%s\n", + segmentEndTimeOffset.getSeconds(), segmentEndTimeOffset.getNanos()); + System.out.printf("\tConfidence : %s\n", track.getConfidence()); + // The object with timestamp and attributes per frame in the track. + for (TimestampedObject timestampedObject : track.getTimestampedObjectsList()) { + // Normalized Bounding box in a frame, where the object is located. + NormalizedBoundingBox normalizedBoundingBox = + timestampedObject.getNormalizedBoundingBox(); + System.out.printf("\n\t\tLeft : %s\n", normalizedBoundingBox.getLeft()); + System.out.printf("\t\tTop : %s\n", normalizedBoundingBox.getTop()); + System.out.printf("\t\tRight : %s\n", normalizedBoundingBox.getRight()); + System.out.printf("\t\tBottom : %s\n", normalizedBoundingBox.getBottom()); + // Optional. The attributes of the object in the bounding box. + for (DetectedAttribute attribute : timestampedObject.getAttributesList()) { + System.out.printf("\n\t\t\tName : %s\n", attribute.getName()); + System.out.printf("\t\t\tConfidence : %s\n", attribute.getConfidence()); + System.out.printf("\t\t\tValue : %s\n", attribute.getValue()); + } + } + // Optional. Attributes in the track level. + for (DetectedAttribute trackAttribute : track.getAttributesList()) { + System.out.printf("\n\t\tName : %s\n", trackAttribute.getName()); + System.out.printf("\t\tConfidence : %s\n", trackAttribute.getConfidence()); + System.out.printf("\t\tValue : %s\n", trackAttribute.getValue()); + } + } + // All video segments where the recognized logo appears. + // There might be multiple instances of the same logo class appearing in one VideoSegment. + for (VideoSegment logoRecognitionAnnotationSegment : + logoRecognitionAnnotation.getSegmentsList()) { + Duration logoRecognitionAnnotationSegmentStartTimeOffset = + logoRecognitionAnnotationSegment.getStartTimeOffset(); + System.out.printf( + "\n\tStart Time Offset : %s.%s\n", + logoRecognitionAnnotationSegmentStartTimeOffset.getSeconds(), + logoRecognitionAnnotationSegmentStartTimeOffset.getNanos()); + Duration logoRecognitionAnnotationSegmentEndTimeOffset = + logoRecognitionAnnotationSegment.getEndTimeOffset(); + System.out.printf( + "\tEnd Time Offset : %s.%s\n", + logoRecognitionAnnotationSegmentEndTimeOffset.getSeconds(), + logoRecognitionAnnotationSegmentEndTimeOffset.getNanos()); + } + } + } + } + // [END video_detect_logo_gcs] +} + diff --git a/video/cloud-client/src/test/java/com/example/video/DetectIT.java b/video/cloud-client/src/test/java/com/example/video/DetectIT.java index 86a0530bd54..8d8f2933044 100644 --- a/video/cloud-client/src/test/java/com/example/video/DetectIT.java +++ b/video/cloud-client/src/test/java/com/example/video/DetectIT.java @@ -21,32 +21,35 @@ import com.google.cloud.videointelligence.v1.ObjectTrackingAnnotation; import com.google.cloud.videointelligence.v1.TextAnnotation; import com.google.cloud.videointelligence.v1.VideoAnnotationResults; + import java.io.ByteArrayOutputStream; import java.io.PrintStream; import java.util.Arrays; import java.util.List; + import org.junit.After; import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; import org.junit.runners.JUnit4; -/** Tests for video analysis sample. */ +/** + * Tests for video analysis sample. + */ @RunWith(JUnit4.class) @SuppressWarnings("checkstyle:abbreviationaswordinname") public class DetectIT { - private ByteArrayOutputStream bout; - private PrintStream out; - static final String LABEL_GCS_LOCATION = "gs://cloud-samples-data/video/cat.mp4"; static final String LABEL_FILE_LOCATION = "./resources/cat.mp4"; static final String SHOTS_FILE_LOCATION = "gs://cloud-samples-data/video/gbikes_dinosaur.mp4"; - static final String EXPLICIT_CONTENT_LOCATION = "gs://cloud-samples-data/video/cat.mp4"; + static final String EXPLICIT_CONTENT_LOCATION = "gs://cloud-samples-data/video/cat.mp4"; static final String SPEECH_GCS_LOCATION = "gs://java-docs-samples-testing/video/googlework_short.mp4"; private static final List POSSIBLE_TEXTS = Arrays.asList( - "Google", "SUR", "SUR", "ROTO", "Vice President", "58oo9", "LONDRES", "OMAR", "PARIS", - "METRO", "RUE", "CARLO"); + "Google", "SUR", "SUR", "ROTO", "Vice President", "58oo9", "LONDRES", "OMAR", "PARIS", + "METRO", "RUE", "CARLO"); + private ByteArrayOutputStream bout; + private PrintStream out; @Before public void setUp() { @@ -78,6 +81,28 @@ public void testLabelsFile() throws Exception { assertThat(got.toUpperCase()).contains("WHISKERS"); } + @Test + public void testLogoDetect() throws Exception { + LogoDetection.detectLogo("resources/googlework_short.mp4"); + String got = bout.toString(); + + assertThat(got).contains("Description : Google Maps"); + assertThat(got).contains("Confidence"); + assertThat(got).contains("Start Time Offset"); + assertThat(got).contains("End Time Offset"); + } + + @Test + public void testLogoDetectGcs() throws Exception { + LogoDetectionGcs.detectLogoGcs("gs://cloud-samples-data/video/googlework_tiny.mp4"); + String got = bout.toString(); + + assertThat(got).contains("Description : Google Maps"); + assertThat(got).contains("Confidence"); + assertThat(got).contains("Start Time Offset"); + assertThat(got).contains("End Time Offset"); + } + @Test public void testExplicitContent() throws Exception { String[] args = {"explicit-content", EXPLICIT_CONTENT_LOCATION}; From 1e3a9cc3907b1db70b322f55a450b7a063d9aa8d Mon Sep 17 00:00:00 2001 From: Mike <45373284+munkhuushmgl@users.noreply.github.com> Date: Wed, 18 Mar 2020 11:14:36 -0700 Subject: [PATCH 02/14] Update video/cloud-client/src/main/java/com/example/video/LogoDetection.java Co-Authored-By: Noah Negrey --- .../java/com/example/video/LogoDetection.java | 59 ++++++++++--------- 1 file changed, 32 insertions(+), 27 deletions(-) diff --git a/video/cloud-client/src/main/java/com/example/video/LogoDetection.java b/video/cloud-client/src/main/java/com/example/video/LogoDetection.java index a5a0f4da1f3..b8f55bfadaf 100644 --- a/video/cloud-client/src/main/java/com/example/video/LogoDetection.java +++ b/video/cloud-client/src/main/java/com/example/video/LogoDetection.java @@ -76,36 +76,41 @@ public static void detectLogo(String filePath) throws Exception { System.out.printf("Entity Id : %s\n", entity.getEntityId()); // Textual description, e.g. `Google`. System.out.printf("Description : %s\n", entity.getDescription()); - // All logo tracks where the recognized logo appears. Each track corresponds - // to one logo instance appearing in consecutive frames. +// All logo tracks where the recognized logo appears. Each track corresponds to one logo + // instance appearing in consecutive frames. for (Track track : logoRecognitionAnnotation.getTracksList()) { + // Video segment of a track. VideoSegment segment = track.getSegment(); Duration segmentStartTimeOffset = segment.getStartTimeOffset(); System.out.printf( - "\n\tStart Time Offset : %s.%s\n", - segmentStartTimeOffset.getSeconds(), segmentStartTimeOffset.getNanos()); + "\n\tStart Time Offset: %s.%s\n", + segmentStartTimeOffset.getSeconds(), segmentStartTimeOffset.getNanos()); Duration segmentEndTimeOffset = segment.getEndTimeOffset(); System.out.printf( - "\tEnd Time Offset : %s.%s\n", - segmentEndTimeOffset.getSeconds(), segmentEndTimeOffset.getNanos()); - System.out.printf("\tConfidence : %s\n", track.getConfidence()); + "\tEnd Time Offset: %s.%s\n", + segmentEndTimeOffset.getSeconds(), segmentEndTimeOffset.getNanos()); + System.out.printf("\tConfidence: %s\n", track.getConfidence()); + // The object with timestamp and attributes per frame in the track. for (TimestampedObject timestampedObject : track.getTimestampedObjectsList()) { + // Normalized Bounding box in a frame, where the object is located. NormalizedBoundingBox normalizedBoundingBox = - timestampedObject.getNormalizedBoundingBox(); - System.out.printf("\n\t\tLeft : %s\n", normalizedBoundingBox.getLeft()); - System.out.printf("\t\tTop : %s\n", normalizedBoundingBox.getTop()); - System.out.printf("\t\tRight : %s\n", normalizedBoundingBox.getRight()); - System.out.printf("\t\tBottom : %s\n", normalizedBoundingBox.getBottom()); + timestampedObject.getNormalizedBoundingBox(); + System.out.printf("\n\t\tLeft: %s\n", normalizedBoundingBox.getLeft()); + System.out.printf("\t\tTop: %s\n", normalizedBoundingBox.getTop()); + System.out.printf("\t\tRight: %s\n", normalizedBoundingBox.getRight()); + System.out.printf("\t\tBottom: %s\n", normalizedBoundingBox.getBottom()); + // Optional. The attributes of the object in the bounding box. for (DetectedAttribute attribute : timestampedObject.getAttributesList()) { - System.out.printf("\n\t\t\tName : %s\n", attribute.getName()); - System.out.printf("\t\t\tConfidence : %s\n", attribute.getConfidence()); - System.out.printf("\t\t\tValue : %s\n", attribute.getValue()); + System.out.printf("\n\t\t\tName: %s\n", attribute.getName()); + System.out.printf("\t\t\tConfidence: %s\n", attribute.getConfidence()); + System.out.printf("\t\t\tValue: %s\n", attribute.getValue()); } } + // Optional. Attributes in the track level. for (DetectedAttribute trackAttribute : track.getAttributesList()) { System.out.printf("\n\t\tName : %s\n", trackAttribute.getName()); @@ -113,26 +118,26 @@ public static void detectLogo(String filePath) throws Exception { System.out.printf("\t\tValue : %s\n", trackAttribute.getValue()); } } - // All video segments where the recognized logo appears. - // There might be multiple instances of the same logo class appearing in one VideoSegment. + + // All video segments where the recognized logo appears. There might be multiple instances + // of the same logo class appearing in one VideoSegment. for (VideoSegment logoRecognitionAnnotationSegment : - logoRecognitionAnnotation.getSegmentsList()) { + logoRecognitionAnnotation.getSegmentsList()) { Duration logoRecognitionAnnotationSegmentStartTimeOffset = - logoRecognitionAnnotationSegment.getStartTimeOffset(); + logoRecognitionAnnotationSegment.getStartTimeOffset(); System.out.printf( - "\n\tStart Time Offset : %s.%s\n", - logoRecognitionAnnotationSegmentStartTimeOffset.getSeconds(), - logoRecognitionAnnotationSegmentStartTimeOffset.getNanos()); + "\n\tStart Time Offset : %s.%s\n", + logoRecognitionAnnotationSegmentStartTimeOffset.getSeconds(), + logoRecognitionAnnotationSegmentStartTimeOffset.getNanos()); Duration logoRecognitionAnnotationSegmentEndTimeOffset = - logoRecognitionAnnotationSegment.getEndTimeOffset(); + logoRecognitionAnnotationSegment.getEndTimeOffset(); System.out.printf( - "\tEnd Time Offset : %s.%s\n", - logoRecognitionAnnotationSegmentEndTimeOffset.getSeconds(), - logoRecognitionAnnotationSegmentEndTimeOffset.getNanos()); + "\tEnd Time Offset : %s.%s\n", + logoRecognitionAnnotationSegmentEndTimeOffset.getSeconds(), + logoRecognitionAnnotationSegmentEndTimeOffset.getNanos()); } } } } // [END video_detect_logo] } - From 6a9bcf28e3713f7c41d809392c580054205f783f Mon Sep 17 00:00:00 2001 From: Mike <45373284+munkhuushmgl@users.noreply.github.com> Date: Wed, 18 Mar 2020 11:15:02 -0700 Subject: [PATCH 03/14] Update video/cloud-client/src/main/java/com/example/video/LogoDetection.java Co-Authored-By: Noah Negrey --- .../src/main/java/com/example/video/LogoDetection.java | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/video/cloud-client/src/main/java/com/example/video/LogoDetection.java b/video/cloud-client/src/main/java/com/example/video/LogoDetection.java index b8f55bfadaf..245bcf5c516 100644 --- a/video/cloud-client/src/main/java/com/example/video/LogoDetection.java +++ b/video/cloud-client/src/main/java/com/example/video/LogoDetection.java @@ -48,7 +48,10 @@ public static void detectLogo() throws Exception { // [START video_detect_logo] public static void detectLogo(String filePath) throws Exception { - try (VideoIntelligenceServiceClient client = VideoIntelligenceServiceClient.create()) { + // Initialize client that will be used to send requests. This client only needs to be created + // once, and can be reused for multiple requests. After completing all of your requests, call + // the "close" method on the client to safely clean up any remaining background resources. + try (VideoIntelligenceServiceClient client = VideoIntelligenceServiceClient.create()) {``` // Read file Path path = Paths.get(filePath); byte[] data = Files.readAllBytes(path); From ab97a535168d3ba3bb9f89c1b7fb9915a9628a73 Mon Sep 17 00:00:00 2001 From: Mike <45373284+munkhuushmgl@users.noreply.github.com> Date: Wed, 18 Mar 2020 11:22:56 -0700 Subject: [PATCH 04/14] Update video/cloud-client/src/main/java/com/example/video/LogoDetection.java Co-Authored-By: Noah Negrey --- .../src/main/java/com/example/video/LogoDetection.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/video/cloud-client/src/main/java/com/example/video/LogoDetection.java b/video/cloud-client/src/main/java/com/example/video/LogoDetection.java index 245bcf5c516..acb7ef6ac24 100644 --- a/video/cloud-client/src/main/java/com/example/video/LogoDetection.java +++ b/video/cloud-client/src/main/java/com/example/video/LogoDetection.java @@ -15,7 +15,7 @@ */ package com.example.video; - +// [START video_detect_logo] import com.google.api.gax.longrunning.OperationFuture; import com.google.cloud.videointelligence.v1.AnnotateVideoProgress; import com.google.cloud.videointelligence.v1.AnnotateVideoRequest; From e470cd06d9814c2c3d2fc397ad4421807e635a4a Mon Sep 17 00:00:00 2001 From: Mike Ganbold Date: Wed, 18 Mar 2020 12:59:05 -0700 Subject: [PATCH 05/14] made requested changes --- .../java/com/example/video/LogoDetection.java | 26 ++++---- .../com/example/video/LogoDetectionGcs.java | 60 +++++++++++-------- .../test/java/com/example/video/DetectIT.java | 22 ------- .../com/example/video/DetectLogoGcsTest.java | 53 ++++++++++++++++ .../com/example/video/DetectLogoTest.java | 53 ++++++++++++++++ 5 files changed, 157 insertions(+), 57 deletions(-) create mode 100644 video/cloud-client/src/test/java/com/example/video/DetectLogoGcsTest.java create mode 100644 video/cloud-client/src/test/java/com/example/video/DetectLogoTest.java diff --git a/video/cloud-client/src/main/java/com/example/video/LogoDetection.java b/video/cloud-client/src/main/java/com/example/video/LogoDetection.java index acb7ef6ac24..b39f55d9b3f 100644 --- a/video/cloud-client/src/main/java/com/example/video/LogoDetection.java +++ b/video/cloud-client/src/main/java/com/example/video/LogoDetection.java @@ -15,7 +15,9 @@ */ package com.example.video; + // [START video_detect_logo] + import com.google.api.gax.longrunning.OperationFuture; import com.google.cloud.videointelligence.v1.AnnotateVideoProgress; import com.google.cloud.videointelligence.v1.AnnotateVideoRequest; @@ -32,38 +34,41 @@ import com.google.cloud.videointelligence.v1.VideoSegment; import com.google.protobuf.ByteString; import com.google.protobuf.Duration; - +import java.io.IOException; import java.nio.file.Files; import java.nio.file.Path; import java.nio.file.Paths; +import java.util.concurrent.ExecutionException; import java.util.concurrent.TimeUnit; +import java.util.concurrent.TimeoutException; public class LogoDetection { public static void detectLogo() throws Exception { // TODO(developer): Replace these variables before running the sample. - String localFilePath = "resources/googlework_short.mp4"; + String localFilePath = "path/to/your/video.mp4"; detectLogo(localFilePath); } - // [START video_detect_logo] - public static void detectLogo(String filePath) throws Exception { + public static void detectLogo(String filePath) + throws IOException, ExecutionException, InterruptedException, TimeoutException { // Initialize client that will be used to send requests. This client only needs to be created // once, and can be reused for multiple requests. After completing all of your requests, call // the "close" method on the client to safely clean up any remaining background resources. - try (VideoIntelligenceServiceClient client = VideoIntelligenceServiceClient.create()) {``` + try (VideoIntelligenceServiceClient client = VideoIntelligenceServiceClient.create()) { // Read file Path path = Paths.get(filePath); byte[] data = Files.readAllBytes(path); // Create the request - AnnotateVideoRequest request = AnnotateVideoRequest.newBuilder() + AnnotateVideoRequest request = + AnnotateVideoRequest.newBuilder() .setInputContent(ByteString.copyFrom(data)) .addFeatures(Feature.LOGO_RECOGNITION) .build(); // asynchronously perform object tracking on videos OperationFuture future = - client.annotateVideoAsync(request); + client.annotateVideoAsync(request); System.out.println("Waiting for operation to complete..."); // The first result is retrieved because a single video was processed. @@ -72,14 +77,13 @@ public static void detectLogo(String filePath) throws Exception { // Annotations for list of logos detected, tracked and recognized in video. for (LogoRecognitionAnnotation logoRecognitionAnnotation : - annotationResult.getLogoRecognitionAnnotationsList()) { + annotationResult.getLogoRecognitionAnnotationsList()) { Entity entity = logoRecognitionAnnotation.getEntity(); // Opaque entity ID. Some IDs may be available in // [Google Knowledge Graph Search API](https://developers.google.com/knowledge-graph/). System.out.printf("Entity Id : %s\n", entity.getEntityId()); - // Textual description, e.g. `Google`. System.out.printf("Description : %s\n", entity.getDescription()); -// All logo tracks where the recognized logo appears. Each track corresponds to one logo + // All logo tracks where the recognized logo appears. Each track corresponds to one logo // instance appearing in consecutive frames. for (Track track : logoRecognitionAnnotation.getTracksList()) { @@ -142,5 +146,5 @@ public static void detectLogo(String filePath) throws Exception { } } } - // [END video_detect_logo] } +// [END video_detect_logo] diff --git a/video/cloud-client/src/main/java/com/example/video/LogoDetectionGcs.java b/video/cloud-client/src/main/java/com/example/video/LogoDetectionGcs.java index 6c29b22a36d..438c65cbc72 100644 --- a/video/cloud-client/src/main/java/com/example/video/LogoDetectionGcs.java +++ b/video/cloud-client/src/main/java/com/example/video/LogoDetectionGcs.java @@ -16,6 +16,8 @@ package com.example.video; +// [START video_detect_logo_gcs] + import com.google.api.gax.longrunning.OperationFuture; import com.google.cloud.videointelligence.v1.AnnotateVideoProgress; import com.google.cloud.videointelligence.v1.AnnotateVideoRequest; @@ -31,29 +33,35 @@ import com.google.cloud.videointelligence.v1.VideoIntelligenceServiceClient; import com.google.cloud.videointelligence.v1.VideoSegment; import com.google.protobuf.Duration; - +import java.io.IOException; +import java.util.concurrent.ExecutionException; import java.util.concurrent.TimeUnit; +import java.util.concurrent.TimeoutException; public class LogoDetectionGcs { public static void detectLogoGcs() throws Exception { // TODO(developer): Replace these variables before running the sample. - String gcsUri = "gs://cloud-samples-data/video/googlework_short.mp4"; + String gcsUri = "gs://path/to/your/bucket/video.mp4"; detectLogoGcs(gcsUri); } - // [START video_detect_logo_gcs] - public static void detectLogoGcs(String inputUri) throws Exception { + public static void detectLogoGcs(String inputUri) + throws IOException, ExecutionException, InterruptedException, TimeoutException { + // Initialize client that will be used to send requests. This client only needs to be created + // once, and can be reused for multiple requests. After completing all of your requests, call + // the "close" method on the client to safely clean up any remaining background resources. try (VideoIntelligenceServiceClient client = VideoIntelligenceServiceClient.create()) { // Create the request - AnnotateVideoRequest request = AnnotateVideoRequest.newBuilder() + AnnotateVideoRequest request = + AnnotateVideoRequest.newBuilder() .setInputUri(inputUri) .addFeatures(Feature.LOGO_RECOGNITION) .build(); // asynchronously perform object tracking on videos OperationFuture future = - client.annotateVideoAsync(request); + client.annotateVideoAsync(request); System.out.println("Waiting for operation to complete..."); // The first result is retrieved because a single video was processed. @@ -62,36 +70,39 @@ public static void detectLogoGcs(String inputUri) throws Exception { // Annotations for list of logos detected, tracked and recognized in video. for (LogoRecognitionAnnotation logoRecognitionAnnotation : - annotationResult.getLogoRecognitionAnnotationsList()) { + annotationResult.getLogoRecognitionAnnotationsList()) { Entity entity = logoRecognitionAnnotation.getEntity(); // Opaque entity ID. Some IDs may be available in // [Google Knowledge Graph Search API](https://developers.google.com/knowledge-graph/). System.out.printf("Entity Id : %s\n", entity.getEntityId()); - // Textual description, e.g. `Google`. System.out.printf("Description : %s\n", entity.getDescription()); // All logo tracks where the recognized logo appears. Each track corresponds // to one logo instance appearing in consecutive frames. for (Track track : logoRecognitionAnnotation.getTracksList()) { + // Video segment of a track. VideoSegment segment = track.getSegment(); Duration segmentStartTimeOffset = segment.getStartTimeOffset(); System.out.printf( - "\n\tStart Time Offset : %s.%s\n", - segmentStartTimeOffset.getSeconds(), segmentStartTimeOffset.getNanos()); + "\n\tStart Time Offset : %s.%s\n", + segmentStartTimeOffset.getSeconds(), segmentStartTimeOffset.getNanos()); Duration segmentEndTimeOffset = segment.getEndTimeOffset(); System.out.printf( - "\tEnd Time Offset : %s.%s\n", - segmentEndTimeOffset.getSeconds(), segmentEndTimeOffset.getNanos()); + "\tEnd Time Offset : %s.%s\n", + segmentEndTimeOffset.getSeconds(), segmentEndTimeOffset.getNanos()); System.out.printf("\tConfidence : %s\n", track.getConfidence()); + // The object with timestamp and attributes per frame in the track. for (TimestampedObject timestampedObject : track.getTimestampedObjectsList()) { + // Normalized Bounding box in a frame, where the object is located. NormalizedBoundingBox normalizedBoundingBox = - timestampedObject.getNormalizedBoundingBox(); + timestampedObject.getNormalizedBoundingBox(); System.out.printf("\n\t\tLeft : %s\n", normalizedBoundingBox.getLeft()); System.out.printf("\t\tTop : %s\n", normalizedBoundingBox.getTop()); System.out.printf("\t\tRight : %s\n", normalizedBoundingBox.getRight()); System.out.printf("\t\tBottom : %s\n", normalizedBoundingBox.getBottom()); + // Optional. The attributes of the object in the bounding box. for (DetectedAttribute attribute : timestampedObject.getAttributesList()) { System.out.printf("\n\t\t\tName : %s\n", attribute.getName()); @@ -99,6 +110,7 @@ public static void detectLogoGcs(String inputUri) throws Exception { System.out.printf("\t\t\tValue : %s\n", attribute.getValue()); } } + // Optional. Attributes in the track level. for (DetectedAttribute trackAttribute : track.getAttributesList()) { System.out.printf("\n\t\tName : %s\n", trackAttribute.getName()); @@ -106,26 +118,26 @@ public static void detectLogoGcs(String inputUri) throws Exception { System.out.printf("\t\tValue : %s\n", trackAttribute.getValue()); } } + // All video segments where the recognized logo appears. // There might be multiple instances of the same logo class appearing in one VideoSegment. for (VideoSegment logoRecognitionAnnotationSegment : - logoRecognitionAnnotation.getSegmentsList()) { + logoRecognitionAnnotation.getSegmentsList()) { Duration logoRecognitionAnnotationSegmentStartTimeOffset = - logoRecognitionAnnotationSegment.getStartTimeOffset(); + logoRecognitionAnnotationSegment.getStartTimeOffset(); System.out.printf( - "\n\tStart Time Offset : %s.%s\n", - logoRecognitionAnnotationSegmentStartTimeOffset.getSeconds(), - logoRecognitionAnnotationSegmentStartTimeOffset.getNanos()); + "\n\tStart Time Offset : %s.%s\n", + logoRecognitionAnnotationSegmentStartTimeOffset.getSeconds(), + logoRecognitionAnnotationSegmentStartTimeOffset.getNanos()); Duration logoRecognitionAnnotationSegmentEndTimeOffset = - logoRecognitionAnnotationSegment.getEndTimeOffset(); + logoRecognitionAnnotationSegment.getEndTimeOffset(); System.out.printf( - "\tEnd Time Offset : %s.%s\n", - logoRecognitionAnnotationSegmentEndTimeOffset.getSeconds(), - logoRecognitionAnnotationSegmentEndTimeOffset.getNanos()); + "\tEnd Time Offset : %s.%s\n", + logoRecognitionAnnotationSegmentEndTimeOffset.getSeconds(), + logoRecognitionAnnotationSegmentEndTimeOffset.getNanos()); } } } } - // [END video_detect_logo_gcs] } - +// [END video_detect_logo_gcs] diff --git a/video/cloud-client/src/test/java/com/example/video/DetectIT.java b/video/cloud-client/src/test/java/com/example/video/DetectIT.java index 8d8f2933044..a9710548b80 100644 --- a/video/cloud-client/src/test/java/com/example/video/DetectIT.java +++ b/video/cloud-client/src/test/java/com/example/video/DetectIT.java @@ -81,28 +81,6 @@ public void testLabelsFile() throws Exception { assertThat(got.toUpperCase()).contains("WHISKERS"); } - @Test - public void testLogoDetect() throws Exception { - LogoDetection.detectLogo("resources/googlework_short.mp4"); - String got = bout.toString(); - - assertThat(got).contains("Description : Google Maps"); - assertThat(got).contains("Confidence"); - assertThat(got).contains("Start Time Offset"); - assertThat(got).contains("End Time Offset"); - } - - @Test - public void testLogoDetectGcs() throws Exception { - LogoDetectionGcs.detectLogoGcs("gs://cloud-samples-data/video/googlework_tiny.mp4"); - String got = bout.toString(); - - assertThat(got).contains("Description : Google Maps"); - assertThat(got).contains("Confidence"); - assertThat(got).contains("Start Time Offset"); - assertThat(got).contains("End Time Offset"); - } - @Test public void testExplicitContent() throws Exception { String[] args = {"explicit-content", EXPLICIT_CONTENT_LOCATION}; diff --git a/video/cloud-client/src/test/java/com/example/video/DetectLogoGcsTest.java b/video/cloud-client/src/test/java/com/example/video/DetectLogoGcsTest.java new file mode 100644 index 00000000000..35b91233983 --- /dev/null +++ b/video/cloud-client/src/test/java/com/example/video/DetectLogoGcsTest.java @@ -0,0 +1,53 @@ +/* + * Copyright 2020 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. + */ + +package com.example.video; + +import static com.google.common.truth.Truth.assertThat; + +import java.io.ByteArrayOutputStream; +import java.io.PrintStream; +import org.junit.After; +import org.junit.Before; +import org.junit.Test; + +public class DetectLogoGcsTest { + private ByteArrayOutputStream bout; + private PrintStream out; + + @Before + public void setUp() { + bout = new ByteArrayOutputStream(); + out = new PrintStream(bout); + System.setOut(out); + } + + @After + public void tearDown() { + System.setOut(null); + } + + @Test + public void testLogoDetectGcs() throws Exception { + LogoDetectionGcs.detectLogoGcs("gs://cloud-samples-data/video/googlework_tiny.mp4"); + String got = bout.toString(); + + assertThat(got).contains("Description : Google Maps"); + assertThat(got).contains("Confidence"); + assertThat(got).contains("Start Time Offset"); + assertThat(got).contains("End Time Offset"); + } +} diff --git a/video/cloud-client/src/test/java/com/example/video/DetectLogoTest.java b/video/cloud-client/src/test/java/com/example/video/DetectLogoTest.java new file mode 100644 index 00000000000..76565430189 --- /dev/null +++ b/video/cloud-client/src/test/java/com/example/video/DetectLogoTest.java @@ -0,0 +1,53 @@ +/* + * Copyright 2020 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. + */ + +package com.example.video; + +import static com.google.common.truth.Truth.assertThat; + +import java.io.ByteArrayOutputStream; +import java.io.PrintStream; +import org.junit.After; +import org.junit.Before; +import org.junit.Test; + +public class DetectLogoTest { + private ByteArrayOutputStream bout; + private PrintStream out; + + @Before + public void setUp() { + bout = new ByteArrayOutputStream(); + out = new PrintStream(bout); + System.setOut(out); + } + + @After + public void tearDown() { + System.setOut(null); + } + + @Test + public void testLogoDetect() throws Exception { + LogoDetection.detectLogo("resources/googlework_short.mp4"); + String got = bout.toString(); + + assertThat(got).contains("Description : Google Maps"); + assertThat(got).contains("Confidence"); + assertThat(got).contains("Start Time Offset"); + assertThat(got).contains("End Time Offset"); + } +} From e2b736fddf0a1334543c9c883500fdec576b985a Mon Sep 17 00:00:00 2001 From: Mike <45373284+munkhuushmgl@users.noreply.github.com> Date: Wed, 18 Mar 2020 13:13:39 -0700 Subject: [PATCH 06/14] Update video/cloud-client/src/test/java/com/example/video/DetectLogoGcsTest.java Co-Authored-By: Noah Negrey --- .../src/test/java/com/example/video/DetectLogoGcsTest.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/video/cloud-client/src/test/java/com/example/video/DetectLogoGcsTest.java b/video/cloud-client/src/test/java/com/example/video/DetectLogoGcsTest.java index 35b91233983..e58a4f8af8c 100644 --- a/video/cloud-client/src/test/java/com/example/video/DetectLogoGcsTest.java +++ b/video/cloud-client/src/test/java/com/example/video/DetectLogoGcsTest.java @@ -45,7 +45,7 @@ public void testLogoDetectGcs() throws Exception { LogoDetectionGcs.detectLogoGcs("gs://cloud-samples-data/video/googlework_tiny.mp4"); String got = bout.toString(); - assertThat(got).contains("Description : Google Maps"); + assertThat(got).contains("Description"); assertThat(got).contains("Confidence"); assertThat(got).contains("Start Time Offset"); assertThat(got).contains("End Time Offset"); From b3fe692a45d7725191d61b3554d1fe4c58e5974e Mon Sep 17 00:00:00 2001 From: Mike <45373284+munkhuushmgl@users.noreply.github.com> Date: Wed, 18 Mar 2020 13:15:04 -0700 Subject: [PATCH 07/14] Update video/cloud-client/src/test/java/com/example/video/DetectLogoTest.java Co-Authored-By: Noah Negrey --- .../src/test/java/com/example/video/DetectLogoTest.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/video/cloud-client/src/test/java/com/example/video/DetectLogoTest.java b/video/cloud-client/src/test/java/com/example/video/DetectLogoTest.java index 76565430189..abadde3536d 100644 --- a/video/cloud-client/src/test/java/com/example/video/DetectLogoTest.java +++ b/video/cloud-client/src/test/java/com/example/video/DetectLogoTest.java @@ -45,7 +45,7 @@ public void testLogoDetect() throws Exception { LogoDetection.detectLogo("resources/googlework_short.mp4"); String got = bout.toString(); - assertThat(got).contains("Description : Google Maps"); + assertThat(got).contains("Description"); assertThat(got).contains("Confidence"); assertThat(got).contains("Start Time Offset"); assertThat(got).contains("End Time Offset"); From d4931410f45fc87c20e44c807ca15be2ead71102 Mon Sep 17 00:00:00 2001 From: Mike Ganbold Date: Wed, 18 Mar 2020 13:16:00 -0700 Subject: [PATCH 08/14] added spec exceptions --- .../src/test/java/com/example/video/DetectLogoGcsTest.java | 6 +++++- .../src/test/java/com/example/video/DetectLogoTest.java | 6 +++++- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/video/cloud-client/src/test/java/com/example/video/DetectLogoGcsTest.java b/video/cloud-client/src/test/java/com/example/video/DetectLogoGcsTest.java index 35b91233983..3070c4b68ad 100644 --- a/video/cloud-client/src/test/java/com/example/video/DetectLogoGcsTest.java +++ b/video/cloud-client/src/test/java/com/example/video/DetectLogoGcsTest.java @@ -19,7 +19,10 @@ import static com.google.common.truth.Truth.assertThat; import java.io.ByteArrayOutputStream; +import java.io.IOException; import java.io.PrintStream; +import java.util.concurrent.ExecutionException; +import java.util.concurrent.TimeoutException; import org.junit.After; import org.junit.Before; import org.junit.Test; @@ -41,7 +44,8 @@ public void tearDown() { } @Test - public void testLogoDetectGcs() throws Exception { + public void testLogoDetectGcs() + throws IOException, ExecutionException, InterruptedException, TimeoutException { LogoDetectionGcs.detectLogoGcs("gs://cloud-samples-data/video/googlework_tiny.mp4"); String got = bout.toString(); diff --git a/video/cloud-client/src/test/java/com/example/video/DetectLogoTest.java b/video/cloud-client/src/test/java/com/example/video/DetectLogoTest.java index 76565430189..c8b7d987a8a 100644 --- a/video/cloud-client/src/test/java/com/example/video/DetectLogoTest.java +++ b/video/cloud-client/src/test/java/com/example/video/DetectLogoTest.java @@ -19,7 +19,10 @@ import static com.google.common.truth.Truth.assertThat; import java.io.ByteArrayOutputStream; +import java.io.IOException; import java.io.PrintStream; +import java.util.concurrent.ExecutionException; +import java.util.concurrent.TimeoutException; import org.junit.After; import org.junit.Before; import org.junit.Test; @@ -41,7 +44,8 @@ public void tearDown() { } @Test - public void testLogoDetect() throws Exception { + public void testLogoDetect() + throws IOException, ExecutionException, InterruptedException, TimeoutException { LogoDetection.detectLogo("resources/googlework_short.mp4"); String got = bout.toString(); From bf9073f7d333e906ee1b72e8874c811975baff7b Mon Sep 17 00:00:00 2001 From: Mike <45373284+munkhuushmgl@users.noreply.github.com> Date: Wed, 18 Mar 2020 13:18:37 -0700 Subject: [PATCH 09/14] Update video/cloud-client/src/main/java/com/example/video/LogoDetection.java Co-Authored-By: Noah Negrey --- .../src/main/java/com/example/video/LogoDetection.java | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/video/cloud-client/src/main/java/com/example/video/LogoDetection.java b/video/cloud-client/src/main/java/com/example/video/LogoDetection.java index b39f55d9b3f..f7253555367 100644 --- a/video/cloud-client/src/main/java/com/example/video/LogoDetection.java +++ b/video/cloud-client/src/main/java/com/example/video/LogoDetection.java @@ -88,15 +88,13 @@ public static void detectLogo(String filePath) for (Track track : logoRecognitionAnnotation.getTracksList()) { // Video segment of a track. - VideoSegment segment = track.getSegment(); - Duration segmentStartTimeOffset = segment.getStartTimeOffset(); + Duration startTimeOffset = track.getSegment().getStartTimeOffset(); System.out.printf( "\n\tStart Time Offset: %s.%s\n", - segmentStartTimeOffset.getSeconds(), segmentStartTimeOffset.getNanos()); - Duration segmentEndTimeOffset = segment.getEndTimeOffset(); + startTimeOffset.getSeconds(), startTimeOffset.getNanos()); + Duration endTimeOffset = track.getSegment().getEndTimeOffset(); System.out.printf( - "\tEnd Time Offset: %s.%s\n", - segmentEndTimeOffset.getSeconds(), segmentEndTimeOffset.getNanos()); + "\tEnd Time Offset: %s.%s\n", endTimeOffset.getSeconds(), endTimeOffset.getNanos()); System.out.printf("\tConfidence: %s\n", track.getConfidence()); // The object with timestamp and attributes per frame in the track. From e1a8851a5b538ebb7f57ef4c14d92d5e81c65852 Mon Sep 17 00:00:00 2001 From: Mike <45373284+munkhuushmgl@users.noreply.github.com> Date: Wed, 18 Mar 2020 13:18:55 -0700 Subject: [PATCH 10/14] Update video/cloud-client/src/main/java/com/example/video/LogoDetection.java Co-Authored-By: Noah Negrey --- .../main/java/com/example/video/LogoDetection.java | 13 +++---------- 1 file changed, 3 insertions(+), 10 deletions(-) diff --git a/video/cloud-client/src/main/java/com/example/video/LogoDetection.java b/video/cloud-client/src/main/java/com/example/video/LogoDetection.java index f7253555367..09a8fed0a87 100644 --- a/video/cloud-client/src/main/java/com/example/video/LogoDetection.java +++ b/video/cloud-client/src/main/java/com/example/video/LogoDetection.java @@ -126,20 +126,13 @@ public static void detectLogo(String filePath) // All video segments where the recognized logo appears. There might be multiple instances // of the same logo class appearing in one VideoSegment. - for (VideoSegment logoRecognitionAnnotationSegment : - logoRecognitionAnnotation.getSegmentsList()) { - Duration logoRecognitionAnnotationSegmentStartTimeOffset = - logoRecognitionAnnotationSegment.getStartTimeOffset(); + for (VideoSegment segment : logoRecognitionAnnotation.getSegmentsList()) { System.out.printf( "\n\tStart Time Offset : %s.%s\n", - logoRecognitionAnnotationSegmentStartTimeOffset.getSeconds(), - logoRecognitionAnnotationSegmentStartTimeOffset.getNanos()); - Duration logoRecognitionAnnotationSegmentEndTimeOffset = - logoRecognitionAnnotationSegment.getEndTimeOffset(); + segment.getStartTimeOffset().getSeconds(), segment.getStartTimeOffset().getNanos()); System.out.printf( "\tEnd Time Offset : %s.%s\n", - logoRecognitionAnnotationSegmentEndTimeOffset.getSeconds(), - logoRecognitionAnnotationSegmentEndTimeOffset.getNanos()); + segment.getEndTimeOffset().getSeconds(), segment.getEndTimeOffset().getNanos()); } } } From 44486c5281e55f5e7d09a715ba2dbec6293fc469 Mon Sep 17 00:00:00 2001 From: Mike Ganbold Date: Mon, 23 Mar 2020 14:39:35 -0700 Subject: [PATCH 11/14] clean up gcs code --- .../com/example/video/LogoDetectionGcs.java | 28 +++++++++---------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/video/cloud-client/src/main/java/com/example/video/LogoDetectionGcs.java b/video/cloud-client/src/main/java/com/example/video/LogoDetectionGcs.java index 438c65cbc72..7c5ede6046e 100644 --- a/video/cloud-client/src/main/java/com/example/video/LogoDetectionGcs.java +++ b/video/cloud-client/src/main/java/com/example/video/LogoDetectionGcs.java @@ -76,21 +76,21 @@ public static void detectLogoGcs(String inputUri) // [Google Knowledge Graph Search API](https://developers.google.com/knowledge-graph/). System.out.printf("Entity Id : %s\n", entity.getEntityId()); System.out.printf("Description : %s\n", entity.getDescription()); - // All logo tracks where the recognized logo appears. Each track corresponds - // to one logo instance appearing in consecutive frames. + // All logo tracks where the recognized logo appears. Each track corresponds to one logo + // instance appearing in consecutive frames. for (Track track : logoRecognitionAnnotation.getTracksList()) { // Video segment of a track. VideoSegment segment = track.getSegment(); Duration segmentStartTimeOffset = segment.getStartTimeOffset(); System.out.printf( - "\n\tStart Time Offset : %s.%s\n", + "\n\tStart Time Offset: %s.%s\n", segmentStartTimeOffset.getSeconds(), segmentStartTimeOffset.getNanos()); Duration segmentEndTimeOffset = segment.getEndTimeOffset(); System.out.printf( - "\tEnd Time Offset : %s.%s\n", + "\tEnd Time Offset: %s.%s\n", segmentEndTimeOffset.getSeconds(), segmentEndTimeOffset.getNanos()); - System.out.printf("\tConfidence : %s\n", track.getConfidence()); + System.out.printf("\tConfidence: %s\n", track.getConfidence()); // The object with timestamp and attributes per frame in the track. for (TimestampedObject timestampedObject : track.getTimestampedObjectsList()) { @@ -98,16 +98,16 @@ public static void detectLogoGcs(String inputUri) // Normalized Bounding box in a frame, where the object is located. NormalizedBoundingBox normalizedBoundingBox = timestampedObject.getNormalizedBoundingBox(); - System.out.printf("\n\t\tLeft : %s\n", normalizedBoundingBox.getLeft()); - System.out.printf("\t\tTop : %s\n", normalizedBoundingBox.getTop()); - System.out.printf("\t\tRight : %s\n", normalizedBoundingBox.getRight()); - System.out.printf("\t\tBottom : %s\n", normalizedBoundingBox.getBottom()); + System.out.printf("\n\t\tLeft: %s\n", normalizedBoundingBox.getLeft()); + System.out.printf("\t\tTop: %s\n", normalizedBoundingBox.getTop()); + System.out.printf("\t\tRight: %s\n", normalizedBoundingBox.getRight()); + System.out.printf("\t\tBottom: %s\n", normalizedBoundingBox.getBottom()); // Optional. The attributes of the object in the bounding box. for (DetectedAttribute attribute : timestampedObject.getAttributesList()) { - System.out.printf("\n\t\t\tName : %s\n", attribute.getName()); - System.out.printf("\t\t\tConfidence : %s\n", attribute.getConfidence()); - System.out.printf("\t\t\tValue : %s\n", attribute.getValue()); + System.out.printf("\n\t\t\tName: %s\n", attribute.getName()); + System.out.printf("\t\t\tConfidence: %s\n", attribute.getConfidence()); + System.out.printf("\t\t\tValue: %s\n", attribute.getValue()); } } @@ -119,8 +119,8 @@ public static void detectLogoGcs(String inputUri) } } - // All video segments where the recognized logo appears. - // There might be multiple instances of the same logo class appearing in one VideoSegment. + // All video segments where the recognized logo appears. There might be multiple instances + // of the same logo class appearing in one VideoSegment. for (VideoSegment logoRecognitionAnnotationSegment : logoRecognitionAnnotation.getSegmentsList()) { Duration logoRecognitionAnnotationSegmentStartTimeOffset = From 8ffe457ff01564ae409ee178c9afd46508636960 Mon Sep 17 00:00:00 2001 From: Mike <45373284+munkhuushmgl@users.noreply.github.com> Date: Mon, 23 Mar 2020 14:47:57 -0700 Subject: [PATCH 12/14] Update video/cloud-client/src/main/java/com/example/video/LogoDetectionGcs.java Co-Authored-By: Noah Negrey --- .../src/main/java/com/example/video/LogoDetectionGcs.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/video/cloud-client/src/main/java/com/example/video/LogoDetectionGcs.java b/video/cloud-client/src/main/java/com/example/video/LogoDetectionGcs.java index 7c5ede6046e..3e36080dc94 100644 --- a/video/cloud-client/src/main/java/com/example/video/LogoDetectionGcs.java +++ b/video/cloud-client/src/main/java/com/example/video/LogoDetectionGcs.java @@ -42,7 +42,7 @@ public class LogoDetectionGcs { public static void detectLogoGcs() throws Exception { // TODO(developer): Replace these variables before running the sample. - String gcsUri = "gs://path/to/your/bucket/video.mp4"; + String gcsUri = "gs://YOUR_BUCKET_ID/path/to/your/video.mp4"; detectLogoGcs(gcsUri); } From 317e889486caf968f38c4beef0d3adbfb009961f Mon Sep 17 00:00:00 2001 From: Mike <45373284+munkhuushmgl@users.noreply.github.com> Date: Mon, 23 Mar 2020 15:06:44 -0700 Subject: [PATCH 13/14] Update video/cloud-client/src/main/java/com/example/video/LogoDetectionGcs.java Co-Authored-By: Noah Negrey --- .../main/java/com/example/video/LogoDetectionGcs.java | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/video/cloud-client/src/main/java/com/example/video/LogoDetectionGcs.java b/video/cloud-client/src/main/java/com/example/video/LogoDetectionGcs.java index 3e36080dc94..ed835bcb1fe 100644 --- a/video/cloud-client/src/main/java/com/example/video/LogoDetectionGcs.java +++ b/video/cloud-client/src/main/java/com/example/video/LogoDetectionGcs.java @@ -81,15 +81,13 @@ public static void detectLogoGcs(String inputUri) for (Track track : logoRecognitionAnnotation.getTracksList()) { // Video segment of a track. - VideoSegment segment = track.getSegment(); - Duration segmentStartTimeOffset = segment.getStartTimeOffset(); + Duration startTimeOffset = track.getSegment().getStartTimeOffset(); System.out.printf( "\n\tStart Time Offset: %s.%s\n", - segmentStartTimeOffset.getSeconds(), segmentStartTimeOffset.getNanos()); - Duration segmentEndTimeOffset = segment.getEndTimeOffset(); + startTimeOffset.getSeconds(), startTimeOffset.getNanos()); + Duration endTimeOffset = track.getSegment().getEndTimeOffset(); System.out.printf( - "\tEnd Time Offset: %s.%s\n", - segmentEndTimeOffset.getSeconds(), segmentEndTimeOffset.getNanos()); + "\tEnd Time Offset: %s.%s\n", endTimeOffset.getSeconds(), endTimeOffset.getNanos()); System.out.printf("\tConfidence: %s\n", track.getConfidence()); // The object with timestamp and attributes per frame in the track. From 14237191b0e496e6bdc41942299e93d3435a7535 Mon Sep 17 00:00:00 2001 From: Mike <45373284+munkhuushmgl@users.noreply.github.com> Date: Mon, 23 Mar 2020 15:07:14 -0700 Subject: [PATCH 14/14] Update video/cloud-client/src/main/java/com/example/video/LogoDetectionGcs.java Co-Authored-By: Noah Negrey --- .../java/com/example/video/LogoDetectionGcs.java | 13 +++---------- 1 file changed, 3 insertions(+), 10 deletions(-) diff --git a/video/cloud-client/src/main/java/com/example/video/LogoDetectionGcs.java b/video/cloud-client/src/main/java/com/example/video/LogoDetectionGcs.java index ed835bcb1fe..ee054cfc6fd 100644 --- a/video/cloud-client/src/main/java/com/example/video/LogoDetectionGcs.java +++ b/video/cloud-client/src/main/java/com/example/video/LogoDetectionGcs.java @@ -119,20 +119,13 @@ public static void detectLogoGcs(String inputUri) // All video segments where the recognized logo appears. There might be multiple instances // of the same logo class appearing in one VideoSegment. - for (VideoSegment logoRecognitionAnnotationSegment : - logoRecognitionAnnotation.getSegmentsList()) { - Duration logoRecognitionAnnotationSegmentStartTimeOffset = - logoRecognitionAnnotationSegment.getStartTimeOffset(); + for (VideoSegment segment : logoRecognitionAnnotation.getSegmentsList()) { System.out.printf( "\n\tStart Time Offset : %s.%s\n", - logoRecognitionAnnotationSegmentStartTimeOffset.getSeconds(), - logoRecognitionAnnotationSegmentStartTimeOffset.getNanos()); - Duration logoRecognitionAnnotationSegmentEndTimeOffset = - logoRecognitionAnnotationSegment.getEndTimeOffset(); + segment.getStartTimeOffset().getSeconds(), segment.getStartTimeOffset().getNanos()); System.out.printf( "\tEnd Time Offset : %s.%s\n", - logoRecognitionAnnotationSegmentEndTimeOffset.getSeconds(), - logoRecognitionAnnotationSegmentEndTimeOffset.getNanos()); + segment.getEndTimeOffset().getSeconds(), segment.getEndTimeOffset().getNanos()); } } }