InputFrame.cs 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  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. private int width;
  14. private int height;
  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 int getWidth() {
  32. return width;
  33. }
  34. public int getHeight() {
  35. return height;
  36. }
  37. public Int16 getDepthAt(int x, int y) {
  38. return depthData[y * width + x];
  39. }
  40. public Int16 getConfidenceAt(int x, int y) {
  41. return confidenceData[y * width + x];
  42. }
  43. public float getUAt(int x, int y)
  44. {
  45. return uvData[2 * (y * width + x) + 0];
  46. }
  47. public float getVAt(int x, int y)
  48. {
  49. return uvData[2 * (y * width + x) + 1];
  50. }
  51. public Color getColorAt(int x, int y) {
  52. float u = getUAt(x, y);
  53. float v = getVAt(x, y);
  54. if (u < 0 || v < 0)
  55. return Color.Black;
  56. int xInColorImage = (int)(u * widthRawColor) % widthRawColor;
  57. int yInColorImage = (int)(v * heightRawColor) % heightRawColor;
  58. return getRawColorAt(x,y);
  59. }
  60. public Color getRawColorAt(int x, int y) {
  61. int offset = 4 * (y * widthRawColor + x);
  62. byte alpha = rawColorData[offset + 3];
  63. byte red = rawColorData[offset + 2];
  64. byte green = rawColorData[offset + 1];
  65. byte blue = rawColorData[offset + 0];
  66. return Color.FromArgb(alpha, red, green, blue);
  67. }
  68. }
  69. }