Created
December 4, 2018 08:52
-
-
Save ashikns/21b93ebe94454fd1d85ed33415fe21e2 to your computer and use it in GitHub Desktop.
Accessing D400 camera data on UWP
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| private async void Media() | |
| { | |
| var groups = await MediaFrameSourceGroup.FindAllAsync(); | |
| foreach (var group in groups) | |
| { | |
| Debug.WriteLine(group.DisplayName); | |
| } | |
| var selectedGroup = groups.First(); | |
| var name = selectedGroup.DisplayName; | |
| Debug.WriteLine($"Selected {name}"); | |
| var settings = new MediaCaptureInitializationSettings { SourceGroup = selectedGroup }; | |
| var mediaCapture = new MediaCapture(); | |
| await mediaCapture.InitializeAsync(settings); | |
| foreach (var source in mediaCapture.FrameSources) | |
| { | |
| Debug.WriteLine(source.Key); | |
| var intrinsics = source.Value.TryGetCameraIntrinsics(source.Value.CurrentFormat); | |
| Debug.WriteLine(intrinsics?.ImageWidth); | |
| } | |
| var videoDevice = mediaCapture.VideoDeviceController; | |
| var depthXu = new Guid(0xC9606CCB, 0x594C, 0x4D25, 0xaf, 0x47, 0xcc, 0xc4, 0x96, 0x43, 0x59, 0x95); | |
| var DS5_HWMONITOR = 1; | |
| var propString = $"{{{depthXu.ToString()}}} {DS5_HWMONITOR}"; | |
| uint calibrationTableInt = 21; | |
| uint rgbCalibrationId = 32; | |
| uint opCodeXmit = calibrationTableInt; | |
| ushort IVCAM_MONITOR_MAGIC_NUMBER = 0xcdab; | |
| var usbCommandBuffer = new byte[1024]; | |
| int usbCommandLength = 0; | |
| var headerSize = 4; | |
| var writeIndex = 2; | |
| var segment = BitConverter.GetBytes(IVCAM_MONITOR_MAGIC_NUMBER); | |
| Debug.Assert(segment.Length == sizeof(ushort)); | |
| Array.Copy(segment, 0, usbCommandBuffer, writeIndex, segment.Length); | |
| writeIndex += segment.Length; | |
| segment = BitConverter.GetBytes(opCodeXmit); | |
| Debug.Assert(segment.Length == sizeof(uint)); | |
| Array.Copy(segment, 0, usbCommandBuffer, writeIndex, segment.Length); | |
| writeIndex += segment.Length; | |
| segment = BitConverter.GetBytes(0); | |
| for (int i = 0; i < 4; i++) | |
| { | |
| Debug.Assert(segment.Length == sizeof(uint)); | |
| Array.Copy(segment, 0, usbCommandBuffer, writeIndex, segment.Length); | |
| writeIndex += segment.Length; | |
| } | |
| usbCommandLength = writeIndex; | |
| ushort commandSize = (ushort)(usbCommandLength - headerSize); | |
| var lengthSegment = BitConverter.GetBytes(commandSize); | |
| Debug.Assert(lengthSegment.Length == sizeof(ushort)); | |
| Array.Copy(lengthSegment, 0, usbCommandBuffer, 0, lengthSegment.Length); | |
| videoDevice.SetDeviceProperty(propString, usbCommandBuffer); | |
| Debug.WriteLine("End"); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment