Get the Bodyindex (body area) method and sample code through the Kinect SDK v2 preview.
The previous section describes how to get depth data from the Kinect V2 preview, using the Kinect SDK V2 preview version. This section describes how to get Bodyindex (body area) from the Kinect.
BodyindexGets the body area based on the depth data obtained from the Kinect (sensor distance information). Because the human body area is based on depth data, it also relies on the resolution of the depth sensor. As described in the previous section,because the KinectV2The resolution of the depth sensor in the preview version (512x424) is significantly increased,compared to the Kinect v1,a small part of a finger.Human body Areacan also be accurately obtained.。but,can detect theHuman body Areathe number of 6 people this has not changed. About the human body area, which is called in the Kinect SDK v1"player",but there it is.Kinect SDKV2the preview version is renamed"bodyindex". This section, introducing the acquisitionmethod of "bodyindex".
Figure 1 sample program for Kinect SDK v2 Preview (bodybasics) PutBodyindex The position of the color coordinate to intercept,tiny parts like fingers can be clearlyHumanthe body is preserved. (Note: The conversion of the coordinate space is required because the camera location of color and depth is different)
Sample ProcedureUse the Kinect SDK v2 preview to get Bodyindex, and show the sample programs that each body is color-coded and displayed. The 2nd section has an introduction to the stage of obtaining dataexcerpts from the commentary. The full contents of this sample program,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 1 of Figure 1"source" processing the sensor interface of the Kinect v2 preview. 2 Get the defaultSensor. 3 Open Sensor.
"source"Obtained "source" from "sensor".
// Source ibodyindexframesource* Pbodyindexsource; ...... 1 = Psensor->get_bodyindexframesource (&pbodyindexsource); ...... 2 if (FAILED (HResult)) { "error:ikinectsensor::get_bodyindexframesource ()" << Std::endl; return -1;}
Listing 1.2equivalent to the part of Figure 1"source"1 Gets the source interface of the Bodyindex frame. 2 obtained from sensorSource.
"reader""source" from Open "reader".
// Reader ibodyindexframereader* Pbodyindexreader; ...... 1 = Pbodyindexsource->openreader (&pbodyindexreader); ...... 2 if (FAILED (HResult)) { "error:ibodyindexframesource::openreader ()" << Std::endl; return -1;}
Listing 1.3 corresponds to section 1 of Figure 1"reader" to get the Reader interface of Bodyindex frame. 2 Open reader from source.
"frame"~"data"Get the latest "frame" from "reader".
intwidth = +; ......1intHeight =424; ......1Cv::mat bodyindexmat (height, width, cv_8uc3); ...2Cv::namedwindow ("Bodyindex" );//Color TableCv::vec3b color[6]; ......3color[0] = cv::vec3b (255,0,0); color[1] = cv::vec3b (0,255,0); color[2] = cv::vec3b (0,0,255); color[3] = cv::vec3b (255,255,0); color[4] = cv::vec3b (255,0,255); color[5] = cv::vec3b (0,255,255 ); while(1 ){ //Frameibodyindexframe* pbodyindexframe = nullptr; ......4HResult= Pbodyindexreader->acquirelatestframe (&pbodyindexframe); ......5 if(SUCCEEDED (HResult)) {unsignedintBufferSize =0; unsignedChar* Buffer =nullptr; HResult= Pbodyindexframe->accessunderlyingbuffer (&buffersize, &buffer); ......6 if(SUCCEEDED (HResult)) { for(inty =0; Y < height; y++ ){ for(intx =0; x < width; X + +) {unsignedintIndex = y * width +x; if(Buffer[index]! =0xFF) {bodyindexmat.at<cv::Vec3b> (y, x) = Color[buffer[index]]; ......7 } Else{bodyindexmat.at<cv::Vec3b> (y, x) = Cv::vec3b (0,0,0); ......7}}}}} saferelease (pbodyindexframe); //Show WindowCv::imshow ("Bodyindex", Bodyindexmat); if(Cv::waitkey ( -) ==vk_escape) { Break; }}
Listing 1.4 corresponds to the size of Part 1 Bodyindex of Figure 1"frame","data" (512x424). 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 to draw the body area from the Bodyindex, use the OpenCV cv::mat. 3 Draw a color table for the body area. 4 Get the Frame interface for Bodyindex. 5 Get the latest frame from reader. 6 get Bodyindex from frame. Gets a pointer to the save Bodyindex array. 7 Draw the Bodyindex body area. Each bodyindex is shaded with reference to a color table. If you can get the Bodyindex data from the obtained "frame".Bodyindex Data taken out of the,just like Figure 3 .,putHuman body Areaand non-Human body Areaby their corresponding values. The Kinect SDK v1 is "player" by body area Yes"1"~"6" (because it is 6 people),Non-Human body Area"0" to fill in;Kinect SDKV2the preview version of "bodyindex" is based onHuman body Area"0"~"5", non-human domain"255 (0xff)" to fill in (Figure 1).
Figure 3 Bodyindex data
|
kinect SDK v1 |
kinect SDK v2 Preview |
name
player |
bodyindex |
test support number
6 people |
6 people |
The body area of the
1~6 |
0~5 |
The non-human realm |
0 |
255 (0xFF) |
Table 1 Comparison of human areas (Player,bodyindex) in the Kinect SDK V1 and Kinect SDK v2 previewThe sample program is tothe value of the Bodyindex,in theHuman body Areawithcolors for color table(="cv::vec3b (B,G,R) "),in non-Human body Areain Black(="cv::vec3b (0,0,0) ")coloring to achieve visualization.
Run ResultsRunThis example program, like Figure 4, V2 from thePreview version of theHuman body Areais shaded to show.
Figure 4 Running resultsthe small shape of the finger can be clearly split out.
SummaryThis section is usedKinect SDKV2Preview version madeBodyindex is an introduction to the sample program, the next section is gettingBody (Humanposture) is an introduction to the sample program.
"Translation" Kinect v2 programming (c + +) Bodyindex