gpt4 book ai didi

java - ARCore—— session 、框架、相机和姿势

转载 作者:太空狗 更新时间:2023-10-29 13:03:41 25 4
gpt4 key购买 nike

我正在研究 ARCore References , Develop , 从 Coursera 制作类(class),并阅读、理解和学习 Samples .

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

什么是 session ?每次我需要使用 ARCore 时我都需要一个 session ? Session 始终连接相机,以便我可以在屏幕上查看和绘制/渲染我的 3D 模型?我可以在没有 session 的情况下执行此操作吗?

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

我考虑过将这些问题分开,但不知何故我知道它们都是相互关联的。 session 、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.

enter image description here

代码示例:

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(选择Augmented Faces 子系统的行为)
  • Config.CloudAnchorMode(Config中的云 anchor 模式)
  • Config.FocusMode(选择相机对焦子系统所需的行为)
  • Config.LightEstimationMode(选择光照估计子系统的行为)
  • Config.PlaneFindingMode(选择平面检测子系统的行为)
  • Config.UpdateMode(选择 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 .

关于java - ARCore—— session 、框架、相机和姿势,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51763412/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com