/**********************************la fonction du skeletons*************************************************************/

        private Point getDisplayPosition(Joint joint)
        {
            float depthX, depthY;
            _nui.SkeletonEngine.SkeletonToDepthImage(joint.Position, out depthX, out depthY);
            depthX = Math.Max(0, Math.Min(depthX * 320, 320));
            depthY = Math.Max(0, Math.Min(depthY * 240, 240));
            int colorX, colorY;
            ImageViewArea iv = new ImageViewArea();
            _nui.NuiCamera.GetColorPixelCoordinatesFromDepthPixel(ImageResolution.Resolution640x480, iv, (int)depthX, (int)depthY, (short)0, out colorX, out colorY);
            return new Point((int)(skeleton.Width * colorX / 640.0), (int)(skeleton.Height * colorY / 480));
        }
        // Receives the RAW depthX and Y (no the 320x240 one)
        private Point getDisplayPosition(float depthX, float depthY)
        {
            // Convert to 320, 240 space
            depthX = depthX * 320;
            depthY = depthY * 240;
            int           colorX, colorY;
            ImageViewArea iv = new ImageViewArea();

            // Only ImageResolution.Resolution640x480 is supported at this point
            nui.NuiCamera.GetColorPixelCoordinatesFromDepthPixel(ImageResolution.Resolution640x480, iv, (int)depthX, (int)depthY, (short)0, out colorX, out colorY);

            // Map back to skeletonCanvas.Width & skeletonCanvas.Height
            return(new Point((int)(skeletonCanvas.Width * colorX / 640.0), (int)(skeletonCanvas.Height * colorY / 480)));
        }
        // Receives the just the depth pixel index
        private Point getColorMatrixPosition(int depthIndex)
        {
            // Convert to 320, 240 space
            float         depthX = depthIndex % 320;
            float         depthY = depthIndex / 320;
            int           colorX, colorY;
            ImageViewArea iv = new ImageViewArea();

            // Only ImageResolution.Resolution640x480 is supported at this point
            nui.NuiCamera.GetColorPixelCoordinatesFromDepthPixel(ImageResolution.Resolution640x480, iv, (int)depthX, (int)depthY, (short)0, out colorX, out colorY);

            // Map back to skeletonCanvas.Width & skeletonCanvas.Height
            return(new Point((int)(colorX), (int)(colorY)));
        }
Example #4
0
        private static Point getDiplayPosition(Microsoft.Research.Kinect.Nui.Vector Position, Microsoft.Research.Kinect.Nui.Runtime nui, Canvas skeleton)
        {
            float depthX, depthY;
            nui.SkeletonEngine.SkeletonToDepthImage(Position, out depthX, out depthY);
            depthX = depthX * 320; //convert to 320, 240 space
            depthY = depthY * 240; //convert to 320, 240 space
            int colorX, colorY;
            ImageViewArea iv = new ImageViewArea();
            // only ImageResolution.Resolution640x480 is supported at this point
            nui.NuiCamera.GetColorPixelCoordinatesFromDepthPixel(ImageResolution.Resolution640x480, iv, (int)depthX, (int)depthY, (short)0, out colorX, out colorY);

            // map back to skeleton.Width & skeleton.Height
            return new Point((int)(skeleton.Width * colorX / 640.0), (int)(skeleton.Height * colorY / 480));
        }
Example #5
0
        private Point getDisplayPosition(Joint joint)
        {
            float depthX, depthY;
            myRuntime.SkeletonEngine.SkeletonToDepthImage(joint.Position, out depthX, out depthY);
            depthX = depthX * 320; //convert to 320, 240 space
            depthY = depthY * 240; //convert to 320, 240 space
            int colorX, colorY;
            ImageViewArea iv = new ImageViewArea();
            // only ImageResolution.Resolution640x480 is supported at this point
            myRuntime.NuiCamera.GetColorPixelCoordinatesFromDepthPixel(ImageResolution.Resolution640x480, iv, (int)depthX, (int)depthY, (short)0, out colorX, out colorY);

            // map back to skeleton.Width & skeleton.Height
            return new Point((int)(preview.Width * colorX / 640.0), (int)(preview.Height * colorY / 480));
        }
