Click here to Skip to main content
11,922,788 members (51,206 online)
Click here to Skip to main content
Add your own
alternative version


79 bookmarked

Kinect Reception

, 1 Sep 2011 Ms-PL
Rate this:
Please Sign up or sign in to vote.
TV Screen in the Reception, When nothing happens (no one is in the reception) we can display videos on the screen but when some one enters the frame show him the Kinect Image, and if the user doing something funny, capture his image and save it.
This is an old version of the currently published article.



The Idea: TV Screen in the Reception, When nothing happens (no one is in the reception) we can display videos on the screen but when some one enters the frame show him the Kinect Image, and if the user doing something funny, capture his image and save it.

The questions is how can I know if the person doing something funny?

For that I’ve created Image AuthenticManager, that contains a set of rules defining what positions or combinations are funny. 

For example: If Right Hand position is higher than Head position then add 2 points, if the Left Foot position is crossing the Right Foot then add additional 2 points etc.. 
When the user reaches the Goal we decide then Take his picture.

Before jumping to coding let’s talk about the application flow: 
The main window is controlled by two Timers and the AuthenticManager:

SeriousTimer set to 10 sec and it start to Ticking as the Kinect Skeleton Event is first fired(this event will only work when the Kinect identify a full person skeleton). 
Inside the SkeletonFrameReady we also have integer called _fpsCount that increase himself by 1 each time the SkeletonFrameReady is called after starting the SeriousTimer, this will help use to make sure the user is standing in front of the Kinect and not just walk by him. 

Now how can the _fbsCount will tell me that? all we need to do is multiply the SeriousTimer seconds interval by the Minimum Fps (for example 10) and the _fpsCount should be bigger is the user stand in front of the Kinect.

In this case the Timer will stop the Video feed and will display the Kinect Image.

IdleTimer by default is set to 30 seconds and each time the SkeletonFrameReady method is fired we restart the IdleTimer.

So if no events for SkeletonFrameReady the IdleTimer will return the Video feed. 

JointID - AuthenticManager works with RuleObject that contains JointID Source and JointID Target (More about Joints - Kinect – Getting Started – Become The Incredible Hulk). 

AuthenticManager is the heart of Kinect Reception application, this class will check if user position is funny by your own rules.


What is Joint?

The data is provided from the Kinect application code as a set of points, called skeleton positions, that compose a skeleton structure. 

public enum JointID
    HipCenter = 0,
    Spine = 1,
    ShoulderCenter = 2,
    Head = 3,
    ShoulderLeft = 4,
    ElbowLeft = 5,
    WristLeft = 6,
    HandLeft = 7,
    ShoulderRight = 8,
    ElbowRight = 9,
    WristRight = 10,
    HandRight = 11,
    HipLeft = 12,
    KneeLeft = 13,
    AnkleLeft = 14,
    FootLeft = 15,
    HipRight = 16,
    KneeRight = 17,
    AnkleRight = 18,
    FootRight = 19,
    Count = 20,

Vector - For Source and Target Joints you also have to define the Vector to check X or Y against one another.

Operator – Do you expect the Source Vector to be Bigger or Smaller than the Target Vector?

Score – If the rule is true what is the score for the rule. 



Since Microsoft has released the Kinect.NET SDK I wrote many articles on that subject:

I think Kinect it very cool and I’m searching for more projects and good ideas for Kinect, couple of days ago I talked with my friend Guy Burstein and he came with an idea for Kinect application, he said what if people will enter the Microsoft Israel reception and instead of video screen showing commercials lets add something interesting with Kinect. 

Using the code

Using Kinect events I can see when user enters the frame, using two timers I can check if the user is just passing  by or is standing in front of the camera.

The below image describe the application flow, at the beginning the application will show random videos, when the Kinect Skeleton Event will raise then the Serious Timer will begin ticking, each tick based on the FPS rate will be aggregate to variable called NumTicks, when the Serious Timer complete we check if NumTicks is big enough based on the FPS, if so then we’ll start the Idle Timer and switch to Kinect Image.

Idle Timer – Each time the Kinect Skeleton Event is raised the Idle Timer will be restart, so if there is no one in front of the Kinect camera the Idle Timer will switch back to Videos. 


As you can see from the images below (or Full Video), when I moved my hands or legs the Score Bar has changed based on the rules you defined: 




You reached the Goal!!! 


The entire application works with 4 managers:

  1. Kinect Manager
  2. Configuration Manager
  3. Video Manager
  4. Authentic Manager 

Kinect Manager

