Ask Your Question
4

How to track multiple images using ARCore in Android Studio?

asked 2023-06-17 07:41:42 +0000

djk gravatar image

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
3

answered 2023-06-17 07:51:01 +0000

ladyg gravatar image

To track multiple images using ARCore in Android Studio, you can follow these steps:

  1. Add ARCore dependencies to your project by adding the following lines in your app's build.gradle file:
implementation 'com.google.ar:core:1.18.0'
implementation 'com.google.ar.sceneform:core:1.18.0'
  1. Create an ARCore session by calling the ARCore's Session constructor and passing the current activity context as an argument.

  2. Define a list of image targets that you want to track using ARCore. You can create an image database by adding the images in the assets folder and create an instance of ImageDatabase using the builder. For example,

val imageDatabase =
    ImageDatabase.builder(context)
        .addReferenceImage("image_name_1.jpg")
        .addReferenceImage("image_name_2.jpg")
        .addReferenceImage("image_name_3.jpg")
        .build()
  1. Once a session is created, you can start the image tracking process by calling the ARCore session's configure() method and passing the Config object as the argument. The Config object can be used to set up the image tracking settings such as the detection mode and the image database to be used.

In the Config object, set the image database to be used with the setAugmentedImageDatabase() method.

val config = Config(session)
        .apply {
            augmentedImageDatabase = imageDatabase
        }
session.configure(config)
  1. After the session is configured, you can start the ARCore's frame and image tracking using the onDrawFrame method of the GLSurfaceView object.

  2. In the onDrawFrame method, you can call the session's update() method to update the image tracking state for each frame.

val arFrame = session.update()
  1. Iterate over the augmented images detected in the current frame using the arFrame.getUpdatedTrackables() method. This method returns a list of all the trackable images detected in the frame along with their tracking state.

  2. For each detected image, you can check its tracking state and render any augmented content accordingly.

for (trackable in arFrame.getUpdatedTrackables(AugmentedImage::class.java)) {

    if (trackable.trackingState == TrackingState.TRACKING) {
        // Render the augmented content
    }
}

Following these steps, you can track multiple images using ARCore in Android Studio.

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account. This space is reserved only for answers. If you would like to engage in a discussion, please instead post a comment under the question or an answer that you would like to discuss

Add Answer


Question Tools

Stats

Asked: 2023-06-17 07:41:42 +0000

Seen: 13 times

Last updated: Jun 17 '23