PhotoCaptureFrame.cs 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. /****************************************************************************
  2. * Copyright 2019 Nreal Techonology Limited. All rights reserved.
  3. *
  4. * This file is part of NRSDK.
  5. *
  6. * https://www.nreal.ai/
  7. *
  8. *****************************************************************************/
  9. namespace NRKernal.Record
  10. {
  11. using System;
  12. using System.Collections.Generic;
  13. using UnityEngine;
  14. /// <summary> Contains information captured from the web camera. </summary>
  15. public sealed class PhotoCaptureFrame : IDisposable
  16. {
  17. /// <summary> The data. </summary>
  18. private byte[] data;
  19. /// <summary> Constructor. </summary>
  20. /// <param name="format"> Describes the format to use.</param>
  21. /// <param name="data"> The data.</param>
  22. public PhotoCaptureFrame(CapturePixelFormat format, byte[] data)
  23. {
  24. this.data = data;
  25. this.pixelFormat = format;
  26. }
  27. /// <summary> Finalizer. </summary>
  28. ~PhotoCaptureFrame()
  29. {
  30. }
  31. /// <summary> The length of the raw IMFMediaBuffer which contains the image captured. </summary>
  32. /// <value> The length of the data. </value>
  33. public int dataLength { get; }
  34. /// <summary> Specifies whether or not spatial data was captured. </summary>
  35. /// <value> True if this object has location data, false if not. </value>
  36. public bool hasLocationData { get; }
  37. /// <summary> The raw image data pixel format. </summary>
  38. /// <value> The pixel format. </value>
  39. public CapturePixelFormat pixelFormat { get; }
  40. /// <summary> Copies the raw image data into buffer described by byteBuffer. </summary>
  41. /// <param name="byteBuffer"> Buffer for byte data.</param>
  42. public void CopyRawImageDataIntoBuffer(List<byte> byteBuffer)
  43. {
  44. }
  45. /// <summary> Disposes the PhotoCaptureFrame and any resources it uses. </summary>
  46. public void Dispose()
  47. {
  48. }
  49. /// <summary>
  50. /// Provides a COM pointer to the native IMFMediaBuffer that contains the image data. </summary>
  51. /// <returns> A native COM pointer to the IMFMediaBuffer which contains the image data. </returns>
  52. public IntPtr GetUnsafePointerToBuffer()
  53. {
  54. return IntPtr.Zero;
  55. }
  56. /// <summary> Attempts to get camera to world matrix. </summary>
  57. /// <param name="cameraToWorldMatrix"> [out] The camera to world matrix.</param>
  58. /// <returns> True if it succeeds, false if it fails. </returns>
  59. public bool TryGetCameraToWorldMatrix(out Matrix4x4 cameraToWorldMatrix)
  60. {
  61. cameraToWorldMatrix = Matrix4x4.identity;
  62. return true;
  63. }
  64. /// <summary> Attempts to get projection matrix. </summary>
  65. /// <param name="projectionMatrix"> [out] The projection matrix.</param>
  66. /// <returns> True if it succeeds, false if it fails. </returns>
  67. public bool TryGetProjectionMatrix(out Matrix4x4 projectionMatrix)
  68. {
  69. projectionMatrix = Matrix4x4.identity;
  70. return true;
  71. }
  72. /// <summary> Attempts to get projection matrix. </summary>
  73. /// <param name="nearClipPlane"> The near clip plane.</param>
  74. /// <param name="farClipPlane"> The far clip plane.</param>
  75. /// <param name="projectionMatrix"> [out] The projection matrix.</param>
  76. /// <returns> True if it succeeds, false if it fails. </returns>
  77. public bool TryGetProjectionMatrix(float nearClipPlane, float farClipPlane, out Matrix4x4 projectionMatrix)
  78. {
  79. projectionMatrix = Matrix4x4.identity;
  80. return true;
  81. }
  82. /// <summary>
  83. /// This method will copy the captured image data into a user supplied texture for use in Unity. </summary>
  84. /// <param name="targetTexture"> The target texture that the captured image data will be copied to.</param>
  85. public void UploadImageDataToTexture(Texture2D targetTexture)
  86. {
  87. if (data == null)
  88. {
  89. return;
  90. }
  91. ImageConversion.LoadImage(targetTexture, data);
  92. }
  93. }
  94. }