I’ve showed how to get started with Kinect many times in my previous posts but for this application I’ve created a singleton class to handle everything related to the Kinect settings, from restarting the Kinect RunTime object to changing the camera angle.
public KinectManager()

    KinectNui = new Runtime();

    KinectNui.Initialize(RuntimeOptions.UseColor | RuntimeOptions.UseSkeletalTracking |

    KinectNui.VideoStream.Open(ImageStreamType.Video, 2, ImageResolution.Resolution640x480, 

    KinectNui.SkeletonEngine.TransformSmooth = true;
    var parameters = new TransformSmoothParameters
                            Smoothing = 1.0f,
                            Correction = 0.1f,
                            Prediction = 0.1f,
                            JitterRadius = 0.05f,
                            MaxDeviationRadius = 0.05f
    KinectNui.SkeletonEngine.SmoothParameters = parameters;

    _lastTime = DateTime.Now;
    Camera = KinectNui.NuiCamera;

    IsInitialize = true;
    StatusMessage = Properties.Resources.KinectReady;
    catch (InvalidOperationException ex)
    IsInitialize = false;
    StatusMessage = ex.Message;
Another important method the KinectManager has is the CameraAngle control 

public void ChangeCameraAngle(ChangeDirection dir)
    if (!IsInitialize) return;

    if (dir == ChangeDirection.Up)
        Camera.ElevationAngle = Camera.ElevationAngle +
        Camera.ElevationAngle = Camera.ElevationAngle -

    StatusMessage = Properties.Resources.KinectReady;
    catch (InvalidOperationException ex)
    StatusMessage = ex.Message;
    catch (ArgumentOutOfRangeException outOfRangeException)
    StatusMessage = outOfRangeException.Message;

Video Manager 

The Video Manager has two specific types of Videos to play and the main Videos folders to pick random video each time.

Specific? When the user enters the Kinect Range you can choose to play a specific video just before the Kinect Image will appear, and when the user leaves Kinect Range you can choose to play the Out Video.

Define the type of video you want to play, If you ask for out video and there isn't one return null - Stop Video and start showing Kinect Image ,If you ask for in video and there isn't one then return random video. 


public static Uri GetVideo(VideoType type)
  if (string.IsNullOrEmpty(Properties.Settings.Default.VideosLibraryFolder) ||
      return null;
      string value = null;
      switch (type)
          case VideoType.In:
              value = Properties.Settings.Default.VideosLibraryInFile;
              return string.IsNullOrEmpty(value) || !File.Exists(value) ?
                  CollectRandomMovie() : new Uri(value);
          case VideoType.Out:
              value = Properties.Settings.Default.VideosLibraryOutFile;
              return string.IsNullOrEmpty(value) || !File.Exists(value) ?
                  null : new Uri(value);
              return CollectRandomMovie();
 private static Uri CollectRandomMovie()
    var movies = new ArrayList();

    foreach (var filter in Properties.Settings.Default.VideoFilter)

    if (movies.Count == 0) return null;

    var rnd = new Random();
    return new Uri(movies[rnd.Next(movies.Count)].ToString());

Configuration Manager 

Kinect Reception allows you to set a range or rules to define what is considered Funny, the rule are based on Joint to Joint and each rule define the Score if the rule applies. 


The RuleObject contains the Source Joint and Target Joint, Vector to check for both, the operator (Bigger or Smaller) and the Score.


So what the configuration manager does? it’s saves the rules. (Using MemoryStream to translate the Rule to string and then save them into the application resources.) 

public static ObservableCollection<RuleObject> Load()
    var deserializer = new XmlSerializer(typeof(ObservableCollection<RuleObject>));
        var xs = new XmlSerializer(typeof(ObservableCollection<RuleObject>));
        var memoryStream = new MemoryStream(Encoding.UTF8.GetBytes(Properties.Settings.Default.Rules));
        var xmlTextWriter = new XmlTextWriter(memoryStream, Encoding.UTF8);
        return (ObservableCollection<RuleObject>)xs.Deserialize(memoryStream);
    catch (Exception)
        return new ObservableCollection<RuleObject>();
public static void Save(ObservableCollection<RuleObject> items)
        var memoryStream = new MemoryStream();
        var xs = new XmlSerializer(typeof(ObservableCollection<RuleObject>));

        var xmlTextWriter = new XmlTextWriter(memoryStream, Encoding.UTF8);
        xs.Serialize(xmlTextWriter, items);

        memoryStream = (MemoryStream)xmlTextWriter.BaseStream;
        var xmlizedString = Encoding.UTF8.GetString(memoryStream.ToArray());

        Properties.Settings.Default.Rules = xmlizedString;
    catch (Exception ex)
        throw new ArgumentException(ex.Message);

Authentic Manager 

The Authentic Manager is the core of Kinect Reception, he will take all rules defined by you and check them against the Skeleton Joints.

The method below will extract the UnTracked joints and will make sure the joints quality are enough for calculation (We don’t want the user moving out of the picture to be considered as funny Sad smile)

If the Skeleton Joints reach the Goal Score you define then a event will raise telling the main window to save the current Image and display for the user. 

public void ChecksForAuthentic(JointsCollection joints)
  if (_rules.Count == 0) return;

  var fixJoints =
          joint => joint.Position.W >= 0.6f &&
              joint.TrackingState == JointTrackingState.Tracked).ToList();

  var sb = new StringBuilder();
  for (var index = 0; index < _rules.Count; index++)
    var rule = _rules[index];
    var s = (from j in fixJoints.Where(joint => joint.ID == rule.Source) select j).
        DefaultIfEmpty(new Joint() { TrackingState = JointTrackingState.NotTracked }).

    var t = (from j in fixJoints.Where(joint => joint.ID == rule.Target) select j).
        DefaultIfEmpty(new Joint() { TrackingState = JointTrackingState.NotTracked }).

    if (s.TrackingState == JointTrackingState.NotTracked ||
        t.TrackingState == JointTrackingState.NotTracked) break;

    var sv = s.ToFloat(rule.SourceVector);
    var tv = t.ToFloat(rule.TargetVector);

    if (rule.Operator == Operators.Bigger && sv > tv)
      Score = Score + rule.Score;
      sb.AppendLine(string.Format("Bigger -> Source: {0}, Target:{1} , Vector:{2}",
          rule.Source, rule.Target, rule.SourceVector));
    else if (rule.Operator == Operators.Smaller && sv < tv)
      Score = Score + rule.Score;
      sb.AppendLine(string.Format("Smaller -> Source: {0}, Target:{1} , Vector:{2}",
          rule.Source, rule.Target, rule.SourceVector));

  if (Score >= _goal)
    IsAuthentic(Score, sb.ToString());


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


About the Author

Shai Raiten
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:

You may also be interested in...

Comments and Discussions

Discussions posted for the Published version of this article. Posting a message here will take you to the publicly available article in order to continue your conversation in public.
QuestionVery good article! Pin
Volynsky Alex8-Jan-14 4:38
professionalVolynsky Alex8-Jan-14 4:38 
GeneralMy vote of 5 Pin
Edo Tzumer1-Jan-13 20:33
memberEdo Tzumer1-Jan-13 20:33 
GeneralMy vote of 5 Pin
ezekjh5-Mar-12 13:37
memberezekjh5-Mar-12 13:37 
GeneralRe: My vote of 5 Pin
Shai Raiten30-Sep-12 21:37
mvpShai Raiten30-Sep-12 21:37 
GeneralMy vote of 5 Pin
delibey22-Feb-12 13:23
memberdelibey22-Feb-12 13:23 
GeneralMy vote of 5 Pin
Sergio Andrés Gutiérrez Rojas12-Jan-12 8:27
memberSergio Andrés Gutiérrez Rojas12-Jan-12 8:27 
GeneralMy vote of 5 Pin
thatraja10-Jan-12 4:21
mvpthatraja10-Jan-12 4:21 
GeneralRe: My vote of 5 Pin
Shai Raiten12-Jan-12 3:48
mvpShai Raiten12-Jan-12 3:48 
GeneralMy vote of 5 Pin
tolw27-Oct-11 4:03
membertolw27-Oct-11 4:03 
GeneralRe: My vote of 5 Pin
Shai Raiten12-Jan-12 3:47
mvpShai Raiten12-Jan-12 3:47 
GeneralMy vote of 5 Pin
hadre8-Sep-11 0:34
memberhadre8-Sep-11 0:34 
GeneralRe: My vote of 5 Pin
Shai Raiten8-Sep-11 4:22
memberShai Raiten8-Sep-11 4:22 
GeneralWell Done Pin
DaveAuld5-Sep-11 23:42
mentorDaveAuld5-Sep-11 23:42 
GeneralRe: Well Done Pin
Reiss6-Sep-11 1:46
memberReiss6-Sep-11 1:46 
GeneralMy vote of 5 Pin
GPUToaster™5-Sep-11 20:38
memberGPUToaster™5-Sep-11 20:38 
GeneralRe: My vote of 5 Pin
Shai Raiten6-Sep-11 19:27
memberShai Raiten6-Sep-11 19:27 
Questiongreat fun Pin
ErrolErrol5-Sep-11 19:08
memberErrolErrol5-Sep-11 19:08 
AnswerRe: great fun Pin
Shai Raiten6-Sep-11 19:28
memberShai Raiten6-Sep-11 19:28 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

| Advertise | Privacy | Terms of Use | Mobile
Web01 | 2.8.151125.1 | Last Updated 2 Sep 2011
Article Copyright 2011 by Shai Raiten
Everything else Copyright © CodeProject, 1999-2015
Layout: fixed | fluid