Exemplo n.º 1
0
        // Event for handling depth stream updates from the Kinect. Calls the finger update function
        private void SensorDepthFrameReady(object sender, DepthImageFrameReadyEventArgs e)
        {
            // "using" param ensures depth frame is disposed after use.
            using (DepthImageFrame depthFrame = e.OpenDepthImageFrame())
            {
                // Set depth frame parameters
                DFP.Bitmask = DepthImageFrame.PlayerIndexBitmaskWidth;
                DFP.Width   = depthFrame.Width;
                DFP.Height  = depthFrame.Height;

                #region DEBUG_HAND_OUTLINE
                depthFrame.CopyPixelDataTo(this.depthPixels);
                short[] tempDepth = new short[depthPixels.Length];

                depthFrame.CopyPixelDataTo(tempDepth);

                // Updates the hand position based on the kinematic data. Dampened by a multiple to reduce oscillation.
                //Hands[0].position_Pixels += 0.8 * Hands[0].elapsedMillis * Hands[0].velocity_Pixels;
                HandFrame HF = ProcessDepthImage.zoomOnHand(tempDepth, DFP, Hands[0]);

                IntPtr dataStartPtr = bmpData[0].Scan0;
                int    dataLength   = bmpData[0].Stride * bmpData[0].Height;

                // Print to debug left hand
                rgbValues = new byte[bmpData[0].Stride * bmpData[0].Height];
                for (int y = 1; y < HF.dx.GetLength(0); y++)
                {
                    for (int x = 1; x < HF.dy.GetLength(1); x++)
                    {
                        int dD = (byte)(Math.Sqrt(HF.dx[y, x] * HF.dx[y, x] + HF.dy[y, x] * HF.dy[y, x]));

                        int val = debugBitmapSizes[0].Width * (y + (debugBitmapSizes[0].Height - HF.dx.GetLength(0)) / 2) + x + (debugBitmapSizes[0].Width - HF.dx.GetLength(1)) / 2;
                        if (dD > 5 && x + (debugBitmapSizes[0].Width - HF.dx.GetLength(1)) / 2 > 0 && x + (debugBitmapSizes[0].Width - HF.dx.GetLength(1)) / 2 < debugBitmapSizes[0].Width && y + (debugBitmapSizes[0].Height - HF.dx.GetLength(0)) / 2 > 0 && y + (debugBitmapSizes[0].Height - HF.dx.GetLength(0)) / 2 < debugBitmapSizes[0].Height)
                        {
                            rgbValues[4 * val + 0] = 255;
                            rgbValues[4 * val + 1] = 255;
                            rgbValues[4 * val + 2] = 255;
                            rgbValues[4 * val + 3] = 255;
                        }
                    }
                }
                System.Runtime.InteropServices.Marshal.Copy(rgbValues, 0, dataStartPtr, dataLength);
                #endregion

                if (checkBox2.Checked)
                {
                    Hands[1].tracked = false;
                    foreach (ObjectPoint f in Hands[1].fingers)
                    {
                        f.tracked = false;
                    }
                }
                ProcessDepthImage.updateFingersFromDepth(depthPixels, DFP, Hands);
                this.FPScount++;
            }
        }
Exemplo n.º 2
0
        // Get the Thumb, Finger or Palm directors of a hand
        public Vector3 GetHandFrameVector(HandType hand, HandFrame vec)
        {
            var handTrans = GetHandTransform(hand, HandJoint.Wrist);

            return(handTrans.TransformDirection(HAND_FRAME_VECTORS[(int)hand, (int)vec]));
        }