[null,null,["最后更新时间 (UTC):2025-07-26。"],[[["\u003cp\u003eLearn to use Augmented Images in your apps to overlay digital content onto real-world images, requiring fundamental AR concepts and ARCore session configuration knowledge.\u003c/p\u003e\n"],["\u003cp\u003eCreate and manage image databases, which can store up to 1,000 images and be loaded or built dynamically within your app.\u003c/p\u003e\n"],["\u003cp\u003eAdd images to your database, specifying names and physical dimensions, and enable image tracking within your ARCore session to detect these images in the real world.\u003c/p\u003e\n"],["\u003cp\u003eUnderstand how ARCore tracks images, providing pose information even when they move out of view, and consider the tracking methods for different use cases like fixed or moving images.\u003c/p\u003e\n"]]],["To use Augmented Images, create an `AugmentedImageDatabase` by loading a saved database or creating a new one, adding images with `addImage()` specifying their width, if known. Configure the ARCore session with this database via `setAugmentedImageDatabase()`. During the session, retrieve updated `AugmentedImage`s. Check the image `TrackingState` and `TrackingMethod` to determine its tracking status. Use `img.getIndex()` or `img.getName()` to determine which image was matched. Render content based on detected images.\n"],null,["# Augmented Images developer guide for Android\n\nLearn how to use Augmented Images in your own apps.\n\nPrerequisites\n-------------\n\nMake sure that you understand [fundamental AR concepts](/ar/develop/fundamentals)\nand how to [configure an ARCore session](/ar/develop/java/session-config) before proceeding.\n\nCreate an image database\n------------------------\n\nEach image database can store information for up to 1,000 images.\n\nThere two ways to create an\n[`AugmentedImageDatabase`](/ar/reference/java/com/google/ar/core/AugmentedImageDatabase):\n\n- **Load a saved image database**. Then optionally add more reference images.\n- **Create a new empty database**. Then add reference images one at a time.\n\n### Load a saved image database\n\nUse [`AugmentedImageDatabase.deserialize()`](/ar/reference/java/com/google/ar/core/AugmentedImageDatabase#deserialize(com.google.ar.core.Session,%20java.io.InputStream))\nto load an existing image database: \n\n### Java\n\n```java\nAugmentedImageDatabase imageDatabase;\ntry (InputStream inputStream = this.getAssets().open(\"example.imgdb\")) {\n imageDatabase = AugmentedImageDatabase.deserialize(session, inputStream);\n} catch (IOException e) {\n // The Augmented Image database could not be deserialized; handle this error appropriately.\n}\n```\n\n### Kotlin\n\n```kotlin\nval imageDatabase = this.assets.open(\"example.imgdb\").use {\n AugmentedImageDatabase.deserialize(session, it)\n}\n```\n\nImage databases can be created using the [`arcoreimg`](/ar/develop/java/augmented-images/arcoreimg)\ncommand line tool during development, or by calling\n[`AugmentedImageDatabase.serialize()`](/ar/reference/java/com/google/ar/core/AugmentedImageDatabase#serialize(java.io.OutputStream))\non a database that contains that is loaded in memory.\n\n### Create a new empty database\n\nTo create an empty image database at runtime, use the [`AugmentedImageDatabase` constructor](/ar/reference/java/com/google/ar/core/AugmentedImageDatabase#AugmentedImageDatabase(com.google.ar.core.Session)): \n\n### Java\n\n```java\nAugmentedImageDatabase imageDatabase = new AugmentedImageDatabase(session);\n```\n\n### Kotlin\n\n```kotlin\nval imageDatabase = AugmentedImageDatabase(session)\n```\n\n### Add images to an existing database\n\nAdd images to your image database by calling\n[`AugmentedImageDatabase.addImage()`](/ar/reference/java/com/google/ar/core/AugmentedImageDatabase#addImage(java.lang.String,%20android.graphics.Bitmap,%20float))\nfor each image, specifying an optional `widthInMeters`. \n\n### Java\n\n```java\nBitmap bitmap;\ntry (InputStream bitmapString = getAssets().open(\"dog.jpg\")) {\n bitmap = BitmapFactory.decodeStream(bitmapString);\n} catch (IOException e) {\n // The bitmap could not be found in assets; handle this error appropriately.\n throw new AssertionError(\"The bitmap could not be found in assets.\", e);\n}\n\n// If the physical size of the image is not known, use addImage(String, Bitmap) instead, at the\n// expense of an increased image detection time.\nfloat imageWidthInMeters = 0.10f; // 10 cm\nint dogIndex = imageDatabase.addImage(\"dog\", bitmap, imageWidthInMeters);\n```\n\n### Kotlin\n\n```kotlin\nval bitmap = assets.open(\"dog.jpg\").use { BitmapFactory.decodeStream(it) }\n// If the physical size of the image is not known, use addImage(String, Bitmap) instead, at the\n// expense of an increased image detection time.\nval imageWidthInMeters = 0.10f // 10 cm\nval dogIndex = imageDatabase.addImage(\"dog\", bitmap, imageWidthInMeters)\n```\n\nThe returned indexes can later be used to identify which reference image was\ndetected.\n\nEnable image tracking\n---------------------\n\nConfigure your ARCore session to begin tracking images by setting the session\nconfig to one that is configured with the desired image database: \n\n### Java\n\n```java\nConfig config = new Config(session);\nconfig.setAugmentedImageDatabase(imageDatabase);\nsession.configure(config);\n```\n\n### Kotlin\n\n```kotlin\nval config = Config(session)\nconfig.augmentedImageDatabase = imageDatabase\nsession.configure(config)\n```\n\nDuring the session, ARCore looks for images by matching feature points from the\ncamera image against those in the image database.\n\nTo get the matched images, poll for updated [`AugmentedImage`s](/ar/reference/java/com/google/ar/core/AugmentedImage) in your frame update loop. \n\n### Java\n\n```java\nCollection\u003cAugmentedImage\u003e updatedAugmentedImages =\n frame.getUpdatedTrackables(AugmentedImage.class);\nfor (AugmentedImage img : updatedAugmentedImages) {\n if (img.getTrackingState() == TrackingState.TRACKING) {\n // Use getTrackingMethod() to determine whether the image is currently\n // being tracked by the camera.\n switch (img.getTrackingMethod()) {\n case LAST_KNOWN_POSE:\n // The planar target is currently being tracked based on its last\n // known pose.\n break;\n case FULL_TRACKING:\n // The planar target is being tracked using the current camera image.\n break;\n case NOT_TRACKING:\n // The planar target isn't been tracked.\n break;\n }\n\n // You can also check which image this is based on img.getName().\n if (img.getIndex() == dogIndex) {\n // TODO: Render a 3D version of a dog in front of img.getCenterPose().\n } else if (img.getIndex() == catIndex) {\n // TODO: Render a 3D version of a cat in front of img.getCenterPose().\n }\n }\n}\n```\n\n### Kotlin\n\n```kotlin\nval updatedAugmentedImages = frame.getUpdatedTrackables(AugmentedImage::class.java)\n\nfor (img in updatedAugmentedImages) {\n if (img.trackingState == TrackingState.TRACKING) {\n // Use getTrackingMethod() to determine whether the image is currently\n // being tracked by the camera.\n when (img.trackingMethod) {\n AugmentedImage.TrackingMethod.LAST_KNOWN_POSE -\u003e {\n // The planar target is currently being tracked based on its last known pose.\n }\n AugmentedImage.TrackingMethod.FULL_TRACKING -\u003e {\n // The planar target is being tracked using the current camera image.\n }\n AugmentedImage.TrackingMethod.NOT_TRACKING -\u003e {\n // The planar target isn't been tracked.\n }\n }\n\n // You can also check which image this is based on AugmentedImage.getName().\n when (img.index) {\n dogIndex -\u003e TODO(\"Render a 3D version of a dog at img.getCenterPose()\")\n catIndex -\u003e TODO(\"Render a 3D version of a cat at img.getCenterPose()\")\n }\n }\n}\n```\n\n### Supporting different use cases\n\nWhen ARCore detects an Augmented Image, it creates a [`Trackable`](/ar/reference/java/com/google/ar/core/Trackable) for that\nAugmented Image and sets [`TrackingState`](/ar/reference/java/com/google/ar/core/TrackingState)\nto `TRACKING` and [`TrackingMethod`](/ar/reference/java/com/google/ar/core/AugmentedImage.TrackingMethod)\nto `FULL_TRACKING`. When the tracked image moves out of camera view, ARCore\nchanges the [`TrackingMethod`](/ar/reference/java/com/google/ar/core/AugmentedImage.TrackingMethod)\nto `LAST_KNOWN_POSE` while continuing to provide the orientation and position of\nthe image.\n\nYour app should use these enumerations differently depending on the intended use\ncase.\n\n- **Fixed images** . Most use cases involving images that are fixed in place\n (that is, not expected to move) can simply use `TrackingState` to determine\n whether the image has been detected and whether its location is known.\n `TrackingMethod` can be ignored.\n\n- **Moving images** . If your app needs to track a moving image, use both\n `TrackingState` and `TrackingMethod` to determine whether the image has been\n detected and whether its position is known.\n\n| Use case | Fixed image | Moving image |\n| Example | A poster hung on a wall | An advertisement on the side of a bus |\n| The pose can be considered valid when | `TrackingState == TRACKING` | `TrackingState == TRACKING` and `TrackingMethod == FULL_TRACKING` |\n|---------------------------------------|-----------------------------|-------------------------------------------------------------------|\n\n| **Note:** If an image in the camera view changes very rapidly to a second image that has roughly the same size and position, ARCore may erroneously set the [`TrackingMethod`](/ar/reference/java/com/google/ar/core/AugmentedImage.TrackingMethod) to `FULL_TRACKING` for both images and also update the anchor of the first Augmented Image to the position of the new image. For example, this could happen if you were pointing the camera at an image in a web browser, and then switched to another browser tab containing a second similarly sized and positioned image.\n\nSee also\n--------\n\n- The Augmented Images [sample projects](https://github.com/google-ar/arcore-android-sdk/tree/master/samples)\n in the ARCore SDK.\n\n- The [ARCore Augmented Images codelab](https://codelabs.developers.google.com/codelabs/augimg-intro)."]]