arcore-android-sdk icon indicating copy to clipboard operation
arcore-android-sdk copied to clipboard

Issue with ARCore Real-Time Image Tracking – Tracking Status Not Resetting

Open appenvturez-siddharth opened this issue 9 months ago • 1 comments

SPECIFIC ISSUE ENCOUNTERED

I am currently using ARCore for real-time image tracking, and I am facing an issue where the tracking status of an object does not reset even when I am no longer pointing the camera at the tracked image.

Issue Description: • I have implemented image tracking using ARCore’s Augmented Image Database. • When an object gets successfully detected and tracked, it maintains the TrackingState.TRACKING status as expected. • However, the issue arises when I move the camera away from the tracked object. Instead of switching to TrackingState.PAUSED or stopping tracking, it continues to show the object as “tracked” even though it is no longer in the camera’s view. • This causes unintended behavior, as the app still considers the object as detected and tracked, even though it is no longer visible in the frame.

VERSIONS USED

  • Android Studio: Android Studio Koala | 2024.1.1
  • ARCore SDK for Android: 1.47.0
  • Device manufacturer, model, and O/S: Google, Pixel 7, Android
  • Google Play Services for AR (ARCore): 1.48.250340293 On Windows, use: adb shell pm dump com.google.ar.core | findstr /i "packages: versionName" On macOS, use: adb shell pm dump com.google.ar.core | egrep -i versionName\|packages:
  • Output of adb shell getprop ro.build.fingerprint:

STEPS TO REPRODUCE THE ISSUE

Add the required dependencies.

core = "1.47.0"
core = { module = "com.google.ar:core", version.ref = "core" }

sceneformUx = "1.17.1"
sceneform-ux = { group = "com.google.ar.sceneform.ux", name = "sceneform-ux", version.ref = "sceneformUx" }

AR SceneView XML:

<fragment
    android:id="@+id/ar_scene_view"
    android:name="com.google.ar.sceneform.ux.ArFragment"
    android:layout_width="match_parent"
    android:layout_height="match_parent" />

ARcore Intiailization:

private lateinit var arFragment: ArFragment
arFragment = supportFragmentManager.findFragmentById(R.id.ar_scene_view) as ArFragment

private fun initializeAR() {
    var exception: Exception? = null
    try {
        when (ArCoreApk.getInstance().requestInstall(this, true)) {
            ArCoreApk.InstallStatus.INSTALLED -> setupSession()
            ArCoreApk.InstallStatus.INSTALL_REQUESTED -> return
        }
    } catch (e: Exception) {
        exception = e
    }

    if (exception != null || arSession == null) {
        Toast.makeText(this, "ARCore failed to initialize", Toast.LENGTH_LONG).show()
        finish()
    }
}

Session Setup for Image Tracking:

private fun setupSession() {
    arFragment.planeDiscoveryController.hide()
    arFragment.planeDiscoveryController.setInstructionView(null)
    
    arSession = Session(this)
    arConfig = Config(arSession)
    
    setupImageDatabase {
        arConfig?.setAugmentedImageDatabase(augmentedImageDatabase)
        arSession?.configure(arConfig)
        handler.post { Toast.makeText(this, "Database Sync Completed", Toast.LENGTH_SHORT).show() }
    }
    
    arConfig?.setFocusMode(Config.FocusMode.AUTO)
    arConfig?.planeFindingMode = Config.PlaneFindingMode.DISABLED
    arConfig?.imageStabilizationMode = Config.ImageStabilizationMode.OFF
    arConfig?.setUpdateMode(Config.UpdateMode.LATEST_CAMERA_IMAGE)
    arSession?.configure(arConfig)

    arFragment.arSceneView?.setupSession(arSession)
}

Frame Update to Track Images:

override fun onUpdate(frameTime: FrameTime?) {
    val frame = arFragment.arSceneView?.arFrame ?: return

    val images = frame.getUpdatedTrackables(AugmentedImage::class.java)

    for (image in images) {
        when (image.trackingState) {
            TrackingState.TRACKING -> {
                if (!trackedImages.contains(image.name)) {
                    handleDetectedImage(image)
                    trackedImages.add(image.name)
                }
            }
            TrackingState.PAUSED -> {
                // Remove tracking if the image is no longer visible
                trackedImages.remove(image.name)
                runOnUiThread {
                    Toast.makeText(this, "Tracking lost for ${image.name}", Toast.LENGTH_SHORT).show()
                }
            }
            TrackingState.STOPPED -> {
                // Clear the image from tracking
                trackedImages.remove(image.name)
            }
        }
    }
}

appenvturez-siddharth avatar Mar 18 '25 09:03 appenvturez-siddharth

@jankleinert @devbridie @

appenvturez-siddharth avatar Mar 18 '25 15:03 appenvturez-siddharth