Click here to Skip to main content
15,868,016 members
Articles / Desktop Programming / WPF

Kinect Reception

Rate me:
Please Sign up or sign in to vote.
4.94/5 (34 votes)
12 Jan 2012Ms-PL5 min read 67.8K   2K   80  
TV Screen in the Reception, When nothing happens (no one is in the reception) we can display videos on the screen but when someone enters the frame show him the Kinect Image, and if the user is doing something funny, capture his image and save it.
using System;
using System.Linq;
using System.Windows.Controls;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using Microsoft.Research.Kinect.Nui;
using System.Windows;

namespace KinectReception.Controls
{
    /// <summary>
    /// Interaction logic for VitruvianManControl.xaml
    /// </summary>
    public partial class VitruvianManControl : UserControl
    {
        private readonly SolidColorBrush _fill = new SolidColorBrush(Colors.Red);
        private readonly SolidColorBrush _defaultfill = new SolidColorBrush(Colors.Yellow);

        private readonly RepeatBehavior _r = new RepeatBehavior(int.MaxValue);
        private readonly Duration _duration = new Duration(new TimeSpan(0, 0, 0, 1));
        private DoubleAnimation _da;

        public VitruvianManControl()
        {
            this.InitializeComponent();
            _defaultfill.Opacity = 0.5;
            ClearnHighlight();
            
        }

        public void HighlightJoint(JointID sourceJoint)
        {
            ClearnHighlight();
            SetHighlight(sourceJoint);
        }

        public void HighlightJoint(JointID sourceJoint, JointID targetJoint)
        {
            ClearnHighlight();
            SetHighlight(sourceJoint);
            SetHighlight(targetJoint);
        }

        private void SetHighlight(JointID joint)
        {
            switch (joint)
            {
                case JointID.AnkleLeft: HighlightGrid(AnkleLeft); break;
                case JointID.AnkleRight: HighlightGrid(AnkleRight); break;
                case JointID.ElbowLeft:HighlightGrid(ElbowLeft); break;
                case JointID.ElbowRight:HighlightGrid(ElbowRight); break;
                case JointID.FootLeft:HighlightGrid(FootLeft); break;
                case JointID.FootRight:HighlightGrid(FootRight); break;
                case JointID.HandLeft:HighlightGrid(HandLeft); break;
                case JointID.HandRight: HighlightGrid(HandRight); break;
                case JointID.Head:HighlightGrid(Head); break;
                case JointID.HipCenter: HighlightGrid(HipCenter); break;
                case JointID.HipLeft: HighlightGrid(HipLeft); break;
                case JointID.HipRight: HighlightGrid(HipRight); break;
                case JointID.KneeLeft: HighlightGrid(KneeLeft); break;
                case JointID.KneeRight: HighlightGrid(KneeRight); break;
                case JointID.ShoulderCenter: HighlightGrid(ShoulderCenter); break;
                case JointID.ShoulderLeft: HighlightGrid(ShoulderLeft); break;
                case JointID.ShoulderRight: HighlightGrid(ShoulderRight); break;
                case JointID.Spine: HighlightGrid(Spine); break;
                case JointID.WristLeft: HighlightGrid(WristLeft); break;
                case JointID.WristRight: HighlightGrid(WristRight); break;
            }
        }

        void HighlightGrid(Grid grid)
        {
            var eli = grid.Children.OfType<Ellipse>().Single();
            eli.Fill = _fill;

            foreach (var rect in grid.Children.OfType<Rectangle>())
            {
                rect.Visibility = Visibility.Visible;
            }

            Blink(eli);
        }

        void Blink(UIElement ui)
        {
            _da = new DoubleAnimation(1, 0.5, _duration) { RepeatBehavior = _r };
            ui.BeginAnimation(UIElement.OpacityProperty, _da);
        }

        private void ClearnHighlight()
        {
            foreach (var grid in Joints.Children.OfType<Grid>())
            {
                var eli = grid.Children.OfType<Ellipse>().Single();
                eli.BeginAnimation(UIElement.OpacityProperty, null);
                eli.Fill = _defaultfill;

                foreach (var rect in grid.Children.OfType<Rectangle>())
                {
                    rect.Visibility = Visibility.Hidden;
                }
            }
        }
    }
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Microsoft Public License (Ms-PL)


Written By
Architect Sela
Israel Israel
Shai Raiten is VS ALM MVP, currently working for Sela Group as a ALM senior consultant and trainer specializes in Microsoft technologies especially Team System and .NET technology. He is currently consulting in various enterprises in Israel, planning and analysis Load and performance problems using Team System, building Team System customizations and adjusts ALM processes for enterprises. Shai is known as one of the top Team System experts in Israel. He conducts lectures and workshops for developers\QA and enterprises who want to specialize in Team System.

My Blog: http://blogs.microsoft.co.il/blogs/shair/

Comments and Discussions