DCSIMG
Kinect – Getting Started – Control Camera Angle - Shai Raiten's Blog

Shai Raiten's Blog

It's all about code...

Kinect – Getting Started – Control Camera Angle

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

Comments

Shai Raiten said:

In my last two posts I’ve talked about Kinect SDK from Kinect .NET SDK–Getting Started and Kinect – Getting

# June 17, 2011 5:10 PM

Yusep said:

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

# June 21, 2011 2:17 AM

Thijs said:

Same problem.. crashes when trying to set the angle

# June 28, 2011 2:16 PM

Shai Raiten said:

In my previous posts about Kinect I’ve talked about getting started with Kinect SDK from Kinect .NET

# July 5, 2011 4:54 PM

Kinect ??? Getting Started ??? Control Camera Angle - Shai Raiten said:

Pingback from  Kinect ??? Getting Started ??? Control Camera Angle - Shai Raiten

# July 16, 2011 11:33 AM

William said:

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

# July 22, 2011 10:43 PM

stean99 said:

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

# November 4, 2011 7:41 PM

CoCo said:

Great....Thanks!!!!

# March 16, 2012 12:56 AM
Leave a Comment

(required) 

(required) 

(optional)

(required) 


Enter the numbers above: