14
14
* limitations under the License.
15
15
*/
16
16
17
- package com . example . video ;
17
+ package video ;
18
18
19
19
import com .google .api .gax .longrunning .OperationFuture ;
20
20
import com .google .cloud .videointelligence .v1 .AnnotateVideoProgress ;
@@ -51,10 +51,11 @@ public static VideoAnnotationResults detectText(String filePath) throws Exceptio
51
51
byte [] data = Files .readAllBytes (path );
52
52
53
53
// 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 ();
58
59
59
60
// asynchronously perform object tracking on videos
60
61
OperationFuture <AnnotateVideoResponse , AnnotateVideoProgress > future =
@@ -77,25 +78,29 @@ public static VideoAnnotationResults detectText(String filePath) throws Exceptio
77
78
Duration startTimeOffset = videoSegment .getStartTimeOffset ();
78
79
Duration endTimeOffset = videoSegment .getEndTimeOffset ();
79
80
// 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 ));
84
87
85
88
// Show the first result for the first frame in the segment.
86
89
TextFrame textFrame = textSegment .getFrames (0 );
87
90
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 ));
90
95
91
96
// Display the rotated bounding box for where the text is on the frame.
92
97
System .out .println ("Rotated Bounding Box Vertices:" );
93
98
List <NormalizedVertex > vertices = textFrame .getRotatedBoundingBox ().getVerticesList ();
94
99
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 ()));
99
104
}
100
105
return results ;
101
106
}
@@ -111,10 +116,11 @@ public static VideoAnnotationResults detectText(String filePath) throws Exceptio
111
116
public static VideoAnnotationResults detectTextGcs (String gcsUri ) throws Exception {
112
117
try (VideoIntelligenceServiceClient client = VideoIntelligenceServiceClient .create ()) {
113
118
// 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 ();
118
124
119
125
// asynchronously perform object tracking on videos
120
126
OperationFuture <AnnotateVideoResponse , AnnotateVideoProgress > future =
@@ -137,25 +143,29 @@ public static VideoAnnotationResults detectTextGcs(String gcsUri) throws Excepti
137
143
Duration startTimeOffset = videoSegment .getStartTimeOffset ();
138
144
Duration endTimeOffset = videoSegment .getEndTimeOffset ();
139
145
// 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 ));
144
152
145
153
// Show the first result for the first frame in the segment.
146
154
TextFrame textFrame = textSegment .getFrames (0 );
147
155
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 ));
150
160
151
161
// Display the rotated bounding box for where the text is on the frame.
152
162
System .out .println ("Rotated Bounding Box Vertices:" );
153
163
List <NormalizedVertex > vertices = textFrame .getRotatedBoundingBox ().getVerticesList ();
154
164
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 ()));
159
169
}
160
170
return results ;
161
171
}
0 commit comments