javaaugmented-realityarcore

ARCore – Session, Frame, Camera and Pose


I'm studying the ARCore References, Develop, make the course from Coursera, and read, understood and learn from the Samples.

But I still missing some definition with some real use examples.

What is a session? Every time that I need a ARCore use I need a session? Session always has a camera connect so I can see and draw/renderer my 3D models in the screen? Can I do this without a Session?

Camera has a getPose and Frame has a GetPose, what are the diferences between they?

I thought about make this questions split but somehow I know that they are all connected. Sessions, CameraAr, Frame and Pose.


Solution

  • Session

    A Session object is a real gateway in the Google ARCore API. Session manages AR system state and handles the scene's session lifecycle. Session class allows an AR developer to create a working session, configure it and run/stop it when necessary. Most importantly, Session object allows receive AR frames (that are spat out at 60 fps) which gives you a direct access to AR Camera's RGBD image and mobile device Pose which are updated every 16.6 ms.

    Before running a session with a required config, make sure that you have the actual version of ARCore and that chosen config is supported on your device. Keep in mind that the ARCore framework doesn't render 3D models (renderables) - for that you'll need a framework like deprecated Sceneform. I hope that Google will release a brand-new SceneCore library for traditional Android OS very soon (SceneCore currently works with Android XR only).

    ARCore 1.49 has fourteen configs with corresponding APIs that you can use in your AR app:

    Java code snippet:

    session = new Session(this);
    Config config = new Config(session);
    config.setDepthMode(Config.DepthMode.AUTOMATIC);
    
    if (!session.isSupported(config)) {
        showSnackbarMessage("Your device doesn't support this config", true);
    }
    session.configure(config);
    

    Pose

    A Pose class symbolizes the position and orientation of any 3D object in ARCore, like camera, light or a virtual glTF/glb model, within the world coordinate space. Pose represents an immutable rigid transformation from one coordinate space to another. As provided from all ARCore APIs, poses always describe the transformation from object's local coordinate space to the world coordinate space. The order of transformations is defined by a quaternion rotation about the origin followed by a translation.

    Java code snippet:

    float[] position = { 0, 0, -2.0 };    //   { x, y, z }    position 
    float[] rotation = { 0, 0, 0, 1 };    //   { x, y, z, w } quaternion rotation
    
    Session session = arFragment.getArSceneView().getSession();
    Anchor anchor = session.createAnchor(new Pose(position, rotation));
    

    Camera

    A Camera object provides information about the device camera that is used to capture images and additional info inside each AR frame. If the camera is part of an ArSceneView, then this camera does automatically track the Camera's pose from ARCore API. Note that the Camera is a long-lived object, so the properties of Camera are updated every time Session.update() method is called.

    Java code snippet:

    sharedSession = new Session(this, EnumSet.of(Session.Feature.SHARED_CAMERA))
    sharedCamera = sharedSession.getSharedCamera();
    cameraId = sharedSession.getCameraConfig().getCameraId();
    

    Frame

    In ARCore, a Frame object represents the state of the AR system at a specific point in time. Each AR Frame in a running session records a set of useful data that an AR developer urgently needs. Among this data, you'll find: camera's pose, info on detected planes, RGB image intrinsics, display orientation, tracking state, estimated lighting data, image metadata, updated list of anchors, a timestamp when an image was captured (in nsec), and, of course, hardware buffer contents.

    Java code snippet:

    private void onUpdateFrame(FrameTime frameTime) {
    
        private static final String TAG = "MyActivity";        
        Frame frame = arFragment.getArSceneView().getArFrame();
        Log.d(TAG, frame.getLightEstimate().getState().toString());
    }