Example #1
0
 public HandFrameReadyEventArgs(DepthImage handImage)
 {
     HandImage = handImage;
 }
Example #2
0
        private void DrawHandImage(DepthImage handImage, Rectangle targetArea)
        {
            // Draw the hand
            var zoom = Math.Min(targetArea.Width / handImage.SourceRectangle.Width, targetArea.Height / handImage.SourceRectangle.Height);
            var position = new Vector2(targetArea.X + (targetArea.Width - zoom * handImage.SourceRectangle.Width) / 2, targetArea.Y + (targetArea.Height - zoom * handImage.SourceRectangle.Height) / 2);
            spriteBatch.Draw(handImage.Texture, position, handImage.SourceRectangle, Color.White, 0, Vector2.Zero, zoom, SpriteEffects.None, 0);

            // Draw the gesture points
            if (handImage == LeftHand)
            {
                position.X -= zoom * handImage.SourceRectangle.X;
                position.Y -= zoom * handImage.SourceRectangle.Y;
                foreach (var point in Contour)
                {
                    DrawHandPoint(point, position, zoom, Color.White);
                }
                foreach (var point in ConvexHull)
                {
                    DrawHandPoint(point, position, zoom, Color.Green);
                }
                foreach (var fingertip in Fingertips)
                {
                    DrawHandPoint(fingertip.Point, position, zoom, Color.Red/*, string.Format("[{0,4:F2}]", fingertip.Score)*/);
                }
                return;
            }
        }
Example #3
0
        private void IdentifyGestures(DepthImage hand)
        {
            var hull = hand.CalculateConvexHull();
            var contour = hand.CalculateContour();
            var fingertips = new List<FingertipCandidate>();

            // Only search for fingertips if we have a reasonable outline
            if (contour.Length > 64)
            {
                // Filter out the bad candidates and order the rest by score
                IEnumerable<FingertipCandidate> candidates = hull.Intersect(contour)
                                                                 .Select(p => new FingertipCandidate { Point = p, Score = ScoreCandidate(p, contour) })
                                                                 .Where(c => c.Score < Math.PI / 3)
                                                                 .OrderBy(c => c.Score);

                // Find the best five candidates, clearing out neighbours
                while (fingertips.Count <= 5 && candidates.Any())
                {
                    var fingertip = candidates.First();
                    fingertips.Add(fingertip);
                    candidates = candidates.Where(c => new Vector2(c.Point.X - fingertip.Point.X, c.Point.Y - fingertip.Point.Y).LengthSquared() > 18);
                }
            }

            // Update our gesture confidence
            if (fingertips.Count == FingerCount)
            {
                FingerConfidence++;
            }
            else
            {
                FingerConfidence = 0;
            }
            FingerCount = fingertips.Count;

            lock (GraphicsDevice)
            {
                ConvexHull = hull;
                Contour = contour;
                Fingertips = fingertips;
            }
        }
Example #4
0
        /// <summary>
        /// Allows the game to perform any initialization it needs to before starting to run.
        /// This is where it can query for any required services and load any non-graphic
        /// related content.  Calling base.Initialize will enumerate through any components
        /// and initialize them as well.
        /// </summary>
        protected override void Initialize()
        {
            base.Initialize();
            this.IsMouseVisible = true;

            // Sound
            sound = new DynamicSoundEffectInstance(SampleRate, Channels);
            sound.Play();

            // Images
            colorTexture = new Texture2D(graphics.GraphicsDevice, FrameWidth, FrameHeight);
            LeftHand = new DepthImage(graphics.GraphicsDevice, DepthFrameWidth, DepthFrameHeight);
            RightHand = new DepthImage(graphics.GraphicsDevice, DepthFrameWidth, DepthFrameHeight);

            // Gesture Recognition
            LeftHandTracker = new HandTracker();
            //Thread gestureThread = new Thread(new ThreadStart(IdentifyGestures));
            //gestureThread.Start();

            //Thread kinectThread = new Thread(new ThreadStart(StartKinect));
            //kinectThread.Start();
            StartKinect();
        }