none
Rudimentary C++ Kinect Console App RRS feed

  • Question

  • Hi,

    While I do like many features of C# with WPL and plan to learn more, I am for the time being more comfortable working in C++. I'm not a software engineer but the nature of my job requires me to be a "jack of all trades". Unfortunately, the only C++ Kinect skeletal tracking examples I have been able to find include a substantial amount of additional code related to managing the window system which I find confusing.

    I'm hoping someone will be kind enough to provide a very basic (bare bones -- pun intended, ooops -- sorry) example of a C++ command line application capable of printing the XYZ coordinates of a skeletal joint to a command window.

    Your help is greatly appreciated,

    Bill

    Wednesday, May 23, 2012 6:40 PM

Answers

  • sorry i didnt mention scotts webcam filter link but as you know a directshow filter does not have a window when used. Link to scotts filter:

    http://social.msdn.microsoft.com/Forums/en-US/kinectsdk/thread/4ee6e7ca-123d-4838-82b6-e5816bf6529c

    Scroll down until you see his source for v1.

    I would work on it some more but need to finish another kinect project for work.

    Maybe with your c++ expertise you can figure out if hes handling data wrong or inefficently or something.


    Once you eliminate the impossible, whatever remains, no matter how improbable, must be the truth. - "Sherlock holmes" "speak softly and carry a big stick" - theodore roosevelt. Fear leads to anger, anger leads to hate, hate leads to suffering - Yoda. Blog - http://jefferycarlsonblog.blogspot.com/

    Thursday, May 24, 2012 6:48 PM

