Kinect depth Image filtering

Source: Internet
Author: User

Recent work on machine vision, using Kinect as a sensor for depth data, color, gesture recognition, and more. Thank you very much for the two blog posts on Cnblog: (1) http://www.cnblogs.com/yangecnu/archive/2012/03/30/KinectSDK_Geting_Started.html to catch the cold river alone I've learned a lot about the use of C # on the WPF platform and the knowledge of using the Microsoft Kinect SDK to develop your own applications, and I'm grateful for that!

But Bo master alone fishing in the Cold River Blog, for the depth of image filtering, only briefly said to take the inverse and use Bgr32 to express the depth of the image, the effect is not very ideal.

Later, I found another blog post (2) He Wensi's http://www.cnblogs.com/TravelingLight/archive/2012/05/25/2517680.html introduced an article abroad, This paper introduces two kinds of filtering methods developed by foreign authors: pixel filtering method and weighted moving average method. The effect is very good! Unfortunately, only snippets cannot be tested, and filtering algorithms are not particularly easy to understand. What a pity!

A few days ago accidentally tracked and found the author's source code http://kinectdepthsmoothing.codeplex.com/, download to see. Run discovery, program requirements: VS2012 above, Kinect SDK version 1.7 and above, and according to the single Fishing Cold river Blog guidance, the code is the SDK 1.0, further found that some of the API functions, data types are different, moreover, Kinectdepthsmoothing in the XAML code is created in the background, and the blog post of the Cold river is a layout-based, and I do not understand the XAML, how to combine the two programs?

Because of the program of the single fishing cold river, there are a lot of functions to achieve, such as saving images, mouse click Display pixel depth value, color rendering, body size acquisition, gamer Index and so on, and foreign Friends of the Kinectdepthsmoothing program only filter and save images, Then consider transplanting the filter module to the Cold River alone program, and do not change the original layout-style interface. During the migration process, the following types of incompatibility issues are addressed primarily:

A) change the short[] pixeldata type to depthimagepixel[] pixeldata, note here: in SDK version 1.8, private depthimagepixel[] depthpixels, where the depth data is

1 short depth=depthpixels[i]. Depth;

In the SKD 1.0 version, short[] Pixeldata gets the depth data in the way

1 Int32 depth = this. Depthpixels[pindex] >> depthimageframe.playerindexbitmaskwidth;

A shift operation is required. And the two ways of depth type is different, one is the short16 bit, one is the Int32 bit.

b) Store depth images in a three-channel Bgr32 format colorbitmap instead of Depthbitmap in GRAY16 format. In addition to the format of the depth array, there are several lines of code in a foreign friend's program that deserve attention,

1                 // gets the maximum and minimum available depth values for the current frame 2                  Short mindepth = (short) lastdepthframe.mindepth; 3                  Short maxDepth = ( short

And

1      //in this case, the depth values in the Depthpixels array are converted and stored into the colorpixles by element-wise .2 3                //Finally, write the colorpixels into the Colorbitmap4 5                intColorpixelindex =0; 6 7                 for(inti =0; i < depthpixels.length; i++)                 8 9                {                     Ten  One                 //gets the depth value of the element (point) A  -                  Shortdepth =Depthpixels[i].                     Depth;  -  the                 byteIntensity = (byte)255; -  -                 intNewmax = Depth-mindepth;  -  +                 if(Newmax >0)                                             -  +{intensity = (byte)(255- (255* Newmax/(3150))); }                    A  at                   This. colorpixels[colorpixelindex++] = intensity;//Blue -  -                  This. colorpixels[colorpixelindex++] = intensity;//Green -  -                  This. colorpixels[colorpixelindex++] = intensity;//Red -  in++Colorpixelindex;  -}

when the data is finally written to Colorbitmap, the code is

              This.colorBitmap.WritePixels (                     new Int32Rect (0, 0, This.colorBitmap.PixelWidth, this.colorBitmap.PixelHeight),                     this.colorpixels,                     this.colorBitmap.PixelWidth * sizeof (int),                     0);

Using the This.colorBitmap.PixelWidth, instead of the cold Edohaku Master program, use Depthstream.frameheight to create a rectangular area of the image this.depthrect = new Int32Rect (0, 0, depthstream.framewidth, depthstream.frameheight);

c) In addition, when initializing variables (data containers depthpixels and colorpixels), be aware of the size of the Colorpixels

1                  This New Depthimagepixel[depthstream.framepixeldatalength]; 2                  This New byte sizeof (int)];

In short, the two programs together, to pay attention to two aspects, one is the form of the interface, layout or background creation, two,. CS program because of the use of the SDK version, there are many API and data type inconsistencies, need to modify. Since we are doing a follow-up experiment, such as adding your own code for edge detection using depth data, there are a number of ideas that have not been implemented and are written here for the time being. The full code will be uploaded to the network for your reference! Thank you.

The next article will describe the target segmentation based on the depth value and enclose the complete code.

Kinect depth Image filtering

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.