using System; using System.Collections.Generic; using System.Drawing; using System.Linq; using System.Text; using System.Threading.Tasks; using Emgu.CV; using Emgu.CV.Structure; namespace bbiwarg.InputProviders { class InputFrame { public int Width { get; private set; } public int Height { get; private set; } private int widthRawColor; private int heightRawColor; private Int16[] depthData; private Int16[] confidenceData; private float[] uvData; private byte[] rawColorData; public InputFrame(int width, int height, int widthRawColor, int heightRawColor, Int16[] depthData, Int16[] confidenceData, float[] uvData, byte[] rawColorData) { this.Width = width; this.Height = height; this.widthRawColor = widthRawColor; this.heightRawColor = heightRawColor; this.depthData = depthData; this.confidenceData = confidenceData; this.uvData = uvData; this.rawColorData = rawColorData; } public Int16 getDepthAt(int x, int y) { return depthData[y * Width + x]; } public Int16 getConfidenceAt(int x, int y) { return confidenceData[y * Width + x]; } public float getUAt(int x, int y) { return uvData[2 * (y * Width + x) + 0]; } public float getVAt(int x, int y) { return uvData[2 * (y * Width + x) + 1]; } public Color getColorAt(int x, int y) { float u = getUAt(x, y); float v = getVAt(x, y); if (u < 0 || v < 0) return Color.Black; int xInColorImage = (int)(u * widthRawColor) % widthRawColor; int yInColorImage = (int)(v * heightRawColor) % heightRawColor; return getRawColorAt(x, y); } public Color getRawColorAt(int x, int y) { int offset = 4 * (y * widthRawColor + x); byte alpha = rawColorData[offset + 3]; byte red = rawColorData[offset + 2]; byte green = rawColorData[offset + 1]; byte blue = rawColorData[offset + 0]; return Color.FromArgb(alpha, red, green, blue); } } }