Correct the timestamp in the vision tasks result objects.
PiperOrigin-RevId: 487597999
This commit is contained in:
parent
d5552c4bd9
commit
bb5782ee2f
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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());
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue
Block a user