"Translation" Kinect v2 programming (c + +) depth

Source: Internet
Author: User

Kinect SDK v2 Preview for a description of how to get depth data.

In the previous section, I introducedby usingKinect for Windows SDKV2Preview Version(hereinafter referred to as,Kinect SDKV2Preview Version)fromKinect for WindowsV2Developer Preview version (later,KinectV2preview) to get the color method. This section describes how to get depth data from the Kinect. Depth SensorThe Kinect is equipped with a depth sensor to obtain depth data (and sensor distance information).Kinect v1,can read the projected infraredPatternfromPatternthe deformation gets depth information,The depth sensor is equipped with the "light coding" method. In the Kinect v2 preview, the depth sensor is changed to "time of Flight (ToF) mode by the time it bounces back from the projected infrared pulses to get depth information. "light coding" is an IsraeliPrimeSense Company's depth sensing technology. For details, please refer to the patent informationU.S. Patent Pending (US 2010/0118123 A1)-Depth Mapping using projected Patterns. "time of Flight (ToF)" isA company acquired by Microsoft in the United States with time of Flight (ToF) Depth sensing technology (3DV Systems, Canesta), is generally considered to be using this technology.depth resolution of data,the Kinect v1 is a,but,KinectV2the preview version is promoted to 512x424. Also,the resolution of the depth direction is also improved. OKGetDepthof theData Range,Kinect V1 is the range of 0.8~4.0[m],Kinectv2The preview version can get 0.5~4.5[m] range. It says the depth data range for default mode.The Kinect v1 provides depth data at close rangenear Mode (0.4~3.0[m]) and the data obtained from the depthExtended Depth (~ about 10.0[m]). But,Deviate fromThe range of the Default modethe accuracy of the depth data is reduced. This section introduces methods for obtaining depth data from depth sensors. Figure 1"light Differences in coding" mode and "time of Flight (ToF) mode (image of how the depth sensor works) Sample ProgramKinect SDKV2Preview to get depth data,Visual Displaythe sample program. An excerpt from the data acquisition phase of the introduction of the previous section. The full contents of this sample program,It's all public on the following GitHub. Https://github.com/UnaNancyOwen/Kinect2Sample Figure 2 Data acquisition process for Kinect SDK v2 Preview (re-send ) "sensor"Get "sensor"
//Sensorikinectsensor* Psensor; ......1HRESULT HRESULT=S_ok;hresult= Getdefaultkinectsensor (&psensor); ......2if(FAILED (HResult)) {Std::cerr<<"Error:getdefaultkinectsensor"<<Std::endl; return-1;} HResult= Psensor->open (); ......3if(FAILED (HResult)) {Std::cerr<<"Error:ikinectsensor::open ()"<<Std::endl; return-1;}
Listing 1.1 corresponds to part of Figure 1"sensor" (re-sent) 1 processing the Sensor interface of the Kinect v2 preview. 2 Get the defaultSensor. 3 Open Sensor. "source"Obtained "source" from "sensor".
// Source idepthframesource* Pdepthsource;  ...... 1  = Psensor->get_depthframesource (&pdepthsource);  ...... 2 if (FAILED (HResult)) {  "error:ikinectsensor::get_depthframesource ()" << Std::endl;   return -1;}
Listing 1.2equivalent to the part of Figure 1"source"1 Gets the source interface of the depth frame. 2 obtained from sensorSource. Kinect SDK v1,to obtainThe depth data is primarily made possible by the simultaneousdepth andPlayer (Human body Area) of the "stream". So,It is necessary to have depth data and the split processing of the player data. (Note:The Kinect SDK v1 provides 2 ways to handle depth and player Index, and the old method returns a set of ushort, separating the two by displacement; The new method returns the structure of each of the 2 ushort)The Kinect SDK v2 preview, depth and bodyindex (equivalent to the Kinect SDK V1 player) were taken as "source", as described in Bodyindex in the next section. The Kinect SDK v1 also has the "stream" to get depth, because there are also a lot of things to do with the player and skeleton (body posture) data, which can be achieved with depth and player "stream" at the same time. "reader""source" from Open "reader".
// Reader idepthframereader* Pdepthreader;  ...... 1  = Pdepthsource->openreader (&pdepthreader);  ...... 2 if (FAILED (HResult)) {  "error:idepthframesource::openreader ()" < < Std::endl;   return -1;}
Listing 1.3 corresponds to section 1 of Figure 1"reader" to get the Reader interface of depth frame. 2 Open reader from source. "frame"~"data"Get the latest "frame" from "reader".
intwidth = +; ......1intHeight =424; ......1unsignedintbuffersize = width * Height *sizeof(unsigned Short); ......2Cv::mat buffermat (height, width, cv_16sc1); ...3Cv::mat depthmat (height, width, cv_8uc1); ...3Cv::namedwindow ("Depth" ); while(1 ){  //Frameidepthframe* pdepthframe = nullptr; ......4HResult= Pdepthreader->acquirelatestframe (&pdepthframe); ......5  if(SUCCEEDED (HRESULT)) {HRESULT= Pdepthframe->accessunderlyingbuffer (&buffersize, reinterpret_cast<uint16**> (&bufferMat.data))  ; ......6    if(SUCCEEDED (HResult)) {Buffermat.convertto (Depthmat, cv_8u,-255.0f/4500.0f,255.0f); ......7}} saferelease (Pdepthframe); //Show WindowCv::imshow ("Depth", Depthmat); if(Cv::waitkey ( -) ==vk_escape) {     Break; }}
Listing 1.4 corresponds to the size of Part 1 depth data (512x424) of Figure 1"frame","data".to simplify the description, the image size is set with hard code, and the sample program can get the frame information from the source. 2 depth The size of the data. 3 The Cv::mat type of OPENCV prepared to handle depth data. "buffermat" is the original depth data of 16bit, "depthmat" in order to be displayed as an image, the depth data stored in the range of 8bit processing. "cv_16sc1", is the unsigned 16bit integer (16S) placed in 1 channel (C1) parallel to represent 1 pixels of the data format. (Note: It should be CV_16UC1) "cv_8uc1" is a data format that shows unsigned 8bit integers (8U). 4 Gets the frame interface of the depth data. 5 Get the latest frame from reader.   6 get depth data from frame. Gets a pointer to an array of depth data stores. Here fordepth Data visualization, easy to change processing, with the Cv::mat type to obtain. 7 in order toDisplays the depth data image, converted from 16bit to 8bit. If you get "frame",you can take out the depth data .,visualize them as images. depth Data taken out,As shown in Figure 3, the 16bit (0~4500) is a 1 image. because such images cannot be displayed (note: OpenCV can only display 8bit of image data)NeedConvert the format to a range of 8bit (0~255). Sample program,use Cv::mat's conversion command (Cv::mat::convertto ()) to close the sensor distance (255),The far display is a very dark (0) way to convert.
Figure 3 Arrangement of depth data Run ResultsTo run this sample program,KinectV2Preview to get depth image,just like Figure 4. Figure 4 Running results SummaryThis section describes theKinect SDKV2the preview version obtains the sample program for depth data. The next section describes getting Bsample program for Odyindex data.

"Translation" Kinect v2 programming (c + +) depth

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.