Move loading tasks-vision-jni to individual vision task class

PiperOrigin-RevId: 564840343
This commit is contained in:
MediaPipe Team 2023-09-12 14:50:36 -07:00 committed by Copybara-Service
parent 4ba1dadf92
commit dbcdb44f7c
13 changed files with 39 additions and 1 deletions

View File

@ -34,7 +34,6 @@ public class BaseVisionTaskApi implements AutoCloseable {
protected final String normRectStreamName; protected final String normRectStreamName;
static { static {
System.loadLibrary("mediapipe_tasks_vision_jni");
ProtoUtil.registerTypeName(NormalizedRect.class, "mediapipe.NormalizedRect"); ProtoUtil.registerTypeName(NormalizedRect.class, "mediapipe.NormalizedRect");
} }

View File

@ -81,6 +81,10 @@ public final class FaceDetector extends BaseVisionTaskApi {
private static final String TASK_GRAPH_NAME = private static final String TASK_GRAPH_NAME =
"mediapipe.tasks.vision.face_detector.FaceDetectorGraph"; "mediapipe.tasks.vision.face_detector.FaceDetectorGraph";
static {
System.loadLibrary("mediapipe_tasks_vision_jni");
}
/** /**
* Creates a {@link FaceDetector} instance from a model file and the default {@link * Creates a {@link FaceDetector} instance from a model file and the default {@link
* FaceDetectorOptions}. * FaceDetectorOptions}.

View File

@ -86,6 +86,10 @@ public final class FaceLandmarker extends BaseVisionTaskApi {
private static final String TASK_GRAPH_NAME = private static final String TASK_GRAPH_NAME =
"mediapipe.tasks.vision.face_landmarker.FaceLandmarkerGraph"; "mediapipe.tasks.vision.face_landmarker.FaceLandmarkerGraph";
static {
System.loadLibrary("mediapipe_tasks_vision_jni");
}
/** /**
* Creates a {@link FaceLandmarker} instance from a model asset bundle path and the default {@link * Creates a {@link FaceLandmarker} instance from a model asset bundle path and the default {@link
* FaceLandmarkerOptions}. * FaceLandmarkerOptions}.

View File

@ -88,6 +88,10 @@ public final class FaceStylizer extends BaseVisionTaskApi {
"mediapipe.tasks.vision.face_stylizer.FaceStylizerGraph"; "mediapipe.tasks.vision.face_stylizer.FaceStylizerGraph";
private final boolean hasResultListener; private final boolean hasResultListener;
static {
System.loadLibrary("mediapipe_tasks_vision_jni");
}
/** /**
* Creates an {@link FaceStylizer} instance from an {@link FaceStylizerOptions}. * Creates an {@link FaceStylizer} instance from an {@link FaceStylizerOptions}.
* *

View File

@ -93,6 +93,10 @@ public final class GestureRecognizer extends BaseVisionTaskApi {
private static final String TASK_GRAPH_NAME = private static final String TASK_GRAPH_NAME =
"mediapipe.tasks.vision.gesture_recognizer.GestureRecognizerGraph"; "mediapipe.tasks.vision.gesture_recognizer.GestureRecognizerGraph";
static {
System.loadLibrary("mediapipe_tasks_vision_jni");
}
/** /**
* Creates a {@link GestureRecognizer} instance from a model file and the default {@link * Creates a {@link GestureRecognizer} instance from a model file and the default {@link
* GestureRecognizerOptions}. * GestureRecognizerOptions}.

View File

@ -89,6 +89,10 @@ public final class HandLandmarker extends BaseVisionTaskApi {
private static final String TASK_GRAPH_NAME = private static final String TASK_GRAPH_NAME =
"mediapipe.tasks.vision.hand_landmarker.HandLandmarkerGraph"; "mediapipe.tasks.vision.hand_landmarker.HandLandmarkerGraph";
static {
System.loadLibrary("mediapipe_tasks_vision_jni");
}
/** /**
* Creates a {@link HandLandmarker} instance from a model file and the default {@link * Creates a {@link HandLandmarker} instance from a model file and the default {@link
* HandLandmarkerOptions}. * HandLandmarkerOptions}.

View File

@ -104,6 +104,7 @@ public final class ImageClassifier extends BaseVisionTaskApi {
"mediapipe.tasks.vision.image_classifier.ImageClassifierGraph"; "mediapipe.tasks.vision.image_classifier.ImageClassifierGraph";
static { static {
System.loadLibrary("mediapipe_tasks_vision_jni");
ProtoUtil.registerTypeName( ProtoUtil.registerTypeName(
ClassificationsProto.ClassificationResult.class, ClassificationsProto.ClassificationResult.class,
"mediapipe.tasks.components.containers.proto.ClassificationResult"); "mediapipe.tasks.components.containers.proto.ClassificationResult");

View File

@ -87,6 +87,7 @@ public final class ImageEmbedder extends BaseVisionTaskApi {
"mediapipe.tasks.vision.image_embedder.ImageEmbedderGraph"; "mediapipe.tasks.vision.image_embedder.ImageEmbedderGraph";
static { static {
System.loadLibrary("mediapipe_tasks_vision_jni");
ProtoUtil.registerTypeName( ProtoUtil.registerTypeName(
EmbeddingsProto.EmbeddingResult.class, EmbeddingsProto.EmbeddingResult.class,
"mediapipe.tasks.components.containers.proto.EmbeddingResult"); "mediapipe.tasks.components.containers.proto.EmbeddingResult");

View File

@ -80,6 +80,10 @@ public final class ImageGenerator extends BaseVisionTaskApi {
private CachedInputs cachedInputs = new CachedInputs(); private CachedInputs cachedInputs = new CachedInputs();
private boolean inProcessing = false; private boolean inProcessing = false;
static {
System.loadLibrary("mediapipe_tasks_vision_image_generator_jni");
}
/** /**
* Creates an {@link ImageGenerator} instance from an {@link ImageGeneratorOptions}. * Creates an {@link ImageGenerator} instance from an {@link ImageGeneratorOptions}.
* *

View File

@ -93,6 +93,10 @@ public final class ImageSegmenter extends BaseVisionTaskApi {
private boolean hasResultListener = false; private boolean hasResultListener = false;
private List<String> labels = new ArrayList<>(); private List<String> labels = new ArrayList<>();
static {
System.loadLibrary("mediapipe_tasks_vision_jni");
}
/** /**
* Creates an {@link ImageSegmenter} instance from an {@link ImageSegmenterOptions}. * Creates an {@link ImageSegmenter} instance from an {@link ImageSegmenterOptions}.
* *

View File

@ -102,6 +102,7 @@ public final class InteractiveSegmenter extends BaseVisionTaskApi {
private List<String> labels = new ArrayList<>(); private List<String> labels = new ArrayList<>();
static { static {
System.loadLibrary("mediapipe_tasks_vision_jni");
ProtoUtil.registerTypeName(RenderData.class, "mediapipe.RenderData"); ProtoUtil.registerTypeName(RenderData.class, "mediapipe.RenderData");
} }

View File

@ -113,6 +113,10 @@ public final class ObjectDetector extends BaseVisionTaskApi {
private static final int IMAGE_OUT_STREAM_INDEX = 1; private static final int IMAGE_OUT_STREAM_INDEX = 1;
private static final String TASK_GRAPH_NAME = "mediapipe.tasks.vision.ObjectDetectorGraph"; private static final String TASK_GRAPH_NAME = "mediapipe.tasks.vision.ObjectDetectorGraph";
static {
System.loadLibrary("mediapipe_tasks_vision_jni");
}
/** /**
* Creates an {@link ObjectDetector} instance from a model file and the default {@link * Creates an {@link ObjectDetector} instance from a model file and the default {@link
* ObjectDetectorOptions}. * ObjectDetectorOptions}.

View File

@ -86,6 +86,10 @@ public final class PoseLandmarker extends BaseVisionTaskApi {
private static final String TASK_GRAPH_NAME = private static final String TASK_GRAPH_NAME =
"mediapipe.tasks.vision.pose_landmarker.PoseLandmarkerGraph"; "mediapipe.tasks.vision.pose_landmarker.PoseLandmarkerGraph";
static {
System.loadLibrary("mediapipe_tasks_vision_jni");
}
/** /**
* Creates a {@link PoseLandmarker} instance from a model file and the default {@link * Creates a {@link PoseLandmarker} instance from a model file and the default {@link
* PoseLandmarkerOptions}. * PoseLandmarkerOptions}.