InputFrame.cs 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Drawing;
  4. using System.Linq;
  5. using System.Text;
  6. using System.Threading.Tasks;
  7. using Emgu.CV;
  8. using Emgu.CV.Structure;
  9. namespace bbiwarg.InputProviders
  10. {
  11. class InputFrame
  12. {
  13. public int Width { get; private set; }
  14. public int Height { get; private set; }
  15. private int widthRawColor;
  16. private int heightRawColor;
  17. private Int16[] depthData;
  18. private Int16[] confidenceData;
  19. private float[] uvData;
  20. private byte[] rawColorData;
  21. public InputFrame(int width, int height, int widthRawColor, int heightRawColor, Int16[] depthData, Int16[] confidenceData, float[] uvData, byte[] rawColorData)
  22. {
  23. this.Width = width;
  24. this.Height = height;
  25. this.widthRawColor = widthRawColor;
  26. this.heightRawColor = heightRawColor;
  27. this.depthData = depthData;
  28. this.confidenceData = confidenceData;
  29. this.uvData = uvData;
  30. this.rawColorData = rawColorData;
  31. }
  32. public Int16 getDepthAt(int x, int y)
  33. {
  34. return depthData[y * Width + x];
  35. }
  36. public Int16 getConfidenceAt(int x, int y)
  37. {
  38. return confidenceData[y * Width + x];
  39. }
  40. public float getUAt(int x, int y)
  41. {
  42. return uvData[2 * (y * Width + x) + 0];
  43. }
  44. public float getVAt(int x, int y)
  45. {
  46. return uvData[2 * (y * Width + x) + 1];
  47. }
  48. public Color getColorAt(int x, int y)
  49. {
  50. float u = getUAt(x, y);
  51. float v = getVAt(x, y);
  52. if (u < 0 || v < 0)
  53. return Color.Black;
  54. int xInColorImage = (int)(u * widthRawColor) % widthRawColor;
  55. int yInColorImage = (int)(v * heightRawColor) % heightRawColor;
  56. return getRawColorAt(x, y);
  57. }
  58. public Color getRawColorAt(int x, int y)
  59. {
  60. int offset = 4 * (y * widthRawColor + x);
  61. byte alpha = rawColorData[offset + 3];
  62. byte red = rawColorData[offset + 2];
  63. byte green = rawColorData[offset + 1];
  64. byte blue = rawColorData[offset + 0];
  65. return Color.FromArgb(alpha, red, green, blue);
  66. }
  67. }
  68. }