diff --git a/mediapipe/tasks/java/com/google/mediapipe/tasks/components/containers/BUILD b/mediapipe/tasks/java/com/google/mediapipe/tasks/components/containers/BUILD index 2c76f9a0b..07106985d 100644 --- a/mediapipe/tasks/java/com/google/mediapipe/tasks/components/containers/BUILD +++ b/mediapipe/tasks/java/com/google/mediapipe/tasks/components/containers/BUILD @@ -80,6 +80,15 @@ android_library( ], ) +android_library( + name = "connection", + srcs = ["Connection.java"], + deps = [ + "//third_party:autovalue", + "@maven//:com_google_guava_guava", + ], +) + android_library( name = "landmark", srcs = ["Landmark.java"], diff --git a/mediapipe/tasks/java/com/google/mediapipe/tasks/components/containers/Connection.java b/mediapipe/tasks/java/com/google/mediapipe/tasks/components/containers/Connection.java new file mode 100644 index 000000000..99103c201 --- /dev/null +++ b/mediapipe/tasks/java/com/google/mediapipe/tasks/components/containers/Connection.java @@ -0,0 +1,29 @@ +// Copyright 2023 The MediaPipe Authors. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +package com.google.mediapipe.tasks.components.containers; + +import com.google.auto.value.AutoValue; + +/** Value class representing a landmark connection. */ +@AutoValue +public abstract class Connection { + public static Connection create(int start, int end) { + return new AutoValue_Connection(start, end); + } + + public abstract int start(); + + public abstract int end(); +} diff --git a/mediapipe/tasks/java/com/google/mediapipe/tasks/vision/BUILD b/mediapipe/tasks/java/com/google/mediapipe/tasks/vision/BUILD index a2dbe351a..399156da3 100644 --- a/mediapipe/tasks/java/com/google/mediapipe/tasks/vision/BUILD +++ b/mediapipe/tasks/java/com/google/mediapipe/tasks/vision/BUILD @@ -198,6 +198,7 @@ android_library( "//mediapipe/tasks/cc/vision/pose_detector/proto:pose_detector_graph_options_java_proto_lite", "//mediapipe/tasks/cc/vision/pose_landmarker/proto:pose_landmarker_graph_options_java_proto_lite", "//mediapipe/tasks/cc/vision/pose_landmarker/proto:pose_landmarks_detector_graph_options_java_proto_lite", + "//mediapipe/tasks/java/com/google/mediapipe/tasks/components/containers:connection", "//mediapipe/tasks/java/com/google/mediapipe/tasks/components/containers:landmark", "//mediapipe/tasks/java/com/google/mediapipe/tasks/components/containers:normalized_landmark", "//mediapipe/tasks/java/com/google/mediapipe/tasks/core", @@ -232,6 +233,7 @@ android_library( "//mediapipe/tasks/cc/vision/hand_landmarker/proto:hand_landmarker_graph_options_java_proto_lite", "//mediapipe/tasks/cc/vision/hand_landmarker/proto:hand_landmarks_detector_graph_options_java_proto_lite", "//mediapipe/tasks/java/com/google/mediapipe/tasks/components/containers:category", + "//mediapipe/tasks/java/com/google/mediapipe/tasks/components/containers:connection", "//mediapipe/tasks/java/com/google/mediapipe/tasks/components/containers:landmark", "//mediapipe/tasks/java/com/google/mediapipe/tasks/components/containers:normalized_landmark", "//mediapipe/tasks/java/com/google/mediapipe/tasks/core", @@ -373,6 +375,7 @@ android_library( "//mediapipe/tasks/cc/vision/face_landmarker/proto:face_landmarker_graph_options_java_proto_lite", "//mediapipe/tasks/cc/vision/face_landmarker/proto:face_landmarks_detector_graph_options_java_proto_lite", "//mediapipe/tasks/java/com/google/mediapipe/tasks/components/containers:category", + "//mediapipe/tasks/java/com/google/mediapipe/tasks/components/containers:connection", "//mediapipe/tasks/java/com/google/mediapipe/tasks/components/containers:normalized_landmark", "//mediapipe/tasks/java/com/google/mediapipe/tasks/core", "//third_party:autovalue", diff --git a/mediapipe/tasks/java/com/google/mediapipe/tasks/vision/facelandmarker/FaceLandmarker.java b/mediapipe/tasks/java/com/google/mediapipe/tasks/vision/facelandmarker/FaceLandmarker.java index 6a10f52ed..f7792a1be 100644 --- a/mediapipe/tasks/java/com/google/mediapipe/tasks/vision/facelandmarker/FaceLandmarker.java +++ b/mediapipe/tasks/java/com/google/mediapipe/tasks/vision/facelandmarker/FaceLandmarker.java @@ -25,6 +25,7 @@ import com.google.mediapipe.framework.Packet; import com.google.mediapipe.framework.PacketGetter; import com.google.mediapipe.framework.image.BitmapImageBuilder; import com.google.mediapipe.framework.image.MPImage; +import com.google.mediapipe.tasks.components.containers.Connection; import com.google.mediapipe.tasks.core.BaseOptions; import com.google.mediapipe.tasks.core.ErrorListener; import com.google.mediapipe.tasks.core.OutputHandler; @@ -49,6 +50,7 @@ import java.util.Arrays; import java.util.Collections; import java.util.List; import java.util.Optional; +import java.util.Set; /** * Performs face landmarks detection on images. @@ -223,6 +225,46 @@ public final class FaceLandmarker extends BaseVisionTaskApi { return new FaceLandmarker(runner, landmarkerOptions.runningMode()); } + @SuppressWarnings("ConstantCaseForConstants") + public static final Set FACE_LANDMARKS_LIPS = + FaceLandmarksConnections.FACE_LANDMARKS_LIPS; + + @SuppressWarnings("ConstantCaseForConstants") + public static final Set FACE_LANDMARKS_LEFT_EYE = + FaceLandmarksConnections.FACE_LANDMARKS_LEFT_EYE; + + @SuppressWarnings("ConstantCaseForConstants") + public static final Set FACE_LANDMARKS_LEFT_EYE_BROW = + FaceLandmarksConnections.FACE_LANDMARKS_LEFT_EYE_BROW; + + @SuppressWarnings("ConstantCaseForConstants") + public static final Set FACE_LANDMARKS_LEFT_IRIS = + FaceLandmarksConnections.FACE_LANDMARKS_LEFT_IRIS; + + @SuppressWarnings("ConstantCaseForConstants") + public static final Set FACE_LANDMARKS_RIGHT_EYE = + FaceLandmarksConnections.FACE_LANDMARKS_RIGHT_EYE; + + @SuppressWarnings("ConstantCaseForConstants") + public static final Set FACE_LANDMARKS_RIGHT_EYE_BROW = + FaceLandmarksConnections.FACE_LANDMARKS_RIGHT_EYE_BROW; + + @SuppressWarnings("ConstantCaseForConstants") + public static final Set FACE_LANDMARKS_RIGHT_IRIS = + FaceLandmarksConnections.FACE_LANDMARKS_RIGHT_IRIS; + + @SuppressWarnings("ConstantCaseForConstants") + public static final Set FACE_LANDMARKS_FACE_OVAL = + FaceLandmarksConnections.FACE_LANDMARKS_FACE_OVAL; + + @SuppressWarnings("ConstantCaseForConstants") + public static final Set FACE_LANDMARKS_CONNECTORS = + FaceLandmarksConnections.FACE_LANDMARKS_CONNECTORS; + + @SuppressWarnings("ConstantCaseForConstants") + public static final Set FACE_LANDMARKS_TESSELATION = + FaceLandmarksConnections.FACE_LANDMARKS_TESSELATION; + /** * Constructor to initialize an {@link FaceLandmarker} from a {@link TaskRunner} and a {@link * RunningMode}. diff --git a/mediapipe/tasks/java/com/google/mediapipe/tasks/vision/facelandmarker/FaceLandmarksConnections.java b/mediapipe/tasks/java/com/google/mediapipe/tasks/vision/facelandmarker/FaceLandmarksConnections.java index ad996f369..63b142ced 100644 --- a/mediapipe/tasks/java/com/google/mediapipe/tasks/vision/facelandmarker/FaceLandmarksConnections.java +++ b/mediapipe/tasks/java/com/google/mediapipe/tasks/vision/facelandmarker/FaceLandmarksConnections.java @@ -14,7 +14,7 @@ package com.google.mediapipe.tasks.vision.facelandmarker; -import com.google.auto.value.AutoValue; +import com.google.mediapipe.tasks.components.containers.Connection; import java.util.Arrays; import java.util.Collections; import java.util.HashSet; @@ -23,22 +23,10 @@ import java.util.stream.Collectors; import java.util.stream.Stream; /** Face landmarks connection constants. */ -public final class FaceLandmarksConnections { - - /** Value class representing face landmarks connection. */ - @AutoValue - public abstract static class Connection { - static Connection create(int start, int end) { - return new AutoValue_FaceLandmarksConnections_Connection(start, end); - } - - public abstract int start(); - - public abstract int end(); - } +final class FaceLandmarksConnections { @SuppressWarnings("ConstantCaseForConstants") - public static final Set FACE_LANDMARKS_LIPS = + static final Set FACE_LANDMARKS_LIPS = Collections.unmodifiableSet( new HashSet<>( Arrays.asList( @@ -84,7 +72,7 @@ public final class FaceLandmarksConnections { Connection.create(415, 308)))); @SuppressWarnings("ConstantCaseForConstants") - public static final Set FACE_LANDMARKS_LEFT_EYE = + static final Set FACE_LANDMARKS_LEFT_EYE = Collections.unmodifiableSet( new HashSet<>( Arrays.asList( @@ -106,7 +94,7 @@ public final class FaceLandmarksConnections { Connection.create(398, 362)))); @SuppressWarnings("ConstantCaseForConstants") - public static final Set FACE_LANDMARKS_LEFT_EYE_BROW = + static final Set FACE_LANDMARKS_LEFT_EYE_BROW = Collections.unmodifiableSet( new HashSet<>( Arrays.asList( @@ -120,7 +108,7 @@ public final class FaceLandmarksConnections { Connection.create(296, 336)))); @SuppressWarnings("ConstantCaseForConstants") - public static final Set FACE_LANDMARKS_LEFT_IRIS = + static final Set FACE_LANDMARKS_LEFT_IRIS = Collections.unmodifiableSet( new HashSet<>( Arrays.asList( @@ -130,7 +118,7 @@ public final class FaceLandmarksConnections { Connection.create(477, 474)))); @SuppressWarnings("ConstantCaseForConstants") - public static final Set FACE_LANDMARKS_RIGHT_EYE = + static final Set FACE_LANDMARKS_RIGHT_EYE = Collections.unmodifiableSet( new HashSet<>( Arrays.asList( @@ -152,7 +140,7 @@ public final class FaceLandmarksConnections { Connection.create(173, 133)))); @SuppressWarnings("ConstantCaseForConstants") - public static final Set FACE_LANDMARKS_RIGHT_EYE_BROW = + static final Set FACE_LANDMARKS_RIGHT_EYE_BROW = Collections.unmodifiableSet( new HashSet<>( Arrays.asList( @@ -166,7 +154,7 @@ public final class FaceLandmarksConnections { Connection.create(66, 107)))); @SuppressWarnings("ConstantCaseForConstants") - public static final Set FACE_LANDMARKS_RIGHT_IRIS = + static final Set FACE_LANDMARKS_RIGHT_IRIS = Collections.unmodifiableSet( new HashSet<>( Arrays.asList( @@ -176,7 +164,7 @@ public final class FaceLandmarksConnections { Connection.create(472, 469)))); @SuppressWarnings("ConstantCaseForConstants") - public static final Set FACE_LANDMARKS_FACE_OVAL = + static final Set FACE_LANDMARKS_FACE_OVAL = Collections.unmodifiableSet( new HashSet<>( Arrays.asList( @@ -218,7 +206,7 @@ public final class FaceLandmarksConnections { Connection.create(109, 10)))); @SuppressWarnings("ConstantCaseForConstants") - public static final Set FACE_LANDMARKS_CONNECTORS = + static final Set FACE_LANDMARKS_CONNECTORS = Collections.unmodifiableSet( Stream.of( FACE_LANDMARKS_LIPS.stream(), @@ -231,7 +219,7 @@ public final class FaceLandmarksConnections { .collect(Collectors.toSet())); @SuppressWarnings("ConstantCaseForConstants") - public static final Set FACE_LANDMARKS_TESSELATION = + static final Set FACE_LANDMARKS_TESSELATION = Collections.unmodifiableSet( new HashSet<>( Arrays.asList( diff --git a/mediapipe/tasks/java/com/google/mediapipe/tasks/vision/handlandmarker/HandLandmarker.java b/mediapipe/tasks/java/com/google/mediapipe/tasks/vision/handlandmarker/HandLandmarker.java index 2af893128..8b02b15ad 100644 --- a/mediapipe/tasks/java/com/google/mediapipe/tasks/vision/handlandmarker/HandLandmarker.java +++ b/mediapipe/tasks/java/com/google/mediapipe/tasks/vision/handlandmarker/HandLandmarker.java @@ -26,6 +26,7 @@ import com.google.mediapipe.framework.Packet; import com.google.mediapipe.framework.PacketGetter; import com.google.mediapipe.framework.image.BitmapImageBuilder; import com.google.mediapipe.framework.image.MPImage; +import com.google.mediapipe.tasks.components.containers.Connection; import com.google.mediapipe.tasks.core.BaseOptions; import com.google.mediapipe.tasks.core.ErrorListener; import com.google.mediapipe.tasks.core.OutputHandler; @@ -48,6 +49,7 @@ import java.util.Arrays; import java.util.Collections; import java.util.List; import java.util.Optional; +import java.util.Set; /** * Performs hand landmarks detection on images. @@ -195,6 +197,33 @@ public final class HandLandmarker extends BaseVisionTaskApi { return new HandLandmarker(runner, landmarkerOptions.runningMode()); } + @SuppressWarnings("ConstantCaseForConstants") + public static final Set HAND_PALM_CONNECTIONS = + HandLandmarksConnections.HAND_PALM_CONNECTIONS; + + @SuppressWarnings("ConstantCaseForConstants") + public static final Set HAND_THUMB_CONNECTIONS = + HandLandmarksConnections.HAND_THUMB_CONNECTIONS; + + @SuppressWarnings("ConstantCaseForConstants") + public static final Set HAND_INDEX_FINGER_CONNECTIONS = + HandLandmarksConnections.HAND_INDEX_FINGER_CONNECTIONS; + + @SuppressWarnings("ConstantCaseForConstants") + public static final Set HAND_MIDDLE_FINGER_CONNECTIONS = + HandLandmarksConnections.HAND_MIDDLE_FINGER_CONNECTIONS; + + @SuppressWarnings("ConstantCaseForConstants") + public static final Set HAND_RING_FINGER_CONNECTIONS = + HandLandmarksConnections.HAND_RING_FINGER_CONNECTIONS; + + @SuppressWarnings("ConstantCaseForConstants") + public static final Set HAND_PINKY_FINGER_CONNECTIONS = + HandLandmarksConnections.HAND_PINKY_FINGER_CONNECTIONS; + + @SuppressWarnings("ConstantCaseForConstants") + public static final Set HAND_CONNECTIONS = HandLandmarksConnections.HAND_CONNECTIONS; + /** * Constructor to initialize an {@link HandLandmarker} from a {@link TaskRunner} and a {@link * RunningMode}. diff --git a/mediapipe/tasks/java/com/google/mediapipe/tasks/vision/handlandmarker/HandLandmarksConnections.java b/mediapipe/tasks/java/com/google/mediapipe/tasks/vision/handlandmarker/HandLandmarksConnections.java index c60923840..81b922557 100644 --- a/mediapipe/tasks/java/com/google/mediapipe/tasks/vision/handlandmarker/HandLandmarksConnections.java +++ b/mediapipe/tasks/java/com/google/mediapipe/tasks/vision/handlandmarker/HandLandmarksConnections.java @@ -14,7 +14,7 @@ package com.google.mediapipe.tasks.vision.handlandmarker; -import com.google.auto.value.AutoValue; +import com.google.mediapipe.tasks.components.containers.Connection; import java.util.Arrays; import java.util.Collections; import java.util.HashSet; @@ -23,22 +23,10 @@ import java.util.stream.Collectors; import java.util.stream.Stream; /** Hand landmarks connection constants. */ -public final class HandLandmarksConnections { - - /** Value class representing hand landmarks connection. */ - @AutoValue - public abstract static class Connection { - static Connection create(int start, int end) { - return new AutoValue_HandLandmarksConnections_Connection(start, end); - } - - public abstract int start(); - - public abstract int end(); - } +final class HandLandmarksConnections { @SuppressWarnings("ConstantCaseForConstants") - public static final Set HAND_PALM_CONNECTIONS = + static final Set HAND_PALM_CONNECTIONS = Collections.unmodifiableSet( new HashSet<>( Arrays.asList( @@ -50,28 +38,28 @@ public final class HandLandmarksConnections { Connection.create(0, 17)))); @SuppressWarnings("ConstantCaseForConstants") - public static final Set HAND_THUMB_CONNECTIONS = + static final Set HAND_THUMB_CONNECTIONS = Collections.unmodifiableSet( new HashSet<>( Arrays.asList( Connection.create(1, 2), Connection.create(2, 3), Connection.create(3, 4)))); @SuppressWarnings("ConstantCaseForConstants") - public static final Set HAND_INDEX_FINGER_CONNECTIONS = + static final Set HAND_INDEX_FINGER_CONNECTIONS = Collections.unmodifiableSet( new HashSet<>( Arrays.asList( Connection.create(5, 6), Connection.create(6, 7), Connection.create(7, 8)))); @SuppressWarnings("ConstantCaseForConstants") - public static final Set HAND_MIDDLE_FINGER_CONNECTIONS = + static final Set HAND_MIDDLE_FINGER_CONNECTIONS = Collections.unmodifiableSet( new HashSet<>( Arrays.asList( Connection.create(9, 10), Connection.create(10, 11), Connection.create(11, 12)))); @SuppressWarnings("ConstantCaseForConstants") - public static final Set HAND_RING_FINGER_CONNECTIONS = + static final Set HAND_RING_FINGER_CONNECTIONS = Collections.unmodifiableSet( new HashSet<>( Arrays.asList( @@ -80,7 +68,7 @@ public final class HandLandmarksConnections { Connection.create(15, 16)))); @SuppressWarnings("ConstantCaseForConstants") - public static final Set HAND_PINKY_FINGER_CONNECTIONS = + static final Set HAND_PINKY_FINGER_CONNECTIONS = Collections.unmodifiableSet( new HashSet<>( Arrays.asList( @@ -89,7 +77,7 @@ public final class HandLandmarksConnections { Connection.create(19, 20)))); @SuppressWarnings("ConstantCaseForConstants") - public static final Set HAND_CONNECTIONS = + static final Set HAND_CONNECTIONS = Collections.unmodifiableSet( Stream.of( HAND_PALM_CONNECTIONS.stream(), diff --git a/mediapipe/tasks/java/com/google/mediapipe/tasks/vision/poselandmarker/PoseLandmarker.java b/mediapipe/tasks/java/com/google/mediapipe/tasks/vision/poselandmarker/PoseLandmarker.java index fa2d3da17..d59448dac 100644 --- a/mediapipe/tasks/java/com/google/mediapipe/tasks/vision/poselandmarker/PoseLandmarker.java +++ b/mediapipe/tasks/java/com/google/mediapipe/tasks/vision/poselandmarker/PoseLandmarker.java @@ -27,6 +27,7 @@ import com.google.mediapipe.framework.PacketGetter; import com.google.mediapipe.framework.image.BitmapImageBuilder; import com.google.mediapipe.framework.image.ByteBufferImageBuilder; import com.google.mediapipe.framework.image.MPImage; +import com.google.mediapipe.tasks.components.containers.Connection; import com.google.mediapipe.tasks.core.BaseOptions; import com.google.mediapipe.tasks.core.ErrorListener; import com.google.mediapipe.tasks.core.OutputHandler; @@ -49,6 +50,7 @@ import java.util.Arrays; import java.util.Collections; import java.util.List; import java.util.Optional; +import java.util.Set; /** * Performs pose landmarks detection on images. @@ -206,6 +208,9 @@ public final class PoseLandmarker extends BaseVisionTaskApi { return new PoseLandmarker(runner, landmarkerOptions.runningMode()); } + @SuppressWarnings("ConstantCaseForConstants") + public static final Set POSE_LANDMARKS = PoseLandmarksConnections.POSE_LANDMARKS; + /** * Constructor to initialize a {@link PoseLandmarker} from a {@link TaskRunner} and a {@link * RunningMode}. diff --git a/mediapipe/tasks/java/com/google/mediapipe/tasks/vision/poselandmarker/PoseLandmarksConnections.java b/mediapipe/tasks/java/com/google/mediapipe/tasks/vision/poselandmarker/PoseLandmarksConnections.java index 9be6a9aeb..21d3a74b7 100644 --- a/mediapipe/tasks/java/com/google/mediapipe/tasks/vision/poselandmarker/PoseLandmarksConnections.java +++ b/mediapipe/tasks/java/com/google/mediapipe/tasks/vision/poselandmarker/PoseLandmarksConnections.java @@ -14,29 +14,17 @@ package com.google.mediapipe.tasks.vision.poselandmarker; -import com.google.auto.value.AutoValue; +import com.google.mediapipe.tasks.components.containers.Connection; import java.util.Arrays; import java.util.Collections; import java.util.HashSet; import java.util.Set; /** Pose landmarks connection constants. */ -public final class PoseLandmarksConnections { - - /** Value class representing pose landmarks connection. */ - @AutoValue - public abstract static class Connection { - static Connection create(int start, int end) { - return new AutoValue_PoseLandmarksConnections_Connection(start, end); - } - - public abstract int start(); - - public abstract int end(); - } +final class PoseLandmarksConnections { @SuppressWarnings("ConstantCaseForConstants") - public static final Set POSE_LANDMARKS = + static final Set POSE_LANDMARKS = Collections.unmodifiableSet( new HashSet<>( Arrays.asList(