private HoloPicture RestoreHologram(string path) { var picture = HoloPicture.RestoreHologram(path); picture.DisplayPredictions(); return(picture); }
/// <summary> /// Serializes the current object with predictions /// </summary> /// <param name="predictions"></param> private void SaveHologram(HoloPicture picture) { picture.SaveHologram(captureNum++); }
private void OnFrameSampleAcquired(VideoCaptureSample sample) #endif { lock (sync) { if (processingFrame) { return; } processingFrame = true; } // surrounded with try/finally because we need to dispose of the sample try { // Allocate byteBuffer if (latestImageBytes == null || latestImageBytes.Length < sample.dataLength) { latestImageBytes = new byte[sample.dataLength]; } // Fill frame struct SampleStruct s = new SampleStruct(); sample.CopyRawImageDataIntoBuffer(latestImageBytes); s.data = latestImageBytes; // Get the cameraToWorldMatrix and projectionMatrix if (!sample.TryGetCameraToWorldMatrix(out s.camera2WorldMatrix) || !sample.TryGetProjectionMatrix(out s.projectionMatrix)) { return; } HoloPicture picture = null; UnityEngine.WSA.Application.InvokeOnAppThread(() => { picture = HoloPicture.CreateHologram(s.data, _resolution, s.camera2WorldMatrix, s.projectionMatrix); }, true); videoCapture.StopVideoModeAsync(onVideoModeStopped); IList <Yolo.YoloBoundingBox> predictions = null; #if UNITY_WSA && !UNITY_EDITOR VideoFrame videoFrame = (VideoFrame)videoFrameInfo.GetValue(sample); if (videoFrame?.SoftwareBitmap == null) { return; } SoftwareBitmap softwareBitmap = videoFrame.SoftwareBitmap; if (softwareBitmap.BitmapAlphaMode != BitmapAlphaMode.Premultiplied) { softwareBitmap = SoftwareBitmap.Convert(softwareBitmap, BitmapPixelFormat.Bgra8, BitmapAlphaMode.Premultiplied); videoFrame = VideoFrame.CreateWithSoftwareBitmap(softwareBitmap); } predictions = await ObjectDetector.Instance.AnalyzeImage(videoFrame); if (predictions?.Count == 0) { return; } #endif UnityEngine.WSA.Application.InvokeOnAppThread(() => { picture.Predictions = predictions; SaveHologram(picture); picture.DisplayPredictions(); }, true); } finally { sample.Dispose(); } }