Skip to content

Commit 6539664

Browse files
gguussjabubake
authored andcommitted
Change request type on certain inspection type (#857)
1 parent 476f33e commit 6539664

File tree

1 file changed

+21
-22
lines changed
  • video/cloud-client/src/main/java/com/example/video

1 file changed

+21
-22
lines changed

video/cloud-client/src/main/java/com/example/video/Detect.java

+21-22
Original file line numberDiff line numberDiff line change
@@ -107,19 +107,9 @@ public static void analyzeFaces(String gcsUri) throws Exception {
107107
// [START detect_faces]
108108
// Instantiate a com.google.cloud.videointelligence.v1beta2.VideoIntelligenceServiceClient
109109
try (VideoIntelligenceServiceClient client = VideoIntelligenceServiceClient.create()) {
110-
// detect shot and frame
111-
LabelDetectionConfig labelDetectionConfig = LabelDetectionConfig.newBuilder()
112-
.setLabelDetectionMode(LabelDetectionMode.SHOT_AND_FRAME_MODE)
113-
.build();
114-
115-
VideoContext videoContext = VideoContext.newBuilder()
116-
.setLabelDetectionConfig(labelDetectionConfig)
117-
.build();
118-
119110
AnnotateVideoRequest request = AnnotateVideoRequest.newBuilder()
120111
.setInputUri(gcsUri)
121-
.setVideoContext(videoContext)
122-
.addFeatures(Feature.LABEL_DETECTION)
112+
.addFeatures(Feature.FACE_DETECTION)
123113
.build();
124114

125115
// asynchronously perform facial analysis on videos
@@ -140,17 +130,26 @@ public static void analyzeFaces(String gcsUri) throws Exception {
140130
+ segment.getSegment().getEndTimeOffset().getNanos() / 1e9;
141131
System.out.printf("Segment location : %.3f:%.3f\n", startTime, endTime);
142132
}
143-
// printing info on the first frame
144-
FaceFrame frame = faceAnnotation.getFrames(0);
145-
double timeOffset = frame.getTimeOffset().getSeconds()
146-
+ frame.getTimeOffset().getNanos() / 1e9;
147-
System.out.printf("First frame time offset: %.3fs", timeOffset);
148-
// print info on the first normalized bounding box
149-
NormalizedBoundingBox box = frame.getNormalizedBoundingBoxesList().get(0);
150-
System.out.printf("Left: %.3f\n", box.getLeft());
151-
System.out.printf("Top: %.3f\n", box.getTop());
152-
System.out.printf("Bottom: %.3f\n", box.getBottom());
153-
System.out.printf("Right: %.3f\n", box.getRight());
133+
try {
134+
// printing info on the first frame
135+
if (faceAnnotation.getFramesCount() > 0) {
136+
System.out.println(faceAnnotation.getFramesList().get(0));
137+
FaceFrame frame = faceAnnotation.getFrames(0);
138+
double timeOffset = frame.getTimeOffset().getSeconds()
139+
+ frame.getTimeOffset().getNanos() / 1e9;
140+
System.out.printf("First frame time offset: %.3fs", timeOffset);
141+
// print info on the first normalized bounding box
142+
NormalizedBoundingBox box = frame.getNormalizedBoundingBoxesList().get(0);
143+
System.out.printf("Left: %.3f\n", box.getLeft());
144+
System.out.printf("Top: %.3f\n", box.getTop());
145+
System.out.printf("Bottom: %.3f\n", box.getBottom());
146+
System.out.printf("Right: %.3f\n", box.getRight());
147+
} else {
148+
System.out.println("No frames found in annotation");
149+
}
150+
} catch (IndexOutOfBoundsException ioe) {
151+
System.out.println("Could not retrieve frame: " + ioe.getMessage());
152+
}
154153
}
155154
}
156155
if (!faceFound) {

0 commit comments

Comments
 (0)