简体   繁体   English

如何在ARCore中使用SurfaceView获取相机的Pose

[英]How to use SurfaceView in ARCore to get the Pose of the camera

I'm trying to create a camera application which saves the camera position along with each image captured.我正在尝试创建一个相机应用程序,它保存相机 position 以及拍摄的每张图像。 I'm new to Android Studio and ARCore.我是 Android Studio 和 ARCore 的新手。

I created a camera app using Android Studio tutorial, then tried to use the Pose class inside the app.我使用 Android Studio 教程创建了一个相机应用程序,然后尝试在应用程序中使用 Pose class。 But it gives me an error saying that it requires and OpenGL context.但它给了我一个错误,说它需要和 OpenGL 上下文。 I then realized that I have to use SurfaceView instead of PreviewView for Pose to work.然后我意识到我必须使用 SurfaceView 而不是 PreviewView 才能使 Pose 工作。 But I don't get how to use it properly even after reading the documentation.但是即使阅读了文档,我也不知道如何正确使用它。 Please help me out.请帮帮我。

I've found an example demonstrating ARCore texture's reading app that implements GLSurfaceView and its renderer.我找到了一个演示 ARCore 纹理读取应用程序的示例,该应用程序实现GLSurfaceView及其渲染器。 Due to the fact that the code takes almost 300 lines, I'm posting a link to it.由于代码将近 300 行,我发布了一个链接

class MainActivity extends AppCompatActivity implements GLSurfaceView.Renderer {

    private GLSurfaceView surfaceView;
    private Session session;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        surfaceView = (GLSurfaceView) findViewById(R.id.surfaceview);

        // some code...

        surfaceView.setRenderer(this);
        surfaceView.setRenderMode(GLSurfaceView.RENDERMODE_CONTINUOUSLY);
    }

    @Override
    protected void onResume() {
        super.onResume();

        if (session == null) {
            if (!CameraPermissionHelper.hasCameraPermission(this)) {
                CameraPermissionHelper.requestCameraPermission(this);
                return;
            }
            session = new Session(/* some context= */ this);
        }
    }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM