Kinect – Getting Started – Control Camera Angle

17/06/2011





In my last post Kinect .NET SDK–Getting Started I showed how to begin writing for Kinect using the new and cool .NET SDK For Kinect, and as I promised I‘ll keep on writing step by step to allow you to understand and get inside all the cool things in Kinect  – But Step By Step

So in this post I’ll show to easy is to control Kinect Camera Angle (Change the position on the camera).

There is Minimum and Maximum angels you can control but as you can see from the last picture (right) you can move the Kinect Sensor manually and the Angle will change automatically.

imageimageimage

Download Demo Project

Step 1: Create Kinect Application

First you need to create a basic WPF application Kinect .NET SDK–Getting Started.

Now when you initialize the KinectNui you can only use the UseColor option for this demo.

//Open the video and depth streams, and sets up the event handlers that the runtime calls when a video, depth, or skeleton frame is ready
//An application must initialize the Kinect sensor by calling Runtime.Initialize before calling any other methods on the Runtime object. 
_kinectNui.Initialize(RuntimeOptions.UseColor);

Step 2: Obtain Camera Sensor

Create  object from the Kinect Nui after the initialization

Camera _cam;
_cam = _kinectNui.NuiCamera;
txtCameraName.Text = _cam.UniqueDeviceName;
Here is the Camera Definition:
public class Camera     
{
         public static readonly int ElevationMaximum;
         public static readonly int ElevationMinimum;
         public int ElevationAngle { get; set; }
         public string UniqueDeviceName { get; }
         public void GetColorPixelCoordinatesFromDepthPixel(ImageResolution colorResolution, ImageViewArea viewArea,
                                                            int depthX, int depthY, short depthValue, out int colorX,
                                                            out int colorY);     }

Step 3: Up and Down

Now when you do that you can control the camera angel as follow:
To increase the Camera Angel all you need to do is to increase camera ElevationAngle, there is Min and Max angels for the camera that you can control so don’t be afraid to push it to much. Smile
private void BtnCameraUpClick(object sender, RoutedEventArgs e)
{
     try
     {
         _cam.ElevationAngle = _cam.ElevationAngle + 5;
     }
     catch (InvalidOperationException ex)
     {
         MessageBox.Show(ex.Message);
     }
     catch (ArgumentOutOfRangeException outOfRangeException)
     {
         //Elevation angle must be between Elevation Minimum/Maximum"

         MessageBox.Show(outOfRangeException.Message);
     }
And Down
private void BtnCameraDownClick(object sender, RoutedEventArgs e)
{
     try     {
         _cam.ElevationAngle = _cam.ElevationAngle - 5;
     }
     catch (InvalidOperationException ex)
     {         MessageBox.Show(ex.Message);
     }
     catch (ArgumentOutOfRangeException outOfRangeException)
     {
        
//Elevation angle must be between Elevation Minimum/Maximum"
         MessageBox.Show(outOfRangeException.Message);
     } }
Download Demo Project
Add comment
facebook linkedin twitter email

Leave a Reply

5 comments

  1. Yusep21/06/2011 ב 02:17

    When I execute the code a had exceptions about _cam is not assigned and I can’t move the angle.

  2. Thijs28/06/2011 ב 14:16

    Same problem.. crashes when trying to set the angle

  3. William22/07/2011 ב 22:43

    The SDK reference says ElevationAngle is a property of Camera but I think this has changed. There is however a Runtime.NuiCamera.ElevationAngle.

  4. stean9904/11/2011 ב 19:41

    when downloading the example:

    on line 57 there is the following line: Camera _cam;

    this is wrong (make it( //Camera _cam;)) because there is already a private property above mentioned

  5. CoCo16/03/2012 ב 00:56

    Great….Thanks!!!!