2

I am wondering if it is possible to use ARToolkit for single image detection in Android wrapper? For example: choose image from gallery or capture image with camera and then send bytes to ARToolkit for marker recognition?

kubedo8
  • 21
  • 1
  • 4

1 Answers1

1

Yes, it's very much possible and I've done it already but in a little different way.

I have integrated ARToolkit library into the sample ARCore app(hello_ar_java) from the github repo of ARCore, I used artoolkitx for image detection since it's detection speed is very fast.

In the hello_ar_java app, there's an openGL function onDrawFrame() which gets called on every frame change and here the frames that I receive from ARCore session update is converted into image(jpeg) files and written to the disk.

ARToolkit java wrapper has a method arwStartRunning() in ARX_jni.java which accepts video configuration and camera parameters as method parameters. Your task here is, in the java wrapper there's a class ARController.java, write a method in this class to call the arwStartRunning() of ARX_jni.java

Eg.

 public boolean startRunning(String cfg) {
     if (!ARX_jni.arwStartRunning(cfg, null)) {
         Log.e(TAG, "StartRunning command failed.");
         return false;
     }
     Log.e(TAG, "StartRunning command passed.");
     return true;
 }

Now rebuild ARToolkit library and add the new arxj-release.aar file into your app.

From your android app code, call the startRunning() method by passing configurations as

String cfg = "-module=Image -width=" + imageWidth + " -height=" + imageHeight + " -image=" + imageAbsolutePath;

boolean runStatus = ARController.getInstance().startRunning(cfg);

if (runStatus) {
    if (!ARController.getInstance().captureAndUpdate()) {
        Log.e(TAG, "ARController update call failed, skip going further.");
        return;
    } else Log.d(TAG, "vaib: ARController update call passed");

    for (int trackableUID : trackableUIDs) {
        float[] modelViewMatrix = new float[16];
        if (ARController.getInstance().queryTrackableVisibilityAndTransformation(trackableUID, modelViewMatrix)) {
            float[] projectionMatrix = ARController.getInstance().getProjectionMatrix(10.0f, 10000.0f);
            Log.e(TAG, "Trackable "+trackableUID +" is visible.");
            runOnUiThread(() -> showToast("Trackable "+trackableUID +" is visible."));

        } else Log.e(TAG, "Trackable "+trackableUID +" is not visible");
    }
} else Log.e(TAG, "Failed to start ARToolkit, config used : " + cfg);
Vaibhav S
  • 115
  • 1
  • 12