public async Task Inititalize(IUnityScanScene unityApp) { UnityApp = unityApp; ModelHelper = new ONNXModelHelper(UnityApp); await ModelHelper.LoadModelAsync(); await InitializeCameraCapture(); await InitializeCameraFrameReader(); }
public async Task Inititalize(IUnityScanScene unityApp, string modelName = "", float accuracy = 0.5f) { UnityApp = unityApp; ModelHelper = new ONNXModelHelper(UnityApp); await ModelHelper.LoadModelAsync(modelName, accuracy); #if UNITY_WSA && !UNITY_EDITOR await InitializeCameraCapture(); await InitializeCameraFrameReader(); #endif }
public void StartPullCameraFrames() { System.Diagnostics.Debug.WriteLine("StartPullCameraFrames"); Task.Run(async() => { var ModelHelper = new ONNXModelHelper(UnityApp); System.Diagnostics.Debug.WriteLine("model inited"); for (; ;) // Forever = While the app runs { FramesCaptured++; await Task.Delay(PredictionFrequency); using (var frameReference = CameraFrameReader.TryAcquireLatestFrame()) using (var videoFrame = frameReference?.VideoMediaFrame?.GetVideoFrame()) { if (videoFrame == null) { System.Diagnostics.Debug.WriteLine("frame is null"); continue; //ignoring frame } if (videoFrame.Direct3DSurface == null) { System.Diagnostics.Debug.WriteLine("d3d surface is null"); videoFrame.Dispose(); continue; //ignoring frame } try { System.Diagnostics.Debug.WriteLine("trying to evaluate"); SpatialCoordinateSystem worldCoordinateSystem = m_referenceFrame.CoordinateSystem; Matrix4x4 cameraToWorld = (Matrix4x4)frameReference.CoordinateSystem.TryGetTransformTo(worldCoordinateSystem); CameraIntrinsics cameraIntrinsics = frameReference.VideoMediaFrame.CameraIntrinsics; DepthMediaFrame depthFrame = frameReference.VideoMediaFrame.DepthMediaFrame; await ModelHelper.EvaluateVideoFrameAsync(videoFrame, frameReference.VideoMediaFrame, worldCoordinateSystem, frameReference.CoordinateSystem).ConfigureAwait(false); } catch (Exception ex) { System.Diagnostics.Debug.WriteLine(ex.Message); } finally { } } } }); }