Example #6
0
        private static Point GetDisplayPosition(Runtime nui, Joint joint, int width, int height)
        {
            float depthX, depthY;
            nui.SkeletonEngine.SkeletonToDepthImage(joint.Position, out depthX, out depthY);
            depthX = depthX*320; //convert to 320, 240 space
            depthY = depthY*240; //convert to 320, 240 space
            int colorX, colorY;
            var iv = new ImageViewArea();
            // only ImageResolution.Resolution640x480 is supported at this point
            nui.NuiCamera.GetColorPixelCoordinatesFromDepthPixel(ImageResolution.Resolution640x480, iv, (int) depthX,
                                                                 (int) depthY, 0, out colorX, out colorY);

            // map back to skeleton.Width & skeleton.Height
            return new Point((int) (width*colorX/640.0), (height*colorY/480));
        }
        private Point getPointPosition(Joint joint)
        {
            float depthX, depthY;

            runtime.SkeletonEngine.SkeletonToDepthImage(joint.Position, out depthX, out depthY);
            depthX = depthX * 320;
            depthY = depthY * 240;
            int           colorX, colorY;
            ImageViewArea iv = new ImageViewArea();

            runtime.NuiCamera.GetColorPixelCoordinatesFromDepthPixel(ImageResolution.Resolution640x480, iv, (int)depthX, (int)depthY, (short)0, out colorX, out colorY);

            // map back to skeleton.Width & skeleton.Height
            return(new Point((int)(skeleton.Width * colorX / 640.0), (int)(skeleton.Height * colorY / 480)));
        }
Example #8
0
        private Point getDisplayPosition(Joint joint)
        {
            float depthX, depthY;

            nui.SkeletonEngine.SkeletonToDepthImage(joint.Position, out depthX, out depthY);
            depthX = Math.Max(0, Math.Min(depthX * 320, 320));  //convert to 320, 240 space
            depthY = Math.Max(0, Math.Min(depthY * 240, 240));  //convert to 320, 240 space
            int           colorX, colorY;
            ImageViewArea iv = new ImageViewArea();

            // only ImageResolution.Resolution640x480 is supported at this point
            nui.NuiCamera.GetColorPixelCoordinatesFromDepthPixel(ImageResolution.Resolution640x480, iv, (int)depthX, (int)depthY, (short)0, out colorX, out colorY);

            // map back to skeleton.Width & skeleton.Height
            return(new Point((int)(skeleton.Width * colorX / 640.0), (int)(skeleton.Height * colorY / 480)));
        }
        private Point getDisplayPosition(Microsoft.Research.Kinect.Nui.Vector mainPoint)
        {
            float depthX, depthY;

            nui.SkeletonEngine.SkeletonToDepthImage(mainPoint, out depthX, out depthY);
            // Convert to 320, 240 space
            depthX = depthX * 320; // MICHI: WATCH OUT HERE!!!! this are the depth X/Y coordinates first in the 0-1 interval
            depthY = depthY * 240;
            int           colorX, colorY;
            ImageViewArea iv = new ImageViewArea();

            // Only ImageResolution.Resolution640x480 is supported at this point
            nui.NuiCamera.GetColorPixelCoordinatesFromDepthPixel(ImageResolution.Resolution640x480, iv, (int)depthX, (int)depthY, (short)0, out colorX, out colorY);

            // Map back to skeletonCanvas.Width & skeletonCanvas.Height
            return(new Point((int)(skeletonCanvas.Width * colorX / 640.0), (int)(skeletonCanvas.Height * colorY / 480)));
        }
        //Maps a circle to a joint position
        public void SetJointPosition(ref Runtime nui, FrameworkElement ellipse, Joint incJoint)
        {
            float depthX, depthY;

            nui.SkeletonEngine.SkeletonToDepthImage(incJoint.Position, out depthX, out depthY);
            depthX = Math.Max(0, Math.Min(depthX * (float)mVideoX, (float)mVideoX));  //convert to 320, 240 space
            depthY = Math.Max(0, Math.Min(depthY * (float)mVideoY, (float)mVideoY));  //convert to 320, 240 space

            int           colorX, colorY;
            ImageViewArea iv = new ImageViewArea();

            // only ImageResolution.Resolution640x480 is supported at this point
            nui.NuiCamera.GetColorPixelCoordinatesFromDepthPixel(ImageResolution.Resolution640x480, iv, (int)depthX, (int)depthY, (short)0, out colorX, out colorY);

            Canvas.SetLeft(ellipse, (int)(320 * colorX / 640.0) - ellipse.Width / 2);
            Canvas.SetTop(ellipse, (int)(240 * colorY / 480) - ellipse.Width / 2);
        }
        private Point getDisplayPosition(Joint joint)
        {
            float depthX, depthY;
            Point newPoint = new Point(); ;
            nuiRuntime.SkeletonEngine.SkeletonToDepthImage(joint.Position, out depthX, out depthY);
            depthX = Math.Max(0, Math.Min(depthX * 320, 320));  //convert to 320, 240 space
            depthY = Math.Max(0, Math.Min(depthY * 240, 240));  //convert to 320, 240 space
            int colorX, colorY;
            ImageViewArea iv = new ImageViewArea();
            // only ImageResolution.Resolution640x480 is supported at this point
            nuiRuntime.NuiCamera.GetColorPixelCoordinatesFromDepthPixel(ImageResolution.Resolution640x480, iv, (int)depthX, (int)depthY, (short)0, out colorX, out colorY);

            newPoint = new Point((int)(skeletonToForm.Width * colorX / 640.0), (int)(skeletonToForm.Height * colorY / 480));

            return newPoint;
        }
