In this article i demonstrate a simple way to tilt the Kinect Sensor.
Download Download source code for How to Tilt the Kinect Sensor
This is one of the most exciting projects I have ever done. In
this article I will demonstrate to you, how you can move the Kinect sensor to
look where you want it to look.
The Object is to move the Kinect Sensor to move in a click of a
Button, Later you might want to point a sensor to look in a different
directions based on some hand gestures. But for the purpose of simplicity, we
will click the button and look at the sensor while it moves.
In the previous article explained how you can setup your
environment and I also left a link that has downloads to Kinect templates that
will appear in your visual studio if you want to create a new project.
In this article I will not attempt to explain the setting up of
environment. If you are reading this article it is assumed that you have
already installed the latest Kinect sdk and also the development toolkit.
First Start Visual Studio 2010 or 2012, Kinect will not work with
Visual studio 2008. Kinect applications are created using WPF, fire-up your
visual studio as depicted in Step 1.
If you have
already installed the templates , you will notice that the Kinect templates appears in the
list of available Visual studio templates, you can choose any or you can just
select a normal wpf project.
difference between choosing the wpf project and the template is that the
template already add the namespaces that are commonly used when building Kinect
application as depicted in figure 1.2
If you have
created your project using the normal wpf, you need to add a reference to the
“Microsoft.Kinect” that gets installed in the following path
C:\Program Files\Microsoft SDKs\Kinect\v1.6\Assemblies\Microsoft.Kinect.dll
If you have been using a template, you will notice that there will
be a lot of generated code for you, but because of the simplicity we want to
create on this example, we will remove all the code that will not affect the
success of our demonstration.
Clean your code, and make sure your Xaml looks like this
Title="MainWindow" Height="600" Width="800">
<Button Content="Set Tilt"
HorizontalAlignment="Left" x:Name="btnsetTilt" Click="btnsetTilt_Click_1" Margin="453,233,0,0" VerticalAlignment="Top" Width="214" Height="61"/>
<TextBox HorizontalAlignment="Left" Height="56" Margin="196,233,0,0"
TextWrapping="Wrap" Text="" x:Name="txttilt" VerticalAlignment="Top" Width="235"/>
Which will result into this
Figure 1.3 has a textbox and a button to set the tilt. To tilt we
use ElevationAngle property of the Camera object to a value of between
-27 to +27. The Tilt is not designed for frequent use, I thought I should just
show you how easy it will be for you to tilt your Kinect Sensor. You should
never change the tilt programmatically too often because it will results to a run-time error.
In our example if you enter the value, it will tilt according to
the value you have entered in the textbox. Below is the code behind to do the
public partial class MainWindow : Window
//Instantiate the Kinect runtime. Required to initialize the device.
//IMPORTANT NOTE: You can pass the device ID here, in case more than one Kinect device is connected.
KinectSensor sensor = KinectSensor.KinectSensors;
//Runtime initialization is handled when the window is opened. When the window
//is closed, the runtime MUST be unitialized.
this.Loaded += new RoutedEventHandler(MainWindow_Loaded);
//We must stop the Sensor when we exit our project
this.Unloaded += new RoutedEventHandler(MainWindow_Unloaded);
void MainWindow_Unloaded(object sender, RoutedEventArgs e)
//Stop the Sensor, when exit the application
void MainWindow_Loaded(object sender, RoutedEventArgs e)
//Start the Sensor, when exit the application
private void btnsetTilt_Click_1(object sender, RoutedEventArgs e)
if (txttilt.Text != string.Empty)
//change the Elevation based on what has been entered in the textbox
Microsoft gave us flexibility to be in control of the sensor while
writing our application. In this article I have successfully explained how to
tilt your Kinect sensor.
Thank you for visiting Dotnetfunda
If you like this article, subscribe to our RSS Feed. You can also subscribe via email to our Interview Questions, Codes and Forums section.