Hello!

Today’s post is simple: let’s see how to make a Hello World app with the new SDK v2. In Kinect apps, Hello World is basically an app that detects a person in front of the Kinect sensor.

So let’s go for it

1. Create a console app

2. Add the reference to Microsoft.Kinect v2.0

image

4. Important: Change the settings for the reference to not make a local copy.

image

5 Modify the project so that it is compiled for X 86 or X 64. In this way still do not work projects with the ANY CPU type build.

image

6. Then add the following code to the console app

   1: using System;

   2: using Microsoft.Kinect;

   3:  

   4: namespace ConsoleApplication1

   5: {

   6:     class Program

   7:     {

   8:         private static KinectSensor _kinectSensor;

   9:         private static Body[] _bodies;

  10:         private static BodyFrameReader _bodyFrameReader;

  11:  

  12:         static void Main(string[] args)

  13:         {

  14:             // gets the default sensor

  15:             _kinectSensor = KinectSensor.Default;

  16:             if (null != _kinectSensor)

  17:             {

  18:                 // open the sensor

  19:                 _kinectSensor.Open();

  20:  

  21:                 // init body recognition

  22:                 _bodies = new Body[_kinectSensor.BodyFrameSource.BodyCount];

  23:                 _bodyFrameReader = _kinectSensor.BodyFrameSource.OpenReader();

  24:                 _bodyFrameReader.FrameArrived += _bodyFrameReader_FrameArrived;

  25:  

  26:                 // sensor init done!

  27:                 Console.WriteLine("Sensor init done !");

  28:             }

  29:  

  30:             Console.ReadLine();

  31:         }

  32:  

  33:         static void _bodyFrameReader_FrameArrived(object sender, BodyFrameArrivedEventArgs e)

  34:         {

  35:             var frameReference = e.FrameReference;

  36:             var frame = frameReference.AcquireFrame();

  37:             if (frame == null) return;

  38:             using (frame)

  39:             {

  40:                 // update bodycount

  41:                 frame.GetAndRefreshBodyData(_bodies);

  42:                 foreach (var body in _bodies)

  43:                 {

  44:                     if (body.IsTracked)

  45:                     {

  46:                         Console.WriteLine("Body Tracked:" + body.TrackingId);

  47:                     }

  48:                 }

  49:             }

  50:         }

  51:     }

  52: }

Let see some interesting notes for the new SDK

  • line 15. We can have access to the sensor by default connected to our computer.
  • lines 21 to 24; now introduces the concept of Body for recognition. Formerly they were Skeletons
  • lines 33 to 50; Once detected a frame of Body, we can parse it and complete an array of bodies to begin to work with them

7. Launch the app KinectService

image

8 Run the application, and we already have an app that detects bodies with the new Kinect for Windows SDK v2.

image

And as always

“This is preliminary software and/or hardware and APIs are preliminary and subject to change

Greetings @ Home

El Bruno

imageimageimageGoogle

One response to “[#KINECTONE] Hello world with #KinectSdk v2 (body count!)”

  1. […] Hello world with #KinectSdk v2 (body count!)https://elbruno.com/category/msn-microsoft/kinect/kinect-sdk-v2/page/2/ […]

    Like

Leave a comment

Discover more from El Bruno

Subscribe now to keep reading and get access to the full archive.

Continue reading