Getting started with the Kinect for Windows SDK Development (v) data processing in depth

Source: Internet
Author: User

1. Simple depth image processing

In the previous article, we discussed how to get the depth value of the pixel and how to produce the image based on the depth value. In the previous example, we filtered out the points outside the threshold value. This is a simple image processing, called threshold processing. The threshold method used is a bit rough, but useful. A better approach is to use machine learning to calculate thresholds from each frame of image data. The maximum number of Kinect depth values is the 4096mm,0 value, which usually indicates that the depth value is not determined, and generally 0 values should be filtered out. Microsoft recommends using a value of 1220mm (4 ') ~3810mm (12.5 ') in development. Before you perform other deep image processing, you should use the threshold method to filter the depth data to the 1220mm-3810mm range.

Using statistical methods to process deep image data is a common method. Threshold values can be determined based on the average or median of the depth data. Statistical methods can help determine whether a point is noise, shading, or other objects that are more meaningful, such as a user's hand. Sometimes, if you do not consider the visual meaning of pixels, you can data mining the original depth. The purpose of data processing in depth is to identify the shape or object. With this information, the program can determine the position and movement of the body relative to the Kinect.

1.1 Depth Image Data histogram

Histograms are an effective tool for the distribution of statistical data. What we care about here is the distribution of depth values in an image of depth. A histogram can visually reflect the distribution of data in a given data set. From a straight square graph, we can see the frequency of the depth values and the clustering groupings. With this information, we are able to determine thresholds and other metrics that can be used to filter the image so that the depth information in the depth image can be maximized. To show this, we will then show a histogram of the depth image data, and use some simple techniques to filter out the pixels we don't want with the histogram.

First, create a new project. The Kinectsensor object is then discovered and initialized according to the steps in the previous article to perform deep image data processing, including registering Depthframeready events. Before adding the implementation depth histogram, change the UI interface to the following:

 <window x:class= "Kinectdepthhistogram.mainwindow xmlns=" http://schemas.microsoft.com/winfx/2006/xaml/pr Esentation "xmlns:x=" Http://schemas.microsoft.com/winfx/2006/xaml "title=" MainWindow "height=" "width=" 1200 "windowstartuplocation=" Centerscreen "> <Grid> <StackPanel> <stackpanel Orie ntation= "Horizontal" > <image x:name= "depthimage" width= "640" height= "he"/> < Image x:name= "Filtereddepthimage" width= "640" height= "he"/> </StackPanel> <scrollvie Wer margin= "0,15" horizontalscrollbarvisibility= "Auto" verticalscrollbarvisibility= "Auto" > <stackpan El x:name= "Depthhistogram" orientation= "horizontal" height= ""/> </ScrollViewer> </stac Kpanel> </Grid> </window> 

The

Way to create a histogram is simply to create a series of rectangular elements and then add it to the StackPanel element named Depthhistogram. Because the Orientation property of the Depthhistogram object is set to horizontal, the rectangles are arranged horizontally. Most application compute histograms are just for intermediate process processing, and if you want to show the histogram, you need to do some work on the drawing. The following code shows how to draw a histogram:

private void Kinectdevice_depthframeready (object sender, Depthimageframereadyeventargs e) {using (Depthimageframe fr ame = E.opendepthimageframe ()) {if (frame!= null) {frame.
            Copypixeldatato (This._depthpixeldata);
            Createbettershadesofgray (frame, this._depthpixeldata);
        Createdepthhistogram (frame, this._depthpixeldata);
    }} private void Createdepthhistogram (Depthimageframe depthframe, short[] pixeldata) {int depth;
    int[] depths = new int[4096]; Double chartbarwidth = Math.max (3, depthhistogram.actualwidth/depths.
    Length);
    
    
    int maxValue = 0;
    
    
    DepthHistogram.Children.Clear (); Calculates and gets the depth value. and statistics the number of times each depth value appears for (int i = 0; i < pixeldata.length i++) {depth = Pixeldata[i] >> De
    
        Pthimageframe.playerindexbitmaskwidth;
        if (depth >= lodepththreshold && depth <= hidepththreshold) {depths[depth]++;}//Find the maximum depth value for (int i = 0; i < depths. Length;
    i++) {maxValue = Math.max (MaxValue, depths[i]); //Draw histogram for (int i = 0; i < depths. Length;
            i++) {if (Depths[i] > 0) {Rectangle r = new Rectangle ();
            R.fill = Brushes.black;
            R.width = Chartbarwidth;
            R.height = Depthhistogram.actualheight * (depths[i)/(double) maxValue);
            R.margin = new Thickness (1, 0, 1, 0);
            R.verticalalignment = System.Windows.VerticalAlignment.Bottom;
        DEPTHHISTOGRAM.CHILDREN.ADD (R); }
    }
}

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.