ARCore——会话、框架、相机和姿势

ARCore – Session, Frame, Camera and Pose

我正在研究 ARCore References, Develop, make the course from Coursera, and read, understood and learn from the Samples

但我仍然缺少一些实际使用示例的定义。

什么是会话?每次我需要使用 ARCore 时我都需要一个会话? Session 总是有一个摄像头连接,所以我可以在屏幕上看到和 draw/renderer 我的 3D 模型?我可以在没有会话的情况下执行此操作吗?

Camera有getPose,Frame有GetPose,它们有什么区别?

我曾想过将这些问题分开,但不知何故我知道它们都是相互关联的。会话、CameraAr、框架和姿势。

关于ArSession

ArSession is the most crucial element in AR puzzle. Session manages AR system state and handles the session lifecycle. Session class is the main entry point to the ARCore API. This class allows the user to create a session, configure it, start or stop it and, most importantly, receive ArFrames that allow access to ARCamera image and device Pose.

In order to use ARCore you need an ArSession. ARCore doesn't render 3D models (Renderables). This job is for Sceneform framework.

代码示例:

private Session mSession;
Config config = new Config(mSession);

if (!mSession.isSupported(config)) {
    showSnackbarMessage("This phone doesn't support AR", true);
}
mSession.configure(config);

Session 的配置也可以包含嵌套的 类:

  • Config.AugmentedFaceMode(Select是 Augmented Faces 子系统的行为)
  • Config.CloudAnchorModeConfig中的云锚模式)
  • Config.FocusMode(Select 是 camera focus 子系统所需的行为)
  • Config.LightEstimationMode(Select lighting estimation 子系统的行为)
  • Config.PlaneFindingMode(Select plane detection 子系统的行为)
  • Config.UpdateMode(Select是update()的行为)

关于姿势

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 transformation is defined using a quaternion rotation about the origin followed by a translation.

代码示例:

float[] position = { 0, 0, -2.2 };      //  { x, y, z } position 
float[] rotation = { 0, 0, 0, 1 };      //  { x, y, z, w } quaternion rotation

Session session = arFragment.getArSceneView().getSession();
Anchor myAnchor = session.createAnchor(new Pose(position, rotation));

关于 ArCamera

ArCamera represents a virtual camera, which determines the perspective through which the scene is viewed. If the camera is part of an ArSceneView, then the camera automatically tracks the Camera Pose from ARCore. ArCamera is a long-lived object and the properties of camera are updated every time Session.update() is called. Camera class provides information about the camera that is used to capture images and additional info inside each ArFrame.

代码示例:

// Shared camera access with ARCore

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

关于 ArFrame

When ARCore's understanding of the environment changes, it adjusts its model of the world to keep things consistent. When this happens, the numerical location (coordinates) of the ARCamera and ARAnchors can change significantly to maintain appropriate relative positions of the physical locations they represent.These changes mean that every ArFrame should be considered to be in a completely unique world coordinate space. The numerical coordinates of ARAnchors and the ARCamera should never be used outside the rendering frame during which they were retrieved.

Every ArFrame stores the following info about ARCore's state::

  • RGB 图像本身
  • 跟踪状态
  • 相机相对于世界的姿态
  • 估计的照明参数
  • 关于对象(如点云)更新的信息

代码示例:

private void onUpdateFrame(FrameTime frameTime) {

    Frame frame = arFragment.getArSceneView().getArFrame();

    // .............
}


此外,您还可以阅读 this useful post