none
How to treat depth data in Kinectv2 in C++? RRS feed

  • Question

  • I'm pretty new using C++ and Kinectv2 and I am too used to code in Matalb but I have to do a project treating depth data and tracking with Kinect in C++. I downloaded the sample where depth data is captured and displayed in a windows from Microsoft, Depth Basiics-D2D, and I was looking into it but I was not able to find any variable that for each pixel give you its depth. I just only saw pDepthFrame which I guess it is the frame object and pFrameDescription that I believe it contains different data from the frame.

    IDepthFrame* pDepthFrame = NULL;
    
        HRESULT hr = m_pDepthFrameReader->AcquireLatestFrame(&pDepthFrame);
    
        if (SUCCEEDED(hr))
            {   
                hr = pDepthFrame->get_FrameDescription(&pFrameDescription);
            }

    I saw this method that handle new Depthdata but I'm not sure how it affects pDepthFrame :


    void CDepthBasics::ProcessDepth(INT64 nTime, const UINT16* pBuffer, int nWidth, int nHeight, USHORT nMinDepth, USHORT nMaxDepth)

    So my questions are: Which variable should I use? How is this data? Is there anything that for every pixel I would be able to get the depth?

    Thank you very much.


    Thursday, February 23, 2017 5:55 PM

Answers

  • pDepthFrame is the data bundle you get from the sensor. There are two ways to process the data, you can either call  DepthFrame.CopyFrameDataToArray or one of its alternatives in order to copy the data to a local buffer and process the buffer, or you can access the underlying buffer itself(the one inside pDepthFrame) and process on the fly. Depth Basics D2D uses the second option.

    if (SUCCEEDED(hr))
    {
                hr = pDepthFrame->AccessUnderlyingBuffer(&nBufferSize, &pBuffer);            
    }
    
    if (SUCCEEDED(hr))
    {
                ProcessDepth(nTime, pBuffer, nWidth, nHeight, nDepthMinReliableDistance, nDepthMaxDistance);
    }
    pBuffer is the one you need. You can check this, where it says Depth Frame, to understand what the data inside pBuffer are.

    • Marked as answer by GuillemDelgado Friday, February 24, 2017 9:34 AM
    Friday, February 24, 2017 8:16 AM