Example #12
0
        public static Point getDisplayPosition(Runtime tr,Joint joint, int width,int height)
        {
            float depthX, depthY;
            tr.SkeletonEngine.SkeletonToDepthImage(joint.Position, out depthX, out depthY);
            depthX = Math.Max(0, Math.Min(depthX * 320, 320));  //convert to 320, 240 space
            depthY = Math.Max(0, Math.Min(depthY * 240, 240));  //convert to 320, 240 space
            int colorX, colorY;
            ImageViewArea iv = new ImageViewArea();
            // only ImageResolution.Resolution640x480 is supported at this point
            tr.NuiCamera.GetColorPixelCoordinatesFromDepthPixel(ImageResolution.Resolution640x480, iv, (int)depthX, (int)depthY, (short)0, out colorX, out colorY);

            // map back to skeleton.Width & skeleton.Height
            return new Point((int)(width * colorX / 640.0), (int)(height * colorY / 480));
        }
Example #13
0
        public bool Init()
        {
            _kinectruntime = Runtime.Kinects[0];

            _viewarea = new ImageViewArea();
            _viewarea.CenterX = 0;
            _viewarea.CenterY = 0;

            _kinectruntime.DepthFrameReady +=
                new EventHandler<ImageFrameReadyEventArgs>(KinectruntimeDepthFrameReady);
            _kinectruntime.VideoFrameReady +=
                new EventHandler<ImageFrameReadyEventArgs>(KinectruntimeVideoFrameReady);

            try
            {
                if (SettingsManager.KinectSet.KinectMode == EKinectMode.Depth)
                {
                    _kinectruntime.Initialize(RuntimeOptions.UseColor | RuntimeOptions.UseDepth);
                }
                else
                {
                    _kinectruntime.Initialize(RuntimeOptions.UseDepthAndPlayerIndex | RuntimeOptions.UseColor);
                }

                if (SettingsManager.KinectSet.KinectMode == EKinectMode.Depth)
                {
                    _kinectruntime.VideoStream.Open(ImageStreamType.Video, 2, SettingsManager.KinectSet.VideoResolution, ImageType.Color);
                    _kinectruntime.DepthStream.Open(ImageStreamType.Depth, 2, SettingsManager.KinectSet.DepthResolution, ImageType.Depth);
                }
                else
                {
                    _kinectruntime.DepthStream.Open(ImageStreamType.Depth, 2, SettingsManager.KinectSet.DepthResolution, ImageType.DepthAndPlayerIndex);
                }
            }
            catch
            {
                return false;
            }

            return true;
        }
