Correct the timestamp in the vision tasks result objects.

PiperOrigin-RevId: 487597999
This commit is contained in:
Jiuqiang Tang 2022-11-10 11:44:51 -08:00 committed by Copybara-Service
parent d5552c4bd9
commit bb5782ee2f
5 changed files with 22 additions and 4 deletions

View File

@ -160,4 +160,18 @@ public class BaseVisionTaskApi implements AutoCloseable {
.setRotation(-(float) Math.PI * imageProcessingOptions.rotationDegrees() / 180.0f)
.build();
}
/**
* Generates the timestamp of a vision task result object from the vision task running mode and
* the output packet.
*
* @param runningMode MediaPipe Vision Tasks {@link RunningMode}.
* @param packet the output {@link Packet}.
*/
public static long generateResultTimestampMs(RunningMode runningMode, Packet packet) {
if (runningMode == RunningMode.IMAGE) {
return -1;
}
return packet.getTimestamp() / MICROSECONDS_PER_MILLISECOND;
}
}

View File

@ -175,7 +175,8 @@ public final class GestureRecognizer extends BaseVisionTaskApi {
packets.get(HANDEDNESS_OUT_STREAM_INDEX), ClassificationList.parser()),
PacketGetter.getProtoVector(
packets.get(HAND_GESTURES_OUT_STREAM_INDEX), ClassificationList.parser()),
packets.get(HAND_GESTURES_OUT_STREAM_INDEX).getTimestamp());
BaseVisionTaskApi.generateResultTimestampMs(
recognizerOptions.runningMode(), packets.get(HAND_GESTURES_OUT_STREAM_INDEX)));
}
@Override

View File

@ -165,7 +165,8 @@ public final class HandLandmarker extends BaseVisionTaskApi {
packets.get(WORLD_LANDMARKS_OUT_STREAM_INDEX), LandmarkList.parser()),
PacketGetter.getProtoVector(
packets.get(HANDEDNESS_OUT_STREAM_INDEX), ClassificationList.parser()),
packets.get(LANDMARKS_OUT_STREAM_INDEX).getTimestamp());
BaseVisionTaskApi.generateResultTimestampMs(
landmarkerOptions.runningMode(), packets.get(LANDMARKS_OUT_STREAM_INDEX)));
}
@Override

View File

@ -176,7 +176,8 @@ public final class ImageClassifier extends BaseVisionTaskApi {
PacketGetter.getProto(
packets.get(CLASSIFICATIONS_OUT_STREAM_INDEX),
ClassificationsProto.ClassificationResult.getDefaultInstance())),
packets.get(CLASSIFICATIONS_OUT_STREAM_INDEX).getTimestamp());
BaseVisionTaskApi.generateResultTimestampMs(
options.runningMode(), packets.get(CLASSIFICATIONS_OUT_STREAM_INDEX)));
} catch (IOException e) {
throw new MediaPipeException(
MediaPipeException.StatusCode.INTERNAL.ordinal(), e.getMessage());

View File

@ -173,7 +173,8 @@ public final class ObjectDetector extends BaseVisionTaskApi {
return ObjectDetectionResult.create(
PacketGetter.getProtoVector(
packets.get(DETECTIONS_OUT_STREAM_INDEX), Detection.parser()),
packets.get(DETECTIONS_OUT_STREAM_INDEX).getTimestamp());
BaseVisionTaskApi.generateResultTimestampMs(
detectorOptions.runningMode(), packets.get(DETECTIONS_OUT_STREAM_INDEX)));
}
@Override