private void OnFrameCaptured(HoloLensCamera sender, CameraFrame frame) { Debug.Log($"Frame captured:\n Resolution: {frame.Resolution.Width}x{frame.Resolution.Height}\n PixelFormat: {frame.PixelFormat}\n Exposure: {frame.Exposure}\n Gain: {frame.Gain}\n Frame Time: {frame.FrameTime}\n\n"); #if CAN_USE_UWP_TYPES // this will save the image to the CameraRoll folder, so it needs to have the appropriate priviledges. //string filename = Windows.Storage.KnownFolders.CameraRoll.Path + "\\image." + System.DateTime.Now.ToString("yy.MM.dd.HH.mm.ss.f") + ".jpg"; //frame.Save(filename); if (GrabFrame) { GrabFrame = false; SoftwareBitmap softwareBitmap = frame.SoftwareBitmap; if (softwareBitmap != null) { VideoFrame = VideoFrame.CreateWithSoftwareBitmap(softwareBitmap); ++frameIndex; } } #endif frame.Release(); }
private void CameraInitialized(HoloLensCamera sender, bool initializeSuccessful) { DebugLog("HoloLensCamera initialized"); StreamDescription streamDesc = sender.StreamSelector.Select(StreamCompare.EqualTo, 1280, 720).StreamDescriptions[0]; sender.Start(streamDesc); }
private Task SetupCameraAsync() { lock (lockObj) { #if UNITY_EDITOR UnityCompositorInterface.StartArUcoMarkerDetector(_markerDictionaryName, _markerSize); return(Task.CompletedTask); #else if (setupCameraTask != null) { DebugLog("Returning existing setup camera task"); return(setupCameraTask); } DebugLog("Setting up HoloLensCamera"); if (_holoLensCamera == null) { _holoLensCamera = new HoloLensCamera(CaptureMode.SingleLowLatency, PixelFormat.BGRA8); _holoLensCamera.OnCameraInitialized += CameraInitialized; _holoLensCamera.OnCameraStarted += CameraStarted; _holoLensCamera.OnFrameCaptured += FrameCaptured; } return(setupCameraTask = _holoLensCamera.Initialize()); #endif } }
private Task CleanUpCameraAsync() { lock (lockObj) { #if UNITY_EDITOR UnityCompositorInterface.StopArUcoMarkerDetector(); #else if (setupCameraTask == null) { DebugLog("CleanupCameraAsync was called when no start task had been created."); return(Task.CompletedTask); } DebugLog("Cleaning up HoloLensCamera"); if (_holoLensCamera != null) { _holoLensCamera.Dispose(); _holoLensCamera.OnCameraInitialized -= CameraInitialized; _holoLensCamera.OnCameraStarted -= CameraStarted; _holoLensCamera.OnFrameCaptured -= FrameCaptured; _holoLensCamera = null; } setupCameraTask = null; #endif } return(Task.CompletedTask); }
private Task CleanUpCameraAsync() { lock (lockObj) { if (setupCameraTask == null) { DebugLog("CleanupCameraAsync was called when no start task had been created."); return(Task.CompletedTask); } DebugLog("Cleaning up HoloLensCamera"); if (_holoLensCamera != null) { _holoLensCamera.Dispose(); _holoLensCamera.OnCameraInitialized -= CameraInitialized; _holoLensCamera.OnCameraStarted -= CameraStarted; _holoLensCamera.OnFrameCaptured -= FrameCaptured; _holoLensCamera = null; } setupCameraTask = null; } return(Task.CompletedTask); }
void Start() { pvCamera = new HoloLensCamera(CaptureMode.SingleLowLatency); pvCamera.OnCameraInitialized += OnCameraInitialized; pvCamera.OnFrameCaptured += OnFrameCaptured; pvCamera.KeepSoftwareBitmap = true; pvCamera.Initialize(); }
private void CameraStarted(HoloLensCamera sender, bool startSuccessful) { if (startSuccessful) { DebugLog("HoloLensCamera successfully started"); } else { Debug.LogError("Error: HoloLensCamera failed to start"); } }
private void CleanUpCamera() { DebugLog("Cleaning up HoloLensCamera"); if (_holoLensCamera != null) { _holoLensCamera.Dispose(); _holoLensCamera.OnCameraInitialized -= CameraInitialized; _holoLensCamera.OnCameraStarted -= CameraStarted; _holoLensCamera.OnFrameCaptured -= FrameCaptured; _holoLensCamera = null; } }
private void OnCameraInitialized(HoloLensCamera sender, bool initializeSuccessful) { // choose the first video with 720p resolution StreamDescription streamDesc = pvCamera.StreamSelector.Select(StreamCompare.EqualTo, 1280, 720).StreamDescriptions[0]; Debug.Log($"Selecting {streamDesc.Resolution.Width}x{streamDesc.Resolution.Height}@{streamDesc.Resolution.Framerate}fps"); // initialized, but not running pvCamera.Start(streamDesc); Debug.Log("Starting camera"); startCamera = true; }
private async void SetupCamera() { DebugLog("Setting up HoloLensCamera"); if (_holoLensCamera == null) { _holoLensCamera = new HoloLensCamera(CaptureMode.SingleLowLatency, PixelFormat.BGRA8); } _holoLensCamera.OnCameraInitialized += CameraInitialized; _holoLensCamera.OnCameraStarted += CameraStarted; _holoLensCamera.OnFrameCaptured += FrameCaptured; await _holoLensCamera.Initialize(); }
private void FrameCaptured(HoloLensCamera sender, CameraFrame frame) { #if UNITY_WSA DebugLog("Image obtained from HoloLens"); if (_api != null && _api.IsInitialized) { var pixelFormat = frame.PixelFormat; var imageWidth = frame.Resolution.Width; var imageHeight = frame.Resolution.Height; var imageData = frame.PixelData; var intrinsics = frame.Intrinsics; var extrinsics = frame.Extrinsics; var dictionary = _api.ProcessImage(imageData, imageWidth, imageHeight, pixelFormat, intrinsics, extrinsics); if (_markerObservations != null) { foreach (var markerPair in dictionary) { if (!_markerObservations.ContainsKey(markerPair.Key)) { _markerObservations.Add(markerPair.Key, new List <Marker>()); } _markerObservations[markerPair.Key].Add(markerPair.Value); if (_markerObservations[markerPair.Key].Count > _detectionCompletionStrategy.MaximumMarkerSampleCount) { _markerObservations[markerPair.Key].RemoveAt(0); } } var validMarkers = new Dictionary <int, Marker>(); foreach (var observationPair in _markerObservations) { Marker completedMarker; if (_detectionCompletionStrategy.TryCompleteDetection(observationPair.Value, out completedMarker)) { validMarkers[completedMarker.Id] = completedMarker; observationPair.Value.Clear(); } } _nextMarkerUpdate = validMarkers; } } #endif }
private void FrameCaptured(HoloLensCamera sender, CameraFrame frame) { #if UNITY_WSA DebugLog("Image obtained from HoloLens"); if (_api != null && _api.IsInitialized) { var pixelFormat = frame.PixelFormat; var imageWidth = frame.Resolution.Width; var imageHeight = frame.Resolution.Height; var imageData = frame.PixelData; var intrinsics = frame.Intrinsics; var extrinsics = frame.Extrinsics; var dictionary = _api.ProcessImage(imageData, imageWidth, imageHeight, pixelFormat, intrinsics, extrinsics); ProcessMarkersFromFrame(dictionary); } #endif }
private Task SetupCameraAsync() { lock (lockObj) { if (setupCameraTask != null) { DebugLog("Returning existing setup camera task"); return(setupCameraTask); } DebugLog("Setting up HoloLensCamera"); if (_holoLensCamera == null) { _holoLensCamera = new HoloLensCamera(CaptureMode.SingleLowLatency, PixelFormat.BGRA8); _holoLensCamera.OnCameraInitialized += CameraInitialized; _holoLensCamera.OnCameraStarted += CameraStarted; _holoLensCamera.OnFrameCaptured += FrameCaptured; } return(setupCameraTask = _holoLensCamera.Initialize()); } }