Skip to content

Commit 229be24

Browse files
authored
chore: migrate to owlbot (#664)
1 parent e85c705 commit 229be24

12 files changed

+189
-166
lines changed

video/src/main/java/beta/video/StreamingAutoMlObjectTracking.java

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,7 @@
3838

3939
class StreamingAutoMlObjectTracking {
4040

41-
public static void main(String[] args)
42-
throws IOException {
41+
public static void main(String[] args) throws IOException {
4342
// TODO(developer): Replace these variables before running the sample.
4443
String filePath = "YOUR_VIDEO_FILE";
4544
String projectId = "YOUR_PROJECT_ID";
@@ -64,9 +63,7 @@ static void streamingAutoMlObjectTracking(String filePath, String projectId, Str
6463
String.format("projects/%s/locations/us-central1/models/%s", projectId, modelId);
6564

6665
StreamingAutomlObjectTrackingConfig streamingAutomlObjectTrackingConfig =
67-
StreamingAutomlObjectTrackingConfig.newBuilder()
68-
.setModelName(modelPath)
69-
.build();
66+
StreamingAutomlObjectTrackingConfig.newBuilder().setModelName(modelPath).build();
7067

7168
StreamingVideoConfig streamingVideoConfig =
7269
StreamingVideoConfig.newBuilder()
@@ -79,9 +76,7 @@ static void streamingAutoMlObjectTracking(String filePath, String projectId, Str
7976

8077
// The first request must **only** contain the audio configuration:
8178
call.send(
82-
StreamingAnnotateVideoRequest.newBuilder()
83-
.setVideoConfig(streamingVideoConfig)
84-
.build());
79+
StreamingAnnotateVideoRequest.newBuilder().setVideoConfig(streamingVideoConfig).build());
8580

8681
// Subsequent requests must **only** contain the audio data.
8782
// Send the requests in chunks

video/src/main/java/beta/video/StreamingShotChangeDetection.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,8 +86,8 @@ static void streamingShotChangeDetection(String filePath)
8686
StreamingVideoAnnotationResults annotationResults = response.getAnnotationResults();
8787
if (response.hasError()) {
8888
System.out.println(response.getError().getMessage());
89-
System.out.format("Error was occured with the following status: %s\n",
90-
response.getError());
89+
System.out.format(
90+
"Error was occured with the following status: %s\n", response.getError());
9191
}
9292
for (VideoSegment segment : annotationResults.getShotAnnotationsList()) {
9393
double startTimeOffset =

video/src/main/java/com/example/video/Detect.java

Lines changed: 83 additions & 74 deletions
Large diffs are not rendered by default.

video/src/main/java/com/example/video/QuickstartSample.java

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -32,20 +32,19 @@
3232

3333
public class QuickstartSample {
3434

35-
/**
36-
* Demonstrates using the video intelligence client to detect labels in a video file.
37-
*/
35+
/** Demonstrates using the video intelligence client to detect labels in a video file. */
3836
public static void main(String[] args) throws Exception {
3937
// Instantiate a video intelligence client
4038
try (VideoIntelligenceServiceClient client = VideoIntelligenceServiceClient.create()) {
4139
// The Google Cloud Storage path to the video to annotate.
4240
String gcsUri = "gs://cloud-samples-data/video/cat.mp4";
4341

4442
// Create an operation that will contain the response when the operation completes.
45-
AnnotateVideoRequest request = AnnotateVideoRequest.newBuilder()
46-
.setInputUri(gcsUri)
47-
.addFeatures(Feature.LABEL_DETECTION)
48-
.build();
43+
AnnotateVideoRequest request =
44+
AnnotateVideoRequest.newBuilder()
45+
.setInputUri(gcsUri)
46+
.addFeatures(Feature.LABEL_DETECTION)
47+
.build();
4948

5049
OperationFuture<AnnotateVideoResponse, AnnotateVideoProgress> response =
5150
client.annotateVideoAsync(request);
@@ -61,18 +60,20 @@ public static void main(String[] args) throws Exception {
6160
System.out.println("Labels:");
6261
// get video segment label annotations
6362
for (LabelAnnotation annotation : result.getSegmentLabelAnnotationsList()) {
64-
System.out
65-
.println("Video label description : " + annotation.getEntity().getDescription());
63+
System.out.println(
64+
"Video label description : " + annotation.getEntity().getDescription());
6665
// categories
6766
for (Entity categoryEntity : annotation.getCategoryEntitiesList()) {
6867
System.out.println("Label Category description : " + categoryEntity.getDescription());
6968
}
7069
// segments
7170
for (LabelSegment segment : annotation.getSegmentsList()) {
72-
double startTime = segment.getSegment().getStartTimeOffset().getSeconds()
73-
+ segment.getSegment().getStartTimeOffset().getNanos() / 1e9;
74-
double endTime = segment.getSegment().getEndTimeOffset().getSeconds()
75-
+ segment.getSegment().getEndTimeOffset().getNanos() / 1e9;
71+
double startTime =
72+
segment.getSegment().getStartTimeOffset().getSeconds()
73+
+ segment.getSegment().getStartTimeOffset().getNanos() / 1e9;
74+
double endTime =
75+
segment.getSegment().getEndTimeOffset().getSeconds()
76+
+ segment.getSegment().getEndTimeOffset().getNanos() / 1e9;
7677
System.out.printf("Segment location : %.3f:%.3f\n", startTime, endTime);
7778
System.out.println("Confidence : " + segment.getConfidence());
7879
}

video/src/main/java/com/example/video/TextDetection.java

Lines changed: 38 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -51,10 +51,11 @@ public static VideoAnnotationResults detectText(String filePath) throws Exceptio
5151
byte[] data = Files.readAllBytes(path);
5252

5353
// Create the request
54-
AnnotateVideoRequest request = AnnotateVideoRequest.newBuilder()
55-
.setInputContent(ByteString.copyFrom(data))
56-
.addFeatures(Feature.TEXT_DETECTION)
57-
.build();
54+
AnnotateVideoRequest request =
55+
AnnotateVideoRequest.newBuilder()
56+
.setInputContent(ByteString.copyFrom(data))
57+
.addFeatures(Feature.TEXT_DETECTION)
58+
.build();
5859

5960
// asynchronously perform object tracking on videos
6061
OperationFuture<AnnotateVideoResponse, AnnotateVideoProgress> future =
@@ -77,25 +78,29 @@ public static VideoAnnotationResults detectText(String filePath) throws Exceptio
7778
Duration startTimeOffset = videoSegment.getStartTimeOffset();
7879
Duration endTimeOffset = videoSegment.getEndTimeOffset();
7980
// Display the offset times in seconds, 1e9 is part of the formula to convert nanos to seconds
80-
System.out.println(String.format("Start time: %.2f",
81-
startTimeOffset.getSeconds() + startTimeOffset.getNanos() / 1e9));
82-
System.out.println(String.format("End time: %.2f",
83-
endTimeOffset.getSeconds() + endTimeOffset.getNanos() / 1e9));
81+
System.out.println(
82+
String.format(
83+
"Start time: %.2f", startTimeOffset.getSeconds() + startTimeOffset.getNanos() / 1e9));
84+
System.out.println(
85+
String.format(
86+
"End time: %.2f", endTimeOffset.getSeconds() + endTimeOffset.getNanos() / 1e9));
8487

8588
// Show the first result for the first frame in the segment.
8689
TextFrame textFrame = textSegment.getFrames(0);
8790
Duration timeOffset = textFrame.getTimeOffset();
88-
System.out.println(String.format("Time offset for the first frame: %.2f",
89-
timeOffset.getSeconds() + timeOffset.getNanos() / 1e9));
91+
System.out.println(
92+
String.format(
93+
"Time offset for the first frame: %.2f",
94+
timeOffset.getSeconds() + timeOffset.getNanos() / 1e9));
9095

9196
// Display the rotated bounding box for where the text is on the frame.
9297
System.out.println("Rotated Bounding Box Vertices:");
9398
List<NormalizedVertex> vertices = textFrame.getRotatedBoundingBox().getVerticesList();
9499
for (NormalizedVertex normalizedVertex : vertices) {
95-
System.out.println(String.format(
96-
"\tVertex.x: %.2f, Vertex.y: %.2f",
97-
normalizedVertex.getX(),
98-
normalizedVertex.getY()));
100+
System.out.println(
101+
String.format(
102+
"\tVertex.x: %.2f, Vertex.y: %.2f",
103+
normalizedVertex.getX(), normalizedVertex.getY()));
99104
}
100105
return results;
101106
}
@@ -111,10 +116,11 @@ public static VideoAnnotationResults detectText(String filePath) throws Exceptio
111116
public static VideoAnnotationResults detectTextGcs(String gcsUri) throws Exception {
112117
try (VideoIntelligenceServiceClient client = VideoIntelligenceServiceClient.create()) {
113118
// Create the request
114-
AnnotateVideoRequest request = AnnotateVideoRequest.newBuilder()
115-
.setInputUri(gcsUri)
116-
.addFeatures(Feature.TEXT_DETECTION)
117-
.build();
119+
AnnotateVideoRequest request =
120+
AnnotateVideoRequest.newBuilder()
121+
.setInputUri(gcsUri)
122+
.addFeatures(Feature.TEXT_DETECTION)
123+
.build();
118124

119125
// asynchronously perform object tracking on videos
120126
OperationFuture<AnnotateVideoResponse, AnnotateVideoProgress> future =
@@ -137,25 +143,29 @@ public static VideoAnnotationResults detectTextGcs(String gcsUri) throws Excepti
137143
Duration startTimeOffset = videoSegment.getStartTimeOffset();
138144
Duration endTimeOffset = videoSegment.getEndTimeOffset();
139145
// Display the offset times in seconds, 1e9 is part of the formula to convert nanos to seconds
140-
System.out.println(String.format("Start time: %.2f",
141-
startTimeOffset.getSeconds() + startTimeOffset.getNanos() / 1e9));
142-
System.out.println(String.format("End time: %.2f",
143-
endTimeOffset.getSeconds() + endTimeOffset.getNanos() / 1e9));
146+
System.out.println(
147+
String.format(
148+
"Start time: %.2f", startTimeOffset.getSeconds() + startTimeOffset.getNanos() / 1e9));
149+
System.out.println(
150+
String.format(
151+
"End time: %.2f", endTimeOffset.getSeconds() + endTimeOffset.getNanos() / 1e9));
144152

145153
// Show the first result for the first frame in the segment.
146154
TextFrame textFrame = textSegment.getFrames(0);
147155
Duration timeOffset = textFrame.getTimeOffset();
148-
System.out.println(String.format("Time offset for the first frame: %.2f",
149-
timeOffset.getSeconds() + timeOffset.getNanos() / 1e9));
156+
System.out.println(
157+
String.format(
158+
"Time offset for the first frame: %.2f",
159+
timeOffset.getSeconds() + timeOffset.getNanos() / 1e9));
150160

151161
// Display the rotated bounding box for where the text is on the frame.
152162
System.out.println("Rotated Bounding Box Vertices:");
153163
List<NormalizedVertex> vertices = textFrame.getRotatedBoundingBox().getVerticesList();
154164
for (NormalizedVertex normalizedVertex : vertices) {
155-
System.out.println(String.format(
156-
"\tVertex.x: %.2f, Vertex.y: %.2f",
157-
normalizedVertex.getX(),
158-
normalizedVertex.getY()));
165+
System.out.println(
166+
String.format(
167+
"\tVertex.x: %.2f, Vertex.y: %.2f",
168+
normalizedVertex.getX(), normalizedVertex.getY()));
159169
}
160170
return results;
161171
}

video/src/main/java/com/example/video/TrackObjects.java

Lines changed: 30 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -50,11 +50,12 @@ public static VideoAnnotationResults trackObjects(String filePath) throws Except
5050
byte[] data = Files.readAllBytes(path);
5151

5252
// Create the request
53-
AnnotateVideoRequest request = AnnotateVideoRequest.newBuilder()
54-
.setInputContent(ByteString.copyFrom(data))
55-
.addFeatures(Feature.OBJECT_TRACKING)
56-
.setLocationId("us-east1")
57-
.build();
53+
AnnotateVideoRequest request =
54+
AnnotateVideoRequest.newBuilder()
55+
.setInputContent(ByteString.copyFrom(data))
56+
.addFeatures(Feature.OBJECT_TRACKING)
57+
.setLocationId("us-east1")
58+
.build();
5859

5960
// asynchronously perform object tracking on videos
6061
OperationFuture<AnnotateVideoResponse, AnnotateVideoProgress> future =
@@ -80,19 +81,21 @@ public static VideoAnnotationResults trackObjects(String filePath) throws Except
8081
Duration startTimeOffset = videoSegment.getStartTimeOffset();
8182
Duration endTimeOffset = videoSegment.getEndTimeOffset();
8283
// Display the segment time in seconds, 1e9 converts nanos to seconds
83-
System.out.println(String.format(
84-
"Segment: %.2fs to %.2fs",
85-
startTimeOffset.getSeconds() + startTimeOffset.getNanos() / 1e9,
86-
endTimeOffset.getSeconds() + endTimeOffset.getNanos() / 1e9));
84+
System.out.println(
85+
String.format(
86+
"Segment: %.2fs to %.2fs",
87+
startTimeOffset.getSeconds() + startTimeOffset.getNanos() / 1e9,
88+
endTimeOffset.getSeconds() + endTimeOffset.getNanos() / 1e9));
8789
}
8890

8991
// Here we print only the bounding box of the first frame in this segment.
9092
ObjectTrackingFrame frame = annotation.getFrames(0);
9193
// Display the offset time in seconds, 1e9 converts nanos to seconds
9294
Duration timeOffset = frame.getTimeOffset();
93-
System.out.println(String.format(
94-
"Time offset of the first frame: %.2fs",
95-
timeOffset.getSeconds() + timeOffset.getNanos() / 1e9));
95+
System.out.println(
96+
String.format(
97+
"Time offset of the first frame: %.2fs",
98+
timeOffset.getSeconds() + timeOffset.getNanos() / 1e9));
9699

97100
// Display the bounding box of the detected object
98101
NormalizedBoundingBox normalizedBoundingBox = frame.getNormalizedBoundingBox();
@@ -115,11 +118,12 @@ public static VideoAnnotationResults trackObjects(String filePath) throws Except
115118
public static VideoAnnotationResults trackObjectsGcs(String gcsUri) throws Exception {
116119
try (VideoIntelligenceServiceClient client = VideoIntelligenceServiceClient.create()) {
117120
// Create the request
118-
AnnotateVideoRequest request = AnnotateVideoRequest.newBuilder()
119-
.setInputUri(gcsUri)
120-
.addFeatures(Feature.OBJECT_TRACKING)
121-
.setLocationId("us-east1")
122-
.build();
121+
AnnotateVideoRequest request =
122+
AnnotateVideoRequest.newBuilder()
123+
.setInputUri(gcsUri)
124+
.addFeatures(Feature.OBJECT_TRACKING)
125+
.setLocationId("us-east1")
126+
.build();
123127

124128
// asynchronously perform object tracking on videos
125129
OperationFuture<AnnotateVideoResponse, AnnotateVideoProgress> future =
@@ -145,19 +149,21 @@ public static VideoAnnotationResults trackObjectsGcs(String gcsUri) throws Excep
145149
Duration startTimeOffset = videoSegment.getStartTimeOffset();
146150
Duration endTimeOffset = videoSegment.getEndTimeOffset();
147151
// Display the segment time in seconds, 1e9 converts nanos to seconds
148-
System.out.println(String.format(
149-
"Segment: %.2fs to %.2fs",
150-
startTimeOffset.getSeconds() + startTimeOffset.getNanos() / 1e9,
151-
endTimeOffset.getSeconds() + endTimeOffset.getNanos() / 1e9));
152+
System.out.println(
153+
String.format(
154+
"Segment: %.2fs to %.2fs",
155+
startTimeOffset.getSeconds() + startTimeOffset.getNanos() / 1e9,
156+
endTimeOffset.getSeconds() + endTimeOffset.getNanos() / 1e9));
152157
}
153158

154159
// Here we print only the bounding box of the first frame in this segment.
155160
ObjectTrackingFrame frame = annotation.getFrames(0);
156161
// Display the offset time in seconds, 1e9 converts nanos to seconds
157162
Duration timeOffset = frame.getTimeOffset();
158-
System.out.println(String.format(
159-
"Time offset of the first frame: %.2fs",
160-
timeOffset.getSeconds() + timeOffset.getNanos() / 1e9));
163+
System.out.println(
164+
String.format(
165+
"Time offset of the first frame: %.2fs",
166+
timeOffset.getSeconds() + timeOffset.getNanos() / 1e9));
161167

162168
// Display the bounding box of the detected object
163169
NormalizedBoundingBox normalizedBoundingBox = frame.getNormalizedBoundingBox();

video/src/test/java/beta/video/StreamingAutoMlObjectTrackingIT.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121
import io.grpc.Status;
2222
import io.grpc.StatusRuntimeException;
2323
import java.io.ByteArrayOutputStream;
24-
import java.io.IOException;
2524
import java.io.PrintStream;
2625
import org.junit.After;
2726
import org.junit.Before;
@@ -78,4 +77,4 @@ public void testStreamingAutoMlObjectTracking() {
7877
}
7978
}
8079
}
81-
}
80+
}

video/src/test/java/beta/video/StreamingShotChangeDetectionIT.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,7 @@
2929
import org.junit.runner.RunWith;
3030
import org.junit.runners.JUnit4;
3131

32-
/**
33-
* Integration (system) tests for {@link StreamingShotChangeDetection}.
34-
*/
32+
/** Integration (system) tests for {@link StreamingShotChangeDetection}. */
3533
@RunWith(JUnit4.class)
3634
@SuppressWarnings("checkstyle:abbreviationaswordinname")
3735
public class StreamingShotChangeDetectionIT {

video/src/test/java/com/example/video/DetectIT.java

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818

1919
import static com.google.common.truth.Truth.assertThat;
2020

21-
import com.google.cloud.videointelligence.v1.ObjectTrackingAnnotation;
2221
import com.google.cloud.videointelligence.v1.TextAnnotation;
2322
import com.google.cloud.videointelligence.v1.VideoAnnotationResults;
2423
import java.io.ByteArrayOutputStream;
@@ -31,9 +30,7 @@
3130
import org.junit.runner.RunWith;
3231
import org.junit.runners.JUnit4;
3332

34-
/**
35-
* Tests for video analysis sample.
36-
*/
33+
/** Tests for video analysis sample. */
3734
@RunWith(JUnit4.class)
3835
@SuppressWarnings("checkstyle:abbreviationaswordinname")
3936
public class DetectIT {
@@ -42,10 +39,21 @@ public class DetectIT {
4239
static final String SHOTS_FILE_LOCATION = "gs://cloud-samples-data/video/gbikes_dinosaur.mp4";
4340
static final String EXPLICIT_CONTENT_LOCATION = "gs://cloud-samples-data/video/cat.mp4";
4441
static final String SPEECH_GCS_LOCATION =
45-
"gs://java-docs-samples-testing/video/googlework_short.mp4";
46-
private static final List<String> POSSIBLE_TEXTS = Arrays.asList(
47-
"Google", "SUR", "SUR", "ROTO", "Vice President", "58oo9", "LONDRES", "OMAR", "PARIS",
48-
"METRO", "RUE", "CARLO");
42+
"gs://java-docs-samples-testing/video/googlework_short.mp4";
43+
private static final List<String> POSSIBLE_TEXTS =
44+
Arrays.asList(
45+
"Google",
46+
"SUR",
47+
"SUR",
48+
"ROTO",
49+
"Vice President",
50+
"58oo9",
51+
"LONDRES",
52+
"OMAR",
53+
"PARIS",
54+
"METRO",
55+
"RUE",
56+
"CARLO");
4957
private ByteArrayOutputStream bout;
5058
private PrintStream out;
5159

video/src/test/java/video/DetectFacesGcsIT.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@
2323
import org.junit.After;
2424
import org.junit.Before;
2525
import org.junit.Test;
26-
import video.DetectFacesGcs;
2726

2827
@SuppressWarnings("checkstyle:AbbreviationAsWordInName")
2928
public class DetectFacesGcsIT {

video/src/test/java/video/DetectFacesIT.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@
2323
import org.junit.After;
2424
import org.junit.Before;
2525
import org.junit.Test;
26-
import video.DetectFaces;
2726

2827
@SuppressWarnings("checkstyle:AbbreviationAsWordInName")
2928
public class DetectFacesIT {

video/src/test/java/video/DetectTextTest.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,7 @@ public class DetectTextTest {
4747
"METRO",
4848
"RUE",
4949
"CARLO");
50-
@Rule
51-
public MultipleAttemptsRule multipleAttemptsRule = new MultipleAttemptsRule(3);
50+
@Rule public MultipleAttemptsRule multipleAttemptsRule = new MultipleAttemptsRule(3);
5251
private ByteArrayOutputStream bout;
5352
private PrintStream out;
5453
private PrintStream originalPrintStream;

0 commit comments

Comments
 (0)