What you want to see on DotNetFunda.com ?
Go to DotNetFunda.com
Twitter TwitterLinkedIn
YouTubeGoogle
 Online : 1121 |  Welcome, Guest!   Register  Login
Home > Articles > Kinect > How to Tilt the Kinect Sensor

How to Tilt the Kinect Sensor

1 vote(s)
Rating: 5 out of 5
Article posted by Vuyiswamb on 12/4/2012 | Views: 1784 | Category: Kinect | Level: Beginner | Points: 250 red flag


In this article i demonstrate a simple way to tilt the Kinect Sensor.

Download


 Download source code for How to Tilt the Kinect Sensor


Introduction

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.

Objective

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.

 

Start

 

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.


Step 1




Figure 1.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.

 

The 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


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.


Step 2

 

Clean your code, and make sure your Xaml looks like this

  

<Window x:Class="Tilt_Example.MainWindow"

        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"

        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"

        Title="MainWindow" Height="600" Width="800">

    <Grid>

        <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"/> 

    </Grid>

</Window>

 

Which will result into this

Figure 1.3

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 tilt example

 

using System;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
using Microsoft.Kinect;
using System.Linq;
 
namespace Tilt_Example
{
    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[0];
      
        public MainWindow()
        {
            InitializeComponent();
 
//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
            sensor.Stop();
        }
 
        void MainWindow_Loaded(object sender, RoutedEventArgs e)
        {
//Start the Sensor, when exit the application
            sensor.Start();
        }
 
        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
                sensor.ElevationAngle =Convert.ToInt32(txttilt.Text);
            }
        }    }}

Conclusion

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.

Page copy protected against web site content infringement by Copyscape
Found interesting? Add this to:



Please Sign In to vote for this post.

Experience:11 year(s)
Home page:http://www.Dotnetfunda.com
Member since:Sunday, July 06, 2008
Level:NotApplicable
Status: [Member] [MVP] [Administrator]
Biography:Vuyiswa Junius Maseko is a programmer and a moderator in ".NetFunda. Vuyiswa has been developing for 9 years now. his major strength are C# 1.1,2.0,3.0,3.5 and sql and his interest are in Silverlight,WPF,C#,Kinect , Xbox Gaming Dev.
>> Write Response - Respond to this post and get points
Related Posts

The Kinect for Windows sensor is a fully-tested and supported Kinect experience on Windows with features such as “near mode,” skeletal tracking control, API improvements, and improved USB support across a range of Windows computers and Windows-specific 10’ acoustic models.

In this article I demonstrate to you how to use voice commands to input controls in your Kinect application.

This is a Review of the Book titled "Kinect for Windows SDK Programming Guide" by abhijit jana

Microsoft officially released the 1.7 Kinect for Windows SDK. In this article i will demonstrate or explain what interest me most. The Push-to-Press functionality.

There are few things that I have seen while developing Kinect examples, I wouldn't want to say apps, because I have not yet developed a full-fledged application. Kinect user interface, is different from the traditional user interface, where we will see buttons that needs to be clicked. Using voice you can control or do things that you used to do with a mouse, using hand gesture you can control your application like you used to do with a mouse. In this article i will demonstrate to you, on how you can control your application using voice commands.

More ...
About Us | Contact Us | The Team | Advertise | Software Development | Write for us | Testimonials | Privacy Policy | Terms of Use | Link Exchange | Members | Go Top
General Notice: If you find plagiarised (copied) contents on this page, please let us know the original source along with your correct email id (to communicate) for further action.
Copyright © DotNetFunda.Com. All Rights Reserved. Copying or mimicking the site design and layout is prohibited. Logos, company names used here if any are only for reference purposes and they may be respective owner's right or trademarks. | 5/24/2013 10:37:00 PM