Arcore-android-sdk: Can i place a anchor of the object in air instead of plane in ar-core android?

Created on 4 Jan 2018  路  14Comments  路  Source: google-ar/arcore-android-sdk

How to place a anchor of the object in air instead of placing plane(instead of anchoring object in tables and other horizontal planes?

question

Most helpful comment

You can create an anchor at any Pose. Getting a pose "in the air" probably means doing something relative to the current camera pose, or offsetting the pose returned by a hit test.

For the later, if for example you wanted to place anchors 20cm above the hit point, you could replace

mAnchors.add(hit.createAnchor());

with

mAnchors.add(hit.getTrackable().createAnchor(
    hit.getPose().compose(Pose.makeTranslation(0, 0.2f, 0))));

If instead you wanted to place an anchor straight in front of the camera 1m away, you would do:

mAnchors.add(session.createAnchor(
    frame.getCamera().getPose()
        .compose(Pose.makeTranslation(0, 0, -1f))
        .extractTranslation()))

The extractTranslation() results in the anchor being oriented to world space instead of matching the camera.

Getting a position a fixed distance away from a tapped point is a bit more complex and involves back-projecting through the projection matrix. If you want help with that try StackOverflow.

All 14 comments

You can create an anchor at any Pose. Getting a pose "in the air" probably means doing something relative to the current camera pose, or offsetting the pose returned by a hit test.

For the later, if for example you wanted to place anchors 20cm above the hit point, you could replace

mAnchors.add(hit.createAnchor());

with

mAnchors.add(hit.getTrackable().createAnchor(
    hit.getPose().compose(Pose.makeTranslation(0, 0.2f, 0))));

If instead you wanted to place an anchor straight in front of the camera 1m away, you would do:

mAnchors.add(session.createAnchor(
    frame.getCamera().getPose()
        .compose(Pose.makeTranslation(0, 0, -1f))
        .extractTranslation()))

The extractTranslation() results in the anchor being oriented to world space instead of matching the camera.

Getting a position a fixed distance away from a tapped point is a bit more complex and involves back-projecting through the projection matrix. If you want help with that try StackOverflow.

Thank you so much.

I did with

Pose mCameraRelativePose=Pose.makeTranslation(0.0f, 0.0f, -0.5f);

mSession.createAnchor(mCameraRelativePose)

above code placed anchor at center position is it correct?

That would place the anchor at an arbitrary point in space, 50cm from the origin (which has no specified location) and offset in a random horizontal direction.

By our current behavior, that object would be 50cm horizontally in front of the initial device location, but that could change in the future. If you want to do this, create an anchor as soon as you have a valid pose and position things relative to that.

Thank you for your response.

is it possible to create object 50 from the straight of the hit location in plane

Hi @inio, have this approach changed since 1.0 ?

mAnchors.add(session.createAnchor(
    frame.getCamera().getPose()
        .compose(Pose.makeTranslation(0, 0, -1f))
        .extractTranslation()))

I'm trying to create object in front of the wall and nothing's happening, there is no points to attach to.

@izdi getPose() should now be getDisplayOrientedPose() but otherwise that should work.

When I try to tap in front of the wall where no points around nothings happening. The log message is hit_test.cc:360 generic::internal: No point hit.

Does it mean that this approach won't work and you still need a point or plane to create anchor for objects? Otherwise it has not enough features to track.

Wait, are you using hitTest, or placing camera-relative? This thread is about placing objects relative to the camera without doing a hit test. If you're using hitTest , you'll need some feature points in the vicinity of where you want the tap anchor to be created.

OK, looks like I understand the issue now. I was doing it inside of a hitTest loop, switched to handle on a tap and when tracking state is active and looks like it worked. However sometimes models disappear right after adding to world.
Thanks for clarifying @inio !

Not related to the thread.
Is there any documentation I could read about how feature points calculated? I would like to know what type of environment a user should be in in order to successfully run the AR app if i'm trying to attach my objects not to the plain, but a bottle on a table or toothbrush etc. Does this make any sense?

Sorry I didn't get to this earlier:

Feature points are based on areas of high and unique visual contrast. White walls/tabletops and flat-colored carpet are bad. More dramatically textured surfaces (wood, brick, tile patterns) as well as shadow edges produce features.

The easiest way is to just get a sense for it by playing with it. HelloAR visualizes the debug point cloud, which lets you get a sense of where ARCore finds features.

@inio if I want to detect the only table surface, not floor surface so what I want to do?

        var anchor = hitResult.createAnchor()
        var anchorNode = AnchorNode(anchor)
        anchorNode.setParent(arFragment.arSceneView.scene)
        var transformableNode =TransformableNode(arFragment.transformationSystem)
        transformableNode.setParent(anchorNode)
        transformableNode.setRenderable(andyRenderable)
        transformableNode.localPosition = Vector3(0f,0f,0f)
        transformableNode.select()

please give me some solution

hi, can we do this in ARCore2.0? how can i use the API?

Do the solutions above work for Cloud Anchors as well?

Was this page helpful?
0 / 5 - 0 ratings