Introduction to the Kinect for Windows SDK Development (vi) skeleton tracking based on

Source: Internet
Author: User
Tags object model xmlns

Kinect produces a limited range of depth data, and the use of Kinect to create truly interactive, interesting and memorable applications requires data other than depth data. This is what bone-tracking technology is all about, and bone-tracking technology builds the coordinates of the body's joints by processing the depth of the data, and bone tracking can determine the parts of the body, such as the hand, head, and body. Bone tracing produces x,y,z data to determine these bone points. In the above, we discussed some techniques of depth image processing. The depth image processing technique used in skeletal tracking systems uses more sophisticated algorithms such as matrix transformations, machine learning, and other methods to determine the coordinates of bone points.

In this paper, we first show the main objects involved in skeleton tracking system, and then discuss the object model of skeleton tracking in detail.

1. Get Skeleton data

This section will create an application to draw the captured skeleton data to the UI interface. Before you start coding, take a look at some basic objects and how to get skeleton data from those objects. It is also necessary to understand the format of the data before data processing. This example is simple and straightforward, requiring only the skeleton data object and then drawing the captured data.

Color image data, depth of data from Colorimagesteam and Depthimagestream, similarly, bone data from Skeletonstream. There are two ways to access bone data and access to color image data, depth data, as well as event patterns and "pull" modes. In this case, we adopt an event-based approach because it is simple, less code, and is a very common and basic method. The Kinectsensor object has a Skeletonframeready event named. This event is triggered when new skeleton data is generated in the Skeletonstream. Bone data can also be obtained through the Allframesready event. In the next section, we'll discuss the skeleton tracking object model in more detail, and now we only show how to get skeleton data from the Skeletonstream stream. Each frame of data produced by Skeletonstream is a collection of skeleton objects. Each skeletal object contains data describing the position of the bone and the bone joint. Each joint has a unique identifier such as head, shoulder (shoulder), elbow (Dlbow) information and 3D vector data.

Now to write the code. First create a new WPF project file and add Microsoft.Kinect.dll. Add code for basic lookup and initialization sensors, which refer to previous articles. Before starting the sensor, initialize the Skeletonstream data stream and register the Skeletonframeready event for the Kinectsensor object, which does not use the data produced by the color camera and IR camera, so no initialization of the data stream is necessary. The UI interface uses the default, changing the name of the grid to LayoutRoot and then drawing in the grid. The code is as follows:

<window x:class= "Kinectskeletontracking.mainwindow"
        xmlns= "http://schemas.microsoft.com/winfx/2006/xaml/ Presentation "
        xmlns:x=" Http://schemas.microsoft.com/winfx/2006/xaml "
        title=" MainWindow "height=" "350" Width= "525" >
    <grid x:name= "LayoutRoot" background= "white" >
            
    </Grid>
</Window>

The background logic code is as follows:

Private Kinectsensor Kinectdevice;
    
Private ReadOnly brush[] skeletonbrushes;//drawing brush private skeleton[] frameskeletons;
    Public MainWindow () {InitializeComponent (); Skeletonbrushes = new brush[] {brushes.black, Brushes.crimson, Brushes.indigo, Brushes.dodgerblue, Brushes.Purple,
    Brushes.pink};
    KinectSensor.KinectSensors.StatusChanged + = kinectsensors_statuschanged; This.
    
Kinectdevice = KinectSensor.KinectSensors.FirstOrDefault (x => x.status = = kinectstatus.connected);
    Public Kinectsensor Kinectdevice {get {return this.kinectdevice;} set {if (This.kinectdevice!= value) {//uninitialize if (This.kinectdevice!)
                = null) {this.kinectDevice.Stop ();
                This.kinectDevice.SkeletonFrameReady-= Kinectdevice_skeletonframeready;
                This.kinectDevice.SkeletonStream.Disable ();
            This.frameskeletons = null; } This. Kinectdevice = value; Initialize if (this.kinectdevice!= null) {if (This.kinectDevice.Status = = Kine
                    ctstatus.connected) {this.kinectDevice.SkeletonStream.Enable ();
                    This.frameskeletons = new Skeleton[this.kinectdevice.skeletonstream.frameskeletonarraylength];
                    This.kinectDevice.SkeletonFrameReady + = Kinectdevice_skeletonframeready;
                This.kinectDevice.Start (); 
    '}}} ' private void Kinectsensors_statuschanged (object sender, Statuschangedeventargs e) { Switch (e.status) {case KinectStatus.Initializing:case KinectStatus.Connected:case Kin EctStatus.NotPowered:case KinectStatus.NotReady:case KinectStatus.DeviceNotGenuine:this.
            Kinectdevice = E.sensor;
        Break Case kinectstatus.disconnected://todo: Give the user feedback to plug-in a Kinect device. This.
            Kinectdevice = null;
        Break
    Default://todo:show an error state break; }
}

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.