Early development experience of Kinect for Windows SDK (4) depth of field data

Source: Internet
Author: User

Author: Ma Ning

Finally, I can sit down and continue this series. in Weibo and blog parks, there have been countless reminders. Sorry, my energy is limited, but I will spare all the time available to do it as soon as possible.

In this chapter, we will talk about the Depth of field Data (Depth Data), which is a brand new feature provided by the Depth Camera of Kinect. Previous technologies can only do some work through image recognition, we can use the depth of field to help us. For example, the separation of foreground and background can only be set to a blue screen or a green screen in the past, but now with the depth of field data, we can easily separate foreground objects from the background. Of course, Depth Camera technology is provided by the Israeli company PrimeSense.

Program Layout

In this chapter, the work we need to do is very simple. We can set different colors based on the distance between the object and the Kinect. First, create a new WPF project and add an Image control:

 

Then there is the core code in MainWindow. xaml. cs, which is roughly the same as the previous code, so I will not explain it too much:

 

The only thing you need to note is that the parameter passed in the initialization function is RuntimeOptions. UseDepthAndPlayerIndex, which indicates that the information of the PlayerIndex is included in the depth of field. Next, we will take some time to understand the actual structure of DepthAndPlayerIndex.

Understanding DepthAndPlayerIndex

Let's take a look at the DepthFrameReady event processing function, as shown below:

 

The DepthFrameReady event returns an ImageFrame object that contains a PlanarImage object. The PlanarImage object contains a byte [] array, which contains the depth information of each pixel. This array is characterized by starting from the upper left corner of the image, starting from left to right, and then from top to bottom.

Each pixel in this array is represented by two bytes. We need to use bitwise operations to obtain the location information of each pixel.

If it is Depth Image Type, you can shift the second bytes to eight places left.

 

For DepthAndPlayerIndex Image Type, remove the Player Index information from the first bytes three places to the right, and move the second bytes five places to the left.

 

The first three bytes of the DepthAndPlayerIndex image type include the Player Index information. Player Index contains a maximum of six possible values:

0, no players; 1, Player 1; 2, Player 2, and so on.

We can use the following method to obtain the Player Index information:

 
Set color 

Next, we create a bytes array to store color values.

 

Of course, we 'd better set several boundary values to define different colors of different distances:

 

Finally, put all the Code together and set the color value:

Blue, less than 900; 900 to 2000, green; greater than 2000, red

The Code is as follows:

 

The actual effect of the program is as follows:

650) this. width = 650; "border =" 0 "alt =" "src =" http://www.bkjia.com/uploads/allimg/131228/1S5411255-0.png "/>

Written to the end

Here, we have finished introducing the NUI basic content in the Kinect SDK. Next, we will introduce the Audio section, or use some practical examples to see the actual application of the Kinect SDK.

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.