Example #14
0
        static Point GetDisplayPosition(double totalWidth, double totalHeight, Joint joint)
        {
            float depthX, depthY;
            runtime.SkeletonEngine.SkeletonToDepthImage(joint.Position,
                out depthX, out depthY);
            depthX = Math.Max(Zero, Math.Min(depthX * ThreeTwenty, ThreeTwenty));
            depthY = Math.Max(Zero, Math.Min(depthY * TwoForty, TwoForty));

            int colorX, colorY;
            ImageViewArea iv = new ImageViewArea();
            // only ImageResolution.Resolution640x480 is supported at this point
            runtime.NuiCamera.GetColorPixelCoordinatesFromDepthPixel(
                ImageResolution.Resolution640x480, iv, (int)depthX, (int)depthY,
                (short)0, out colorX, out colorY);

            return new Point((int)(totalWidth * colorX / SixForty),
                (int)(totalHeight * colorY / FourEighty));
        }
        private System.Windows.Point getDisplayPosition(Joint joint)
        {
            float depthX, depthY;
            nui.SkeletonEngine.SkeletonToDepthImage(joint.Position, out depthX, out depthY);
            depthX = Math.Max(0, Math.Min(depthX * 320, 320));  //convert to 320, 240 space
            depthY = Math.Max(0, Math.Min(depthY * 240, 240));  //convert to 320, 240 space
            int colorX, colorY;
            ImageViewArea iv = new ImageViewArea();
            // only ImageResolution.Resolution640x480 is supported at this point
            nui.NuiCamera.GetColorPixelCoordinatesFromDepthPixel(ImageResolution.Resolution640x480, iv, (int)depthX, (int)depthY, (short)0, out colorX, out colorY);

            // map back to skeleton.Width & skeleton.Height
            return new System.Windows.Point((int)(cvsSkeleton.Width * colorX / 640.0), (int)((cvsSkeleton.Height * colorY / 480) - 30));
        }
Example #16
0
        private Point getPointPosition(Joint joint)
        {
            float depthX, depthY;
            runtime.SkeletonEngine.SkeletonToDepthImage(joint.Position, out depthX, out depthY);
            depthX = depthX * 320;
            depthY = depthY * 240;
            int colorX, colorY;
            ImageViewArea iv = new ImageViewArea();
            runtime.NuiCamera.GetColorPixelCoordinatesFromDepthPixel(ImageResolution.Resolution640x480, iv, (int)depthX, (int)depthY, (short)0, out colorX, out colorY);

            // map back to skeleton.Width & skeleton.Height
            return new Point((int)(skeleton.Width * colorX / 640.0), (int)(skeleton.Height * colorY / 480));
        }
