You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何在Android Studio中为Marker-based AR应用配置Marker-less AR作为 fallback?

Solutions for Marker-less AR Fallback in Vuforia (Android Studio)

Hey there! I’ve built similar fallback AR workflows with Vuforia on Android, so I can share a couple of practical solutions to keep your AR experience going when the marker goes out of view. Both options work within Android Studio and prioritize keeping your AR content visible, even with minor expected errors.


Option 1: Use Vuforia’s Built-in Ground Plane Tracking

Vuforia has its own marker-less AR feature (Ground Plane) that you can leverage as a fallback without adding extra SDKs. Here’s how to set it up:

  1. Enable Ground Plane in Vuforia Configuration

    • Open your Vuforia Developer Dashboard, go to your project, and enable the Ground Plane feature for your license key.
    • In Android Studio, update your Vuforia setup to include Ground Plane tracking (add the GroundPlaneObserver to your AR session).
  2. Track Marker Presence & Switch Modes

    • Use Vuforia’s target listeners to detect when the marker is lost/found. When lost, migrate your AR content to the Ground Plane’s tracking space.
    • Save the marker’s last known pose before it’s lost, then bind your AR content to a Ground Plane anchor using that pose to maintain position continuity.

Code Snippet for Marker/Ground Plane Switch

private boolean isTrackingMarker = true;
private boolean isUsingGroundPlane = false;
private Node arContent; // Your 3D AR content node
private ImageTargetObserver markerObserver;
private GroundPlaneObserver groundPlaneObserver;

// Initialize listeners in your setup method
markerObserver.registerListener(new ImageTargetListener() {
    @Override
    public void onTargetFound(@NonNull ImageTargetObserver observer, @NonNull VuTargetTargetStatus status) {
        // Switch back to marker tracking
        arContent.setParent(markerObserver.getTargetNode());
        isTrackingMarker = true;
        isUsingGroundPlane = false;
    }

    @Override
    public void onTargetLost(@NonNull ImageTargetObserver observer, @NonNull VuTargetTargetStatus status) {
        if (!isUsingGroundPlane) {
            // Save the marker's final pose
            VuPose lastMarkerPose = observer.getTargetPose();
            // Create a temporary Ground Plane anchor at the marker's last position
            VuAnchor groundAnchor = groundPlaneObserver.createAnchor(lastMarkerPose);
            // Migrate AR content to the Ground Plane anchor
            arContent.setParent(groundAnchor.getNode());
            arContent.setLocalPose(lastMarkerPose.toMatrix());
            
            isTrackingMarker = false;
            isUsingGroundPlane = true;
        }
    }
});
  1. Key Notes
    • Ground Plane relies on detecting flat surfaces, so it works best in environments with visible floors/walls.
    • Minor drift is expected over time, but this is acceptable as a backup.

Option 2: Combine Vuforia with ARCore for More Robust Marker-less Tracking

If you want smoother marker-less fallback, integrate ARCore (Google’s AR SDK) alongside Vuforia. ARCore’s visual-inertial odometry is great for maintaining tracking without markers.

  1. Set Up ARCore in Android Studio

    • Add the ARCore dependency to your build.gradle file:
      dependencies {
          implementation 'com.google.ar:core:1.37.0'
      }
      
    • Add ARCore permissions to your AndroidManifest.xml:
      <uses-permission android:name="android.permission.CAMERA" />
      <uses-feature android:name="android.hardware.camera.ar" android:required="false" />
      
  2. Switch Between Vuforia Marker Tracking and ARCore

    • Initialize an ARCore session alongside your Vuforia session. When the marker is lost, use ARCore to create an anchor at the marker’s last position, then bind your AR content to it.
    • When the marker is re-detected, switch back to Vuforia’s marker tracking and reset the content’s position.

Code Snippet for Vuforia/ARCore Switch

private ArCoreSession arCoreSession;
private boolean isUsingArCore = false;

// Initialize ARCore in your Activity's onCreate()
arCoreSession = new ArCoreSession(this);
arCoreSession.resume();

// Vuforia marker lost callback
@Override
public void onTargetLost(@NonNull ImageTargetObserver observer, @NonNull VuTargetTargetStatus status) {
    if (!isUsingArCore) {
        // Get Vuforia's last camera pose
        VuCameraPose vuforiaCameraPose = vuforiaEngine.getCameraPose();
        // Convert to ARCore Pose format
        float[] translation = vuforiaCameraPose.getTranslation().toArray();
        float[] rotation = vuforiaCameraPose.getRotation().toArray();
        Pose arCorePose = new Pose(translation, rotation);
        
        // Create ARCore anchor at the marker's last position
        Frame currentFrame = arCoreSession.update();
        Anchor arCoreAnchor = currentFrame.createAnchor(arCorePose);
        
        // Bind AR content to ARCore anchor
        arContent.setAnchor(arCoreAnchor);
        isUsingArCore = true;
        isTrackingMarker = false;
    }
}

// Marker found callback
@Override
public void onTargetFound(@NonNull ImageTargetObserver observer, @NonNull VuTargetTargetStatus status) {
    if (isUsingArCore) {
        // Unbind from ARCore anchor
        arContent.setAnchor(null);
        // Re-bind to Vuforia marker
        arContent.setParent(markerObserver.getTargetNode());
        isUsingArCore = false;
        isTrackingMarker = true;
    }
}
  1. Key Notes
    • ARCore provides more stable marker-less tracking than Vuforia’s Ground Plane, especially in dynamic environments.
    • Ensure both SDKs share the camera feed to avoid performance issues (Vuforia can use ARCore as its camera provider in settings).

General Tips for Smooth Fallback

  • Smooth Transitions: Use a simple animation (like ObjectAnimator) to interpolate between the marker’s last pose and the marker-less anchor’s pose, avoiding sudden jumps.
  • Error Correction: When the marker is re-detected, reset your AR content’s position to match the marker’s current pose to fix any drift that occurred during marker-less tracking.
  • Performance Optimization: Pause unused tracking sessions (e.g., pause Vuforia’s marker detection when using ARCore) to reduce CPU/GPU load.

内容的提问来源于stack exchange,提问作者nipunasudha

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.26 10:35:04