Category: kinect

Sample Kinect application

Made my first application for Kinect. It was just a combination of multiple other source code + EF4.3 for SqlServer Compact 4.0 ( to can have a database without pain of installing).

As learning:

  1. The audio recognition does not work very well.
  2. It was fun to write
  3. Do not make an action for each joint movement – it is overwhelming for Kinect
  4. If you approach Kinect device perpendicular ( such as line of shoulders is perpendicular  to Kinect) it does not recognize you.


The application makes a simple thing:

You can use them to photo the thiefs that comes after you left the house.
Just press “Capture” (or make a circle with the right hand) and after a timeout( set in option) the application will register, via Kinect, any new human move.It will save to the
<user profile> AppData\Roaming\Pictures  and, if configured , to a website ( more details later this month).


Download from here if you have a Kinect device



I have the opportunity to borrow a Kinect hardware  – to make an application( I will make a simple anti-theft application).

The steps for developing in Kinect are:

  • Download the SDK from – it contains the drivers also
  • Connect Kinect to USB , plug in the socket
  • Run the Kinect Explorer or Kinect Shape Game from Kinect SDK Sample Browser installed at 1.  Ensure it works.
  • Read the Kinect Explorer source –it is SO clear!
  • Read documentation – finally, you should RTFM Winking smile

Optional resources:

  1. – Visual Studio template for Skeleton, Audio, Video. Simple example that works ( simpler than Kinect Explorer !)
  2. – added methods to Kinect.
  3. – detection of gesture.

Example 1: Integrating saving image in Kinect Explorer when a skeleton is detected

Add reference to optional resource 2( either download , either via Nuget)

Search for  KinectAllFramesReady in KinectSkeletonViewer.xaml.cs and put this code

						var takePic = this.skeletonData.Count(item => item.TrackingState == SkeletonTrackingState.Tracked) > 0;

						if (takePic)
							DateTime imgDate = DateTime.Now;
							string imageName = "andrei" + imgDate.ToString("yyyyMMdd_HHmmss") + ".jpg";
							if (!File.Exists(imageName))
								using (var image = e.OpenColorImageFrame())
									if (image != null && this.skeletonData.Length > 0 && this.skeletonData.Count(item => item.TrackingState != SkeletonTrackingState.NotTracked) > 0)
										if (image != null && takePic)
											var x = image.ToBitmapSource();
											var b = Save(x, ImageFormat.Jpeg);

											var t = Task.Factory.StartNew(

												(img) =>

													imgDate = DateTime.Now;
													imageName = "andrei" + imgDate.ToString("yyyyMMdd_HHmmss") + ".jpg";
													if (File.Exists(imageName))
													byte[] i = img as byte[];
													if (i != null)
														File.WriteAllBytes(imageName, i);
												}, b);

Example 2 : Detecting circle by right hand in Kinect Explorer when a skeleton is detected

Add reference to optional resource 3( either download , either via Nuget)

Download file and put in your project. Ensure “Copy to output directory” is “copy always/copy if newer”

Add a variable named

TemplatedGestureDetector circleGestureRecognizer;

In KinectSkeletonViewer.xaml.cs in constructor put

			using (Stream recordStream = File.Open("", FileMode.Open))
				circleGestureRecognizer = new TemplatedGestureDetector("Circle", recordStream);
				circleGestureRecognizer.OnGestureDetected += new Action<string>(circleGestureRecognizer_OnGestureDetected);
//TODO : implement circleGestureRecognizer_OnGestureDetected : void circleGestureRecognizer_OnGestureDetected(string obj)

Search for KinectAllFramesReady in KinectSkeletonViewer.xaml.cs and put this code

foreach (Joint joint in skeleton.Joints)//existing code
								Point mappedPoint = this.GetPosition2DLocation(depthImageFrame, joint.Position);//existing code
								jointMapping[joint.JointType] = new JointMapping//existing code
										Joint = joint,
										MappedPoint = mappedPoint
//new code from here:
									 if ((joint.TrackingState == JointTrackingState.Tracked) && (joint.JointType == JointType.HandRight))
											circleGestureRecognizer.Add(joint.Position, Kinect);


That will be all…
If you have developed with Kinect, please share your sources as comments.