Example #17
0
        private Point getDisplayPosition(Joint j)
        {
            float depthX, depthY;
            MainWindow.Instance.NuiRuntime.SkeletonEngine.SkeletonToDepthImage(j.Position, out depthX, out depthY);

            depthX = depthX * 320; //convert to 320, 240 space
            depthY = depthY * 240; //convert to 320, 240 space
            int colorX, colorY;
            ImageViewArea iv = new ImageViewArea();
            // only ImageResolution.Resolution640x480 is supported at this point

            MainWindow.Instance.NuiRuntime.NuiCamera.GetColorPixelCoordinatesFromDepthPixel(ImageResolution.Resolution640x480, iv, (int)depthX, (int)depthY, (short)0, out colorX, out colorY);

            // map back to canvas1.Width & canvas1.Height
            //Console.WriteLine("main window width: " + MainWindow.Instance.canvas1.Width);
            //Console.WriteLine("main window height: " + MainWindow.Instance.canvas1.Height);

            return new Point((double)(MainWindow.Instance.canvas1.ActualWidth * colorX / 640.0), (double)(MainWindow.Instance.canvas1.ActualHeight * 1.2 * colorY / 480));
        }
        void nui_DepthFrameReady(object sender, ImageFrameReadyEventArgs e)
        {
            PlanarImage Image = e.ImageFrame.Image;
            ViewArea = e.ImageFrame.ViewArea;
            depthImage1 = Image;
            depth1Ready = true;
            byte[] convertedDepthFrame = convertDepthFrame(Image.Bits);

            depth.Source = BitmapSource.Create(
                Image.Width, Image.Height, 96, 96, PixelFormats.Bgr32, null, convertedDepthFrame, Image.Width * 4);

            ++totalFrames;

            DateTime cur = DateTime.Now;
            if (cur.Subtract(lastTime) > TimeSpan.FromSeconds(1))
            {
                int frameDiff = totalFrames - lastFrames;
                lastFrames = totalFrames;
                lastTime = cur;
                frameRate.Text = frameDiff.ToString() + " fps";
            }
        }
        // Converts a 16-bit grayscale depth frame which includes player indexes into a 32-bit frame
        // that displays different players in different colors
        byte[] convertDepthFrame(byte[] depthFrame16)
        {
            for (int i16 = 0, i32 = 0; i16 < depthFrame16.Length && i32 < depthFrame32.Length; i16 += 2, i32 += 4)
            {
                int player = depthFrame16[i16] & 0x07;
                int realDepth = (depthFrame16[i16+1] << 5) | (depthFrame16[i16] >> 3);
                // transform 13-bit depth information into an 8-bit intensity appropriate
                // for display (we disregard information in most significant bit)
                byte intensity = (byte)(255 - (255 * realDepth / 0x0fff));

                depthFrame32[i32 + RED_IDX] = 0;
                depthFrame32[i32 + GREEN_IDX] = 0;
                depthFrame32[i32 + BLUE_IDX] = 0;

                // choose different display colors based on player
                switch (player)
                {
                    case 0:
                        depthFrame32[i32 + RED_IDX] = (byte)(intensity / 2);
                        depthFrame32[i32 + GREEN_IDX] = (byte)(intensity / 2);
                        depthFrame32[i32 + BLUE_IDX] = (byte)(intensity / 2);
                        break;
                    case 1:
                        depthFrame32[i32 + RED_IDX] = intensity;
                        break;
                    case 2:
                        depthFrame32[i32 + GREEN_IDX] = intensity;
                        break;
                    case 3:
                        depthFrame32[i32 + RED_IDX] = (byte)(intensity / 4);
                        depthFrame32[i32 + GREEN_IDX] = (byte)(intensity);
                        depthFrame32[i32 + BLUE_IDX] = (byte)(intensity);
                        break;
                    case 4:
                        depthFrame32[i32 + RED_IDX] = (byte)(intensity);
                        depthFrame32[i32 + GREEN_IDX] = (byte)(intensity);
                        depthFrame32[i32 + BLUE_IDX] = (byte)(intensity / 4);
                        break;
                    case 5:
                        depthFrame32[i32 + RED_IDX] = (byte)(intensity);
                        depthFrame32[i32 + GREEN_IDX] = (byte)(intensity / 4);
                        depthFrame32[i32 + BLUE_IDX] = (byte)(intensity);
                        break;
                    case 6:
                        depthFrame32[i32 + RED_IDX] = (byte)(intensity / 2);
                        depthFrame32[i32 + GREEN_IDX] = (byte)(intensity / 2);
                        depthFrame32[i32 + BLUE_IDX] = (byte)(intensity);
                        break;
                    case 7:
                        depthFrame32[i32 + RED_IDX] = (byte)(255 - intensity);
                        depthFrame32[i32 + GREEN_IDX] = (byte)(255 - intensity);
                        depthFrame32[i32 + BLUE_IDX] = (byte)(255 - intensity);
                        break;
                }

                if (colorFrame != null && (i16 % 500 == 0))
                {
                    ImageViewArea iv = new ImageViewArea();

                    int depthX = i16 % 320;
                    int depthY = i16 / 320;
                    int colorX, colorY;
                    //depthX = Math.Max(0, Math.Min(depthX * 320, 320));  //convert to 320, 240 space
                    //depthY = Math.Max(0, Math.Min(depthY * 240, 240));  //convert to 320, 240 space

                    kinect1.NuiCamera.GetColorPixelCoordinatesFromDepthPixel(ImageResolution.Resolution640x480, iv, depthX, depthY, (short)realDepth, out colorX, out colorY);

                    int index = colorX + colorY * 320;
                    //System.Console.WriteLine(depthX + "," + depthY);
                    //depthFrame32[i32 + RED_IDX] = colorFrame[index + RED_IDX];
                    //depthFrame32[i32 + GREEN_IDX] = colorFrame[index + GREEN_IDX]; ;
                    //depthFrame32[i32 + BLUE_IDX] = colorFrame[index + BLUE_IDX]; ;

                }
            }
            return depthFrame32;
        }
