google-ar / arcore-android-sdk

ARCore SDK for Android Studio
https://developers.google.com/ar
Other
4.97k stars 1.22k forks source link

Unable to switch off image tracking when it is no longer needed #999

Open Str0ss opened 4 years ago

Str0ss commented 4 years ago

SPECIFIC ISSUE ENCOUNTERED

It is impossible to disable the augmented image engine after we don't need it anymore. Tested on augmented_image_java example.

Why am I bothered with disabling the augmented image engine? Because it introduces a significant delay in ARCore image processing (both background image and camera pose are updated ~100 ms later when augmented image detection is on). A simple test can be done: point a phone on any stopwatch screen and take a picture of both screens with some other camera. The difference between two times will represent the delay. I got ~100 ms total delay when no image detection, and ~200 ms total delay with image detection, regardless of whether image was detected or not. For my app it's sufficient to detect image once, place an anchor on it's last position, and disable further image detection, so I wanted to switch it off to get rid of the +100 ms delay.

VERSIONS USED

STEPS TO REPRODUCE THE ISSUE

  1. Launch the augmented_image_java example. Measure the camera delay (you can use the method described above). Write down the value, it must be around 200 ms.
  2. Comment out the line config.setAugmentedImageDatabase(augmentedImageDatabase); in AugmentedImageActivity.java to disable augmented image detection. Launch the app, repeat the measurement, write down the delay. It should be ~100 ms less than the previous value.
  3. Uncomment the line commented in p. 2 (to switch the image detection on again). Add following lines to the function drawAugmentedImages, to case TRACKING:
          Config config = new Config(session);
          config.setFocusMode(Config.FocusMode.AUTO);
          config.setAugmentedImageDatabase(null);
          session.configure(config);

This code will disable image detection immediately after the image was found (doc). Launch the app, point the camera on any of the images from arcore-android-sdk\media\augmented_image_database. Notice that after image was found, the image detection actually stopped working (the image frame will disappear quickly after the image was recognized, and the app will recognize no more images after that). Now measure the camera delay - it will still be big (as in p. 1). That means that something is left from the image detection engine, and this 'something' is causing the delay. And this is definitely not needed.

WORKAROUNDS (IF ANY)

Any ideas will be welcome. I even tried to pause+resume the session when re-configuring, with no success.

Thanks in advance. Although I may have missed some obvious thing from the docs, I think this issue is real and must be addressed somehow.

P.S. photos to illustrate the experiments. Augmented image OFF: aug_img_off Augmented image ON: aug_img_on

RGregat commented 4 years ago

Maybe I don't understand fully your problem, but I would guess that not the setting is the problem. What about to just stop aksing ARCore to look for trackable images?

I have a separate class to handle Augmented Images and there I have an onUpdate function with the current frame as a parameter.

```java
public void onUpdate(Frame frame) {
        Collection<AugmentedImage> updatedAugmentedImages = frame.getUpdatedTrackables(AugmentedImage.class);
        for (AugmentedImage augmentedImage : updatedAugmentedImages) {
            if (augmentedImage.getTrackingState() == TrackingState.TRACKING) {
                if (augmentedImage.getTrackingMethod() == AugmentedImage.TrackingMethod.FULL_TRACKING) {
                   // Do something
                }
            }
        }
}

So if I don't want any tracking I simple don't call onUpdate.