如何实例化 ARSCNView

How to instantiate an ARSCNView

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

我做错了什么?

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 运行ning 的代码片段是这样的:

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);
}