Example #20
0
        //adapted from Kinect demo app, i.e. ShapeGame
        private Point getDisplayPosition(Joint joint)
        {
            float depthX, depthY;
            nui.SkeletonEngine.SkeletonToDepthImage(joint.Position, out depthX, out depthY);
            depthX = depthX * 320; //convert to 320, 240 space
            depthY = depthY * 240; //convert to 320, 240 space
            int colorX, colorY;
            ImageViewArea iv = new ImageViewArea();
            // only ImageResolution.Resolution640x480 is supported at this point
            nui.NuiCamera.GetColorPixelCoordinatesFromDepthPixel(ImageResolution.Resolution640x480, iv, (int)depthX, (int)depthY, (short)0, out colorX, out colorY);

            // map back to skeleton.Width & skeleton.Height
            Point p = new Point((int)(KinectScreenSize.X * colorX / 640.0), (int)(KinectScreenSize.Y * colorY / 480));
            debugMsg.WriteLine("getDisplayPosition=" + p, DebugMsg.getDisplayPosition);

            return p;
        }
Example #21
0
        /// <summary>
        /// Gets the display position (i.e. where in the display image) of a Joint
        /// </summary>
        /// <param name="joint">Kinect NUI Joint</param>
        /// <returns>Point mapped location of sent joint</returns>
        private Point GetDisplayPosition(Joint joint)
        {
            float depthX, depthY;
            _nui.SkeletonEngine.SkeletonToDepthImage(joint.Position, out depthX, out depthY);
            depthX = Math.Max(0, Math.Min(depthX * 320, 320)); // convert to 320, 240 space
            depthY = Math.Max(0, Math.Min(depthY * 240, 240)); // convert to 320, 240 space
            int colorX, colorY;
            var iv = new ImageViewArea();

            // Only ImageResolution.Resolution640x480 is supported at this point
            _nui.NuiCamera.GetColorPixelCoordinatesFromDepthPixel(ImageResolution.Resolution640x480, iv, (int)depthX, (int)depthY, 0, out colorX, out colorY);

            // Map back to skeleton.Width & skeleton.Height
            return new Point((int)(skeletonCanvas.Width * colorX / 640.0), (int)(skeletonCanvas.Height * colorY / 480));
        }
        /// <summary>
        /// Gets the display position (i.e. where in the display image) of a Joint
        /// </summary>
        /// <param name="joint">Kinect NUI Joint</param>
        /// <returns>Point mapped location of sent joint</returns>
        private System.Windows.Point GetDisplayPosition(Joint joint)
        {
            var nui = model_.Provider.Runtime;

            //return new System.Windows.Point((int)(skeletonCanvas.ActualWidth / 2 + joint.Position.X * skeletonCanvas.ActualWidth / 2),
            //    (int)(skeletonCanvas.ActualHeight / 2 + joint.Position.Y * skeletonCanvas.ActualHeight / 2));

            float depthX, depthY;
            nui.SkeletonEngine.SkeletonToDepthImage(joint.Position, out depthX, out depthY);
            depthX = Math.Max(0, Math.Min(depthX * 320, 320)); // convert to 320, 240 space
            depthY = Math.Max(0, Math.Min(depthY * 240, 240)); // convert to 320, 240 space
            int colorX, colorY;
            var iv = new ImageViewArea();

            // Only ImageResolution.Resolution640x480 is supported at this point
            nui.NuiCamera.GetColorPixelCoordinatesFromDepthPixel(ImageResolution.Resolution640x480, iv, (int)depthX, (int)depthY, 0, out colorX, out colorY);

            // Map back to skeleton.Width & skeleton.Height
            return new System.Windows.Point((int)(skeletonCanvas.ActualWidth * colorX / 640.0), (int)(skeletonCanvas.ActualHeight * colorY / 480));
        }
        private Point getDisplayPosition(Joint joint)
        {
            float depthX, depthY;
            nui.SkeletonEngine.SkeletonToDepthImage(joint.Position, out depthX, out depthY);
            depthX = Math.Max(0, Math.Min(depthX * 320, 320));  //convert to 320, 240 space
            depthY = Math.Max(0, Math.Min(depthY * 240, 240));  //convert to 320, 240 space
            int colorX, colorY;
            ImageViewArea iv = new ImageViewArea();
            // only ImageResolution.Resolution640x480 is supported at this point
            nui.NuiCamera.GetColorPixelCoordinatesFromDepthPixel(ImageResolution.Resolution640x480, iv, (int)depthX, (int)depthY, (short)0, out colorX, out colorY);

            // map back to skeleton.Width & skeleton.Height
            Point p = new Point((int)(skeleton.Width * colorX / 640.0), (int)(skeleton.Height * colorY / 480));
            if (p.X < 10 && p.Y < 10)
            {

                System.Diagnostics.Debug.WriteLine("Point: " + p.ToString());
            }
            return p;
        }
        private void Window_Loaded(object sender, EventArgs e)
        {
            nui = new Runtime();

            try
            {
                nui.Initialize(RuntimeOptions.UseDepthAndPlayerIndex | RuntimeOptions.UseSkeletalTracking | RuntimeOptions.UseColor);
            }
            catch (InvalidOperationException)
            {
                System.Windows.MessageBox.Show("Runtime initialization failed. Please make sure Kinect device is plugged in.");
                return;
            }

            try
            {
                nui.VideoStream.Open(ImageStreamType.Video, 2, ImageResolution.Resolution640x480, ImageType.Color);
                nui.DepthStream.Open(ImageStreamType.Depth, 2, ImageResolution.Resolution320x240, ImageType.DepthAndPlayerIndex);
            }
            catch (InvalidOperationException)
            {
                System.Windows.MessageBox.Show("Failed to open stream. Please make sure to specify a supported image type and resolution.");
                return;
            }

            lastTime = DateTime.Now;

            nui.SkeletonFrameReady += new EventHandler<SkeletonFrameReadyEventArgs>(nui_SkeletonFrameReady);
            nui.VideoFrameReady += new EventHandler<ImageFrameReadyEventArgs>(nui_ColorFrameReady);

            SkeletonDataAlternative.JointPositionConverter = new JointPositionConverter(delegate(Joint joint)
            {
                float depthX, depthY;
                nui.SkeletonEngine.SkeletonToDepthImage(joint.Position, out depthX, out depthY);
                ImageViewArea iv = new ImageViewArea();
                int colorX, colorY;
                nui.NuiCamera.GetColorPixelCoordinatesFromDepthPixel(ImageResolution.Resolution640x480, iv, (int)(depthX * 320), (int)(depthY * 240), (short)0, out colorX, out colorY);
                Microsoft.Research.Kinect.Nui.Vector converted = new Microsoft.Research.Kinect.Nui.Vector();
                converted.X = (float)colorX / 640.0f;
                converted.Y = (float)colorY / 480.0f;
                converted.Z = joint.Position.Z;
                converted.W = joint.Position.W;
                joint.Position = converted;
                return joint;
            });
        }