22
22
import com .google .cloud .videointelligence .v1 .AnnotateVideoResponse ;
23
23
import com .google .cloud .videointelligence .v1 .Entity ;
24
24
import com .google .cloud .videointelligence .v1 .ExplicitContentFrame ;
25
- import com .google .cloud .videointelligence .v1 .FaceAnnotation ;
26
- import com .google .cloud .videointelligence .v1 .FaceFrame ;
27
- import com .google .cloud .videointelligence .v1 .FaceSegment ;
28
25
import com .google .cloud .videointelligence .v1 .Feature ;
29
26
import com .google .cloud .videointelligence .v1 .LabelAnnotation ;
30
27
import com .google .cloud .videointelligence .v1 .LabelSegment ;
31
- import com .google .cloud .videointelligence .v1 .NormalizedBoundingBox ;
32
28
import com .google .cloud .videointelligence .v1 .VideoAnnotationResults ;
33
29
import com .google .cloud .videointelligence .v1 .VideoIntelligenceServiceClient ;
34
30
import com .google .cloud .videointelligence .v1 .VideoSegment ;
42
38
43
39
public class Detect {
44
40
/**
45
- * Detects entities,sentiment and syntax in a document using the Natural Language API.
41
+ * Detects labels, shots, and explicit content in a video using the Video Intelligence API
46
42
* @param args specifies features to detect and the path to the video on Google Cloud Storage.
47
- *
48
- * @throws IOException on Input/Output errors.
49
43
*/
50
- public static void main (String [] args ) throws Exception {
44
+ public static void main (String [] args ) {
51
45
try {
52
46
argsHelper (args );
53
47
} catch (Exception e ) {
@@ -68,7 +62,7 @@ public static void argsHelper(String[] args) throws Exception {
68
62
System .out .printf (
69
63
"\t java %s \" <command>\" \" <path-to-video>\" \n "
70
64
+ "Commands:\n "
71
- + "\t faces | labels | shots\n "
65
+ + "\t labels | shots\n "
72
66
+ "Path:\n \t A URI for a Cloud Storage resource (gs://...)\n "
73
67
+ "Examples: " ,
74
68
Detect .class .getCanonicalName ());
@@ -77,9 +71,6 @@ public static void argsHelper(String[] args) throws Exception {
77
71
String command = args [0 ];
78
72
String path = args .length > 1 ? args [1 ] : "" ;
79
73
80
- if (command .equals ("faces" )) {
81
- analyzeFaces (path );
82
- }
83
74
if (command .equals ("labels" )) {
84
75
analyzeLabels (path );
85
76
}
@@ -94,68 +85,6 @@ public static void argsHelper(String[] args) throws Exception {
94
85
}
95
86
}
96
87
97
- /**
98
- * Performs facial analysis on the video at the provided Cloud Storage path.
99
- *
100
- * @param gcsUri the path to the video file to analyze.
101
- */
102
- public static void analyzeFaces (String gcsUri ) throws Exception {
103
- // [START detect_faces]
104
- // Instantiate a com.google.cloud.videointelligence.v1.VideoIntelligenceServiceClient
105
- try (VideoIntelligenceServiceClient client = VideoIntelligenceServiceClient .create ()) {
106
- AnnotateVideoRequest request = AnnotateVideoRequest .newBuilder ()
107
- .setInputUri (gcsUri )
108
- .addFeatures (Feature .FACE_DETECTION )
109
- .build ();
110
-
111
- // asynchronously perform facial analysis on videos
112
- OperationFuture <AnnotateVideoResponse , AnnotateVideoProgress > response =
113
- client .annotateVideoAsync (request );
114
-
115
- System .out .println ("Waiting for operation to complete..." );
116
- boolean faceFound = false ;
117
- for (VideoAnnotationResults results : response .get ().getAnnotationResultsList ()) {
118
- int faceCount = 0 ;
119
- for (FaceAnnotation faceAnnotation : results .getFaceAnnotationsList ()) {
120
- faceFound = true ;
121
- System .out .println ("Face: " + ++faceCount );
122
- System .out .println ("Thumbnail size: " + faceAnnotation .getThumbnail ().size ());
123
- for (FaceSegment segment : faceAnnotation .getSegmentsList ()) {
124
- double startTime = segment .getSegment ().getStartTimeOffset ().getSeconds ()
125
- + segment .getSegment ().getStartTimeOffset ().getNanos () / 1e9 ;
126
- double endTime = segment .getSegment ().getEndTimeOffset ().getSeconds ()
127
- + segment .getSegment ().getEndTimeOffset ().getNanos () / 1e9 ;
128
- System .out .printf ("Segment location : %.3f:%.3f\n " , startTime , endTime );
129
- }
130
- try {
131
- // printing info on the first frame
132
- if (faceAnnotation .getFramesCount () > 0 ) {
133
- System .out .println (faceAnnotation .getFramesList ().get (0 ));
134
- FaceFrame frame = faceAnnotation .getFrames (0 );
135
- double timeOffset = frame .getTimeOffset ().getSeconds ()
136
- + frame .getTimeOffset ().getNanos () / 1e9 ;
137
- System .out .printf ("First frame time offset: %.3fs" , timeOffset );
138
- // print info on the first normalized bounding box
139
- NormalizedBoundingBox box = frame .getNormalizedBoundingBoxesList ().get (0 );
140
- System .out .printf ("Left: %.3f\n " , box .getLeft ());
141
- System .out .printf ("Top: %.3f\n " , box .getTop ());
142
- System .out .printf ("Bottom: %.3f\n " , box .getBottom ());
143
- System .out .printf ("Right: %.3f\n " , box .getRight ());
144
- } else {
145
- System .out .println ("No frames found in annotation" );
146
- }
147
- } catch (IndexOutOfBoundsException ioe ) {
148
- System .out .println ("Could not retrieve frame: " + ioe .getMessage ());
149
- }
150
- }
151
- }
152
- if (!faceFound ) {
153
- System .out .println ("No faces detected in " + gcsUri );
154
- }
155
- // [END detect_faces]
156
- }
157
- }
158
-
159
88
/**
160
89
* Performs label analysis on the video at the provided Cloud Storage path.
161
90
*
0 commit comments