如何获得Frame()。相机ARCore

问题描述 投票:0回答:1

我试图将一个锚直接放在距离相机1米远的地方。

我发现了一个代码来实现这个目标。

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

我的代码如下所示:

val anchor =Session(this).createAnchor(
Frame().camera.pose.compose(Pose.makeTranslation(0f,0f,-1f)))

问题是Frame()构造函数。编译器带有错误:

“无法访问'':它受到保护/保护,并且在框架中打包/'

有没有办法初始化Frame()。相机或我做错了什么?

android kotlin arcore
1个回答
0
投票

你没有初始化框架。你从会话中得到它

你是这样做的

@覆盖

  public void onDrawFrame(GL10 gl) {

    // Clear screen to notify driver it should not load any pixels from previous frame.

    GLES20.glClear(GLES20.GL_COLOR_BUFFER_BIT | GLES20.GL_DEPTH_BUFFER_BIT);



    if (session == null) {

      return;

    }

    // Notify ARCore session that the view size changed so that the perspective matrix and

    // the video background can be properly adjusted.

    displayRotationHelper.updateSessionIfNeeded(session);



    try {

      session.setCameraTextureName(backgroundRenderer.getTextureId());



      // Obtain the current frame from ARSession. When the configuration is set to

      // UpdateMode.BLOCKING (it is by default), this will throttle the rendering to the

      // camera framerate.

      Frame frame = session.update();
    } catch (Throwable t) {

      // Avoid crashing the application due to unhandled exceptions.

      Log.e(TAG, "Exception on the OpenGL thread", t);

    }
}
© www.soinside.com 2019 - 2024. All rights reserved.