如何获取Frame()。camera ARCore

时间:2019-04-03 17:06:35

标签: android kotlin arcore

我正在尝试将锚直接放在距离摄像机1m处的位置。

我找到了实现此目的的代码。

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()。camera或我做错了什么?

1 个答案:

答案 0 :(得分:0)

您不初始化框架。您正在从会话中获取它

您以这种方式进行操作

@Override

  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);

    }
}