0

I wanted to create an app via React-Native for pose detection by using ML Kit. I used the instructions of the Google Ml Kit website and I used the following task: poseDetector.process(image)

But when building, I get the error:

 error: cannot access Detector
      poseDetector.process(image)
                  ^
  class file for com.google.mlkit.vision.common.internal.Detector not found

I used several imports in the Java file, but apparently I get the same error over and over again but I don't know why. I can't find anything to it. It seems nobody has the same problem. I thought maybe it's an easy fix.

Imported several dependencies in build.gradle and libraries in the application.

For the application (full code):

import android.graphics.PointF;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;

import androidx.annotation.NonNull;

import com.facebook.react.ReactPackage;
import com.facebook.react.bridge.NativeModule;
import com.facebook.react.bridge.ReactApplicationContext;
import com.facebook.react.uimanager.ViewManager;
import com.facebook.react.bridge.ReactContextBaseJavaModule;
import com.facebook.react.bridge.ReactMethod;
import com.facebook.react.bridge.Promise;

import com.google.android.gms.tasks.OnFailureListener;
import com.google.android.gms.tasks.OnSuccessListener;
import com.google.mlkit.vision.common.InputImage;
import com.google.mlkit.vision.common.PointF3D;
import com.google.mlkit.vision.common.Triangle;


import com.google.mlkit.vision.pose.accurate.AccuratePoseDetectorOptions;
import com.google.mlkit.vision.interfaces.Detector;
import com.google.mlkit.vision.pose.Pose;
import com.google.mlkit.vision.pose.PoseDetector;
import com.google.mlkit.vision.pose.PoseDetection;
import com.google.mlkit.vision.pose.PoseDetectorOptionsBase;
import com.google.mlkit.vision.pose.PoseLandmark;
import com.google.mlkit.vision.pose.defaults.PoseDetectorOptions;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class PoseDetectionModule extends ReactContextBaseJavaModule {

    private static ReactApplicationContext reactContext;

    PoseDetectionModule(ReactApplicationContext context) {
        super(context);
        reactContext = context;
    }

    @Override
    public String getName() {
        return "PoseDetection";
    }

  @ReactMethod
  public void findPose(String imagePath, Promise promise) {
    try {
      Bitmap bitmap = BitmapFactory.decodeFile(imagePath);
      InputImage image = InputImage.fromBitmap(bitmap, 0);
      
      PoseDetectorOptions options =
          new PoseDetectorOptions.Builder()
              .setDetectorMode(PoseDetectorOptions.STREAM_MODE)
              .build();

      PoseDetector poseDetector = PoseDetection.getClient(options);
      poseDetector.process(image)
          .addOnSuccessListener(
              pose -> {
                Map<String, Map<String, Float>> landmarks = new HashMap<>();
                pose.getAllPoseLandmarks().forEach(landmark -> {
                  Map<String, Float> position = new HashMap<>();
                  position.put("x", landmark.getPosition().x);
                  position.put("y", landmark.getPosition().y);
                  landmarks.put(landmark.getLandmarkType().name(), position);
                });
                promise.resolve(landmarks);
              })
          .addOnFailureListener(
              e -> promise.reject("Pose detection failed", e));
    } catch (Exception e) {
      promise.reject("Pose detection failed", e);
    }
  }
}

I know a lot of the imports are unused, but that's the result of desperation I guess...

The dependencies in gradle:

dependencies {
    implementation("com.facebook.react:react-android")
    implementation("com.facebook.react:react-native:+")
    implementation("com.facebook.soloader:soloader:0.10.3")
    implementation 'com.google.mlkit:pose-detection:17.0.1-beta3'
    implementation 'com.google.mlkit:pose-detection-accurate:17.0.1-beta3'
    implementation 'com.google.mlkit:vision-common:17.0.0'
    implementation 'com.google.mlkit:vision-interfaces:16.0.0'
    implementation 'androidx.annotation:annotation:1.3.0'
    implementation 'com.google.android.gms:play-services-tasks:18.0.0'
    implementation 'com.android.support:multidex:1.0.3'

I repeat: desperation

2
  • Does your Gradle build script pull in all required dependencies? If you think it does, a minimal reproducible example would be helpful. Commented Jun 12, 2024 at 17:32
  • I edited the post with the dependencies. Is something missing? Commented Jun 12, 2024 at 17:51

1 Answer 1

0

Simple answer: the dependencies were not correct. Apparently you need the latest versions of posedetection. Currently it's 18.0.0-beta4.

So in the dependencies:

 implementation 'com.google.mlkit:pose-detection:18.0.0-beta4'
 implementation 'com.google.mlkit:pose-detection-accurate:18.0.0-beta4'
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.