1414 * limitations under the License.
1515 */
1616
17- package com . example . video ;
17+ package video ;
1818
1919import com .google .api .gax .longrunning .OperationFuture ;
2020import com .google .cloud .videointelligence .v1 .AnnotateVideoProgress ;
@@ -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- " \t Vertex.x: %.2f, Vertex.y: %.2f" ,
97- normalizedVertex . getX () ,
98- normalizedVertex .getY ()));
100+ System .out .println (
101+ String . format (
102+ " \t Vertex.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- " \t Vertex.x: %.2f, Vertex.y: %.2f" ,
157- normalizedVertex . getX () ,
158- normalizedVertex .getY ()));
165+ System .out .println (
166+ String . format (
167+ " \t Vertex.x: %.2f, Vertex.y: %.2f" ,
168+ normalizedVertex . getX (), normalizedVertex .getY ()));
159169 }
160170 return results ;
161171 }
0 commit comments