1. Opening the camera

2021-08-20
2 min read

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

  1. Add the Microsoft Kinect V2 extension to your project. On the Solution Explorer, right click on References

  1. In the Assemblies section, search for Microsoft.Kinect. Check/select the extension and Save.

  1. You are now able to see the extension active in your Solution Explorer

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

  1. Create a KinectSensor Object from the Microsoft.Kinect library
private KinectSensor kinectSensor = null;
  1. In the Main class, call the Kinect device with the method GetDefault()
// Initialize the sensor
            kinectSensor = KinectSensor.GetDefault();
  1. Open your sensor with the method, Open()
// Open the sensor
            kinectSensor.Open();
  1. Save all
  2. Build your solution by clicking on Build Solution

  1. Run your solution by clicking on Start

  1. You should be able to see the lights of your sensor on!

  1. 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();
        }
    }
}

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

References

Avatar
Violeta Sosa León Microservices Integration, DevOps, Software Development, Geospatial Technologies, Spatial Data Science, Software Development Teams Management