Tutorial 1: Opening Kinect V2 camera
In this tutorial, you will be able to get access to the camera. At the end you will have the lights of your device turned on.
Prerequisites
You must have already followed the guide for installing and configuring the Kinect V2 Link
You must have configured your Visual Studio 2019 correctly as instructed Link
Adding the Microsoft Kinect Library to the project
- Add the Microsoft Kinect V2 extension to your project. On the Solution Explorer, right click on References
- In the Assemblies section, search for Microsoft.Kinect. Check/select the extension and Save.
- You are now able to see the extension active in your Solution Explorer
- For the code to be able to use the extension, you must declare it in your _MainWindow.xaml.cs file:
...
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
/// Kinect Libraries
using Microsoft.Kinect;
namespace kinectTutorial01
{
/// <summary>
/// Interaction logic for MainWindow.xaml
/// </summary>
public partial class MainWindow : Window
...
Opening the camera
- Create a KinectSensor Object from the Microsoft.Kinect library
private KinectSensor kinectSensor = null;
- In the Main class, call the Kinect device with the method GetDefault()
// Initialize the sensor
kinectSensor = KinectSensor.GetDefault();
- Open your sensor with the method, Open()
// Open the sensor
kinectSensor.Open();
- Save all
- Build your solution by clicking on Build Solution
- Run your solution by clicking on Start
- You should be able to see the lights of your sensor on!
- The final code should look like this:
// other libraries from your template
....
// Kinect V2 Extensions
using Microsoft.Kinect;
/***
Body Tracking with depth sensor course SS2021
Kinect Tutorial 01: Access the sensor
Goal: Get access to the Kinect by adding the libraries
Result: An empty Window and the Kinect V2 lights on. We still havent call the feed into the interface!
**/
namespace kinectTutorial01
{
/// <summary>
/// Interaction logic for MainWindow.xaml
/// </summary>
public partial class MainWindow : Window
{
// Create the Kinect sensor object
private KinectSensor kinectSensor = null;
public MainWindow()
{
// Initialize the sensor
kinectSensor = KinectSensor.GetDefault();
// Open the sensor
kinectSensor.Open();
InitializeComponent();
}
}
}
- Now you are able to open your Kinect sensor.
Questions?
If you have any questions, comments, or suggestions, feel free to contact me on Twitter or Linkedin as @violetasdev.