gpt4 book ai didi

ios - 如何实例化 ARSCNView

转载 作者:行者123 更新时间:2023-11-29 00:08:05 25 4
gpt4 key购买 nike

我想使用 ARKit 来计算当前视频帧中的环境光量。但是,在我检索当前帧时创建 ARSCNView 对象后,它返回空值。

我做错了什么?

public class EyeAlignmentUICameraPreview : UIView, IAVCaptureVideoDataOutputSampleBufferDelegate
{

void Initialize()
{
CaptureSession = new CaptureSession();
PreviewLayer = new AVCaptureVideoPreviewLayer(CaptureSession)
{
Frame = Bounds,
VideoGravity = AVLayerVideoGravity.ResizeAspectFill
};
var device = AVCaptureDevice.GetDefaultDevice(AVCaptureDeviceType.BuiltInTelephotoCamera, AVMediaType.Video, AVCaptureDevicePosition.Back);

ARSCNView SceneView = new ARSCNView();
// frame is null after this line is executed
var frame = SceneView.Session.CurrentFrame;
}
}

最佳答案

更新我的评论以回答更多详细信息。

ARFrame

A video image and position tracking information captured as part of an AR session.

currentFrame

The video frame image, with associated AR scene information, most recently captured by the session.

根据这些 Apple ARKit 文档,当 ARSession 获取视频和关联的 AR 场景信息时,currentFrame 将具有值。 因此,我们必须首先运行 session 。

运行 ARSession ,我们需要一个 session 配置:

Running a session requires a session configuration: an instance of the ARConfiguration class, or its subclass ARWorldTrackingConfiguration. These classes determine how ARKit tracks a device's position and motion relative to the real world, and thus affect the kinds of AR experiences you can create.

因此,ARSession运行的代码片段是这样的:

public override void ViewWillAppear(bool animated)
{
base.ViewWillAppear(animated);

//Create a session configuration
var configuration = new ARWorldTrackingConfiguration
{
PlaneDetection = ARPlaneDetection.Horizontal,
LightEstimationEnabled = true
};

// Run the view's session
SceneView.Session.Run(configuration, ARSessionRunOptions.ResetTracking);
}

关于ios - 如何实例化 ARSCNView,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47401727/

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