public static void ConvertToColorImagePointArray(byte[] colorImage, ref ColorPoint[][] pointArray, int width, int height) { //ColorPoint[][] pointArray = new ColorPoint[height][]; for (int i = 0; i < height; i++) { //pointArray[i] = new ColorPoint[width]; for (int j = 0; j < width; j++) { ColorPoint point = new ColorPoint(); int index = (i * width + j) * 3; point.X = j; point.Y = i; point.color = Color.FromRgb(colorImage[index], colorImage[index + 1], colorImage[index + 2]); pointArray[i][j] = point; } } //return pointArray; }
public MainWindow() { InitializeComponent(); //SensorConnect connect = new SensorConnect(); //connect.ShowDialog(); while (!Sensor.EnumDevices()) { if (!MainWindow.ShowDialog("Please connect the Kinect device to the computer and try again.", "Device Connection Failed")) { Close(); break; } } if (Sensor.Status == SensorStatus.NotInitialized) { Close(); } if (!Sensor.EnableDevice()) { ShowMessageDialog("Error: Device could not be enabled.", "Error"); } if (Sensor.PixelDataLength > 0) { colorImage = new byte[Sensor.PixelDataLength]; colorPointArray = new ColorPoint[Sensor.Height][]; for (int i = 0; i < Sensor.Height; i++) { colorPointArray[i] = new ColorPoint[Sensor.Width]; } } else { ShowMessageDialog("Error: The program was unable to receive appropriate pixel data.", "Error"); } colorBitmap = new WriteableBitmap(Sensor.Width, Sensor.Height, 96.0, 96.0, PixelFormats.Bgr32, null); KinectColor.Source = colorBitmap; if (Sensor.DepthPixelDataLength > 0) { depthImage = new DepthImagePixel[Sensor.DepthPixelDataLength]; depthColorImage = new byte[Sensor.DepthPixelDataLength * sizeof(int)]; depthPointArray = new DepthImagePoint[Sensor.DepthHeight][]; for (int i = 0; i < Sensor.DepthHeight; i++) { depthPointArray[i] = new DepthImagePoint[Sensor.DepthWidth]; } skeletonColorImage = new byte[Sensor.DepthPixelDataLength * sizeof(int)]; } else { ShowMessageDialog("Error: The program was unable to receive appropriate pixel data.", "Error"); } depthBitmap = new WriteableBitmap(Sensor.DepthWidth, Sensor.DepthHeight, 96.0, 96.0, PixelFormats.Bgr32, null); KinectDepth.Source = depthBitmap; if (Sensor.SkeletonArrayLength > 0) { skelData = new Skeleton[Sensor.SkeletonArrayLength]; skeletonData = new List <SkeletonData>(); } else { ShowMessageDialog("Error: The program was unable to receive appropriate skeleton data.", "Error"); } skeletonBitmap = new WriteableBitmap(Sensor.DepthWidth, Sensor.DepthHeight, 96.0, 96.0, PixelFormats.Bgr32, null); KinectSkeleton.Source = skeletonBitmap; if (!Sensor.RegisterColorFrameReadyEvent(SensorColorFrameReady) || !Sensor.RegisterDepthFrameReadyEvent(SensorDepthFrameReady) || !Sensor.RegisterSkeletonFrameReadyEvent(SensorSkeletonFrameReady)) { ShowMessageDialog("Error: The program was unable to register the proper events to the Kinect sensor.", "Error"); } if (!Sensor.StartDevice()) { ShowMessageDialog("Error: The program was unable to start the Kinect sensor.", "Error"); } }