All replies

  • Your wish is granted. In the new Kinect Developer's Toolkit (included in our v1.5 release just this week), there's a whole series of new "basics" samples in C++ (as well as C# and VB), which have the sole purpose of demonstrating how to code to each part of the sensor in as few lines as possible. Have a look at each of these samples:

    • ColorBasics-D2D
    • DepthBasics-D2D
    • SkeletonBasics-D2D
    • AudioBasics-D2D
    • SpeechBasics-D2D

    John
    K4W Dev

    • Proposed as answer by The Thinker Thursday, May 24, 2012 12:38 PM
    • Unproposed as answer by The Thinker Thursday, May 24, 2012 6:39 PM
    Wednesday, May 23, 2012 7:51 PM
  • John,

    Thanks for the reply. I appreciate your help.

    I have looked at those examples previously and find that all the code necessary to manage the window system obscures the basic steps required to access the Kinect.

    All I require is an example of a very basic console application that allows me to access the skeletal joint information, which I then use in an existing OpenGL application.

    I'm wasn't kidding when I said I was looking for something rudimentary :)

    Here is an example of what I am looking for that I found on a different forum. I just want to understand how to do the same thing in C++:

    namespace SkeletonExample
    {
        using System;
        using System.Linq;
        using Microsoft.Kinect;

        internal class Program
        {
            private static void Main(string[] args)
            {
                // Find the first connected sensor
                KinectSensor sensor = KinectSensor.KinectSensors.Where(s => s.Status == KinectStatus.Connected).FirstOrDefault();
                if (sensor == null)
                {
                    Console.WriteLine("No Kinect sensor found!");
                    return;
                }

                // Create object that will track skeletons using the sensor
                Tracker tracker = new Tracker(sensor);

                // Start the sensor
                sensor.Start();

                // Run until the user presses 'q' or 'Q' on the keyboard
                while (Char.ToLowerInvariant(Console.ReadKey().KeyChar) != 'q') { }

                // Stop the sensor
                sensor.Stop();
            }
        }

        internal class Tracker
        {
            private Skeleton[] skeletons = null;

            public Tracker(KinectSensor sensor)
            {
                // Connect the skeleton frame handler and enable skeleton tracking
                sensor.SkeletonFrameReady += SensorSkeletonFrameReady;
                sensor.SkeletonStream.Enable();
            }

            private void SensorSkeletonFrameReady(object sender, SkeletonFrameReadyEventArgs e)
            {
                // Access the skeleton frame
                using (SkeletonFrame skeletonFrame = e.OpenSkeletonFrame())
                {
                    if (skeletonFrame != null)
                    {
                        if (this.skeletons == null)
                        {
                            // Allocate array of skeletons
                            this.skeletons = new Skeleton[skeletonFrame.SkeletonArrayLength];
                        }

                        // Copy skeletons from this frame
                        skeletonFrame.CopySkeletonDataTo(this.skeletons);

                        // Find first tracked skeleton, if any
                        Skeleton skeleton = this.skeletons.Where(s => s.TrackingState == SkeletonTrackingState.Tracked).FirstOrDefault();

                        if (skeleton != null)
                        {
                            // Obtain the left knee joint; if tracked, print its position
                            Joint j = skeleton.Joints[JointType.Head];

                            if (j.TrackingState == JointTrackingState.Tracked)
                            {
                                Console.WriteLine("Head position: " + j.Position.X + ", " + j.Position.Y + ", " + j.Position.Z);
                            }
                        }
                    }
                }
            }
        }
    }

    Thanks!!

    Bill

    Thursday, May 24, 2012 3:00 PM
  • Their are a lot of those floating around on this kinect forum I could repeat similar threads 20-30 times and they be v1 and above code. They are not in c++ though but at least 5-10 are in c++ and v1 code. Just wait for a reponse because direct handing of code is not a strong suit in this forum especially when it comes to c++ but if its an easy task someone might respond sooner. Have you tryed scotts v1 filter code in c++ it is very basic and just captures rgb stream data? Maybe you can ignore the window code open a new command line type c++ project and paste the header files and other code into your new c++ app excluding code that requires a control?

    This should be possible in v1.5 kinect sdk since the UI code for WPF samples was seperated from behind code or library.


    Once you eliminate the impossible, whatever remains, no matter how improbable, must be the truth. - "Sherlock holmes" "speak softly and carry a big stick" - theodore roosevelt. Fear leads to anger, anger leads to hate, hate leads to suffering - Yoda. Blog - http://jefferycarlsonblog.blogspot.com/





    • Edited by The Thinker Thursday, May 24, 2012 3:10 PM
    • Proposed as answer by The Thinker Thursday, May 24, 2012 6:39 PM
    Thursday, May 24, 2012 3:03 PM
  • OK. Great -- I'll do some more through searches through the forum and check out scotts v1 filter. Thanks!!

    Thursday, May 24, 2012 6:37 PM
  • You'll have to upgrade scotts code from v1 but I will personally be trying v1.5 this friday or saturday so I will tell you if its a lot of upgrading or not.

    Once you eliminate the impossible, whatever remains, no matter how improbable, must be the truth. - "Sherlock holmes" "speak softly and carry a big stick" - theodore roosevelt. Fear leads to anger, anger leads to hate, hate leads to suffering - Yoda. Blog - http://jefferycarlsonblog.blogspot.com/


    Thursday, May 24, 2012 6:40 PM
  • Great. I really appreciate your help!
    Thursday, May 24, 2012 6:42 PM
  • sorry i didnt mention scotts webcam filter link but as you know a directshow filter does not have a window when used. Link to scotts filter:

    http://social.msdn.microsoft.com/Forums/en-US/kinectsdk/thread/4ee6e7ca-123d-4838-82b6-e5816bf6529c

    Scroll down until you see his source for v1.

    I would work on it some more but need to finish another kinect project for work.

    Maybe with your c++ expertise you can figure out if hes handling data wrong or inefficently or something.


    Once you eliminate the impossible, whatever remains, no matter how improbable, must be the truth. - "Sherlock holmes" "speak softly and carry a big stick" - theodore roosevelt. Fear leads to anger, anger leads to hate, hate leads to suffering - Yoda. Blog - http://jefferycarlsonblog.blogspot.com/

    Thursday, May 24, 2012 6:48 PM