I have a sample ARCore code where I am attaching Anchor to every new trackable i detect. I don't understand the utility of attaching these Anchors and also what is the need of attaching multiple Anchors to a single Trackable.
I have already checked out the documentation. I cant find much explaination.
Collection<AugmentedImage> updatedAugmentedImages =
frame.getUpdatedTrackables(AugmentedImage.class);
// Iterate to update augmentedImageMap, remove elements we cannot draw.
for (AugmentedImage augmentedImage : updatedAugmentedImages) {
switch (augmentedImage.getTrackingState()) {
case PAUSED:
// When an image is in PAUSED state, but the camera is not PAUSED, it has been detected,
// but not yet tracked.
String text = String.format("Detected Image %d", augmentedImage.getIndex());
messageSnackbarHelper.showMessage(this, text);
break;
case TRACKING:
// Have to switch to UI Thread to update View.
this.runOnUiThread(
new Runnable() {
@Override
public void run() {
fitToScanView.setVisibility(View.GONE);
}
});
// Create a new anchor for newly found images.
if (!augmentedImageMap.containsKey(augmentedImage.getIndex())) {
Anchor centerPoseAnchor = augmentedImage.createAnchor(augmentedImage.getCenterPose());
augmentedImageMap.put(
augmentedImage.getIndex(), Pair.create(augmentedImage, centerPoseAnchor));
}
... Hi Parul,
Anchors maps the real world with augmented world and let you see the model in a specific position. In fact an Anchor is a point of contact between virtual content and the sensor acquired content.
I'll try to explain this concept better:
When you put a 3d model somewhere you need to define the position (x,y,z) and the orientation of the model according to an origin. You know where the origin is because you are creating this world implicitly. Every time you move your phone and ArCore is running, the phone store some information about your movement using sensor (e.g. Camera,Gyro,Accellerometer,...) creating an in-memory representation of the space around you (typically a sparse point cloud).
How can I say that a point into my virtual world is the same point present into this new space generate by the phone? I use anchor.
In your example this point is the point of the reference Image detected by a computer vision algorithm. Placing an Anchor on it assume that the virtual world where you place augmented content have a reference to that real point and this content appears in the correct position when you move the phone.
Anchors will be update every frame by ArCore according to your movement allow the content to be more realistic according to the real world.
what is the need of attaching multiple anchors to a single trackable.
Usually you attack multiple Anchors to a trackable to have more reference points and to let ArCore reduce the error between virtual world position and space.
It's not necessary to create a new Anchor for every object. It's a good tip to use the same anchor for models with some sort of spacial relationship, assuming also that these objects aren't too far. Remember also that use and create an Anchor has a cost in term of used resources by your phone. This can lead to a performance loss in your App that will ruin user experience.
Hope this helps.
Cheers.
You could also reference to this article:
https://developers.google.com/ar/develop/developer-guides/anchors
Also be sure to check Visual Inertial Odometry and SLAM if you wanna know more about the processes behind these kind of techniques. Just google to know more.