InputFrame.cs 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  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. this.Width = width;
  23. this.Height = height;
  24. this.widthRawColor = widthRawColor;
  25. this.heightRawColor = heightRawColor;
  26. this.depthData = depthData;
  27. this.confidenceData = confidenceData;
  28. this.uvData = uvData;
  29. this.rawColorData = rawColorData;
  30. }
  31. public Int16 getDepthAt(int x, int y) {
  32. return depthData[y * Width + x];
  33. }
  34. public Int16 getConfidenceAt(int x, int y) {
  35. return confidenceData[y * Width + x];
  36. }
  37. public float getUAt(int x, int y)
  38. {
  39. return uvData[2 * (y * Width + x) + 0];
  40. }
  41. public float getVAt(int x, int y)
  42. {
  43. return uvData[2 * (y * Width + x) + 1];
  44. }
  45. public Color getColorAt(int x, int y) {
  46. float u = getUAt(x, y);
  47. float v = getVAt(x, y);
  48. if (u < 0 || v < 0)
  49. return Color.Black;
  50. int xInColorImage = (int)(u * widthRawColor) % widthRawColor;
  51. int yInColorImage = (int)(v * heightRawColor) % heightRawColor;
  52. return getRawColorAt(x,y);
  53. }
  54. public Color getRawColorAt(int x, int y) {
  55. int offset = 4 * (y * widthRawColor + x);
  56. byte alpha = rawColorData[offset + 3];
  57. byte red = rawColorData[offset + 2];
  58. byte green = rawColorData[offset + 1];
  59. byte blue = rawColorData[offset + 0];
  60. return Color.FromArgb(alpha, red, green, blue);
  61. }
  62. }
  63. }