Kinect 2 - AcquireLatestFrame () does not work most of the time

The following C ++ code is specified, which continuously extracts the last frame from Kinect 2.

int main()
{
    setupKinect();
    acquireFrames();  
    return 0;
}

template<class Interface>
inline static void safeRelease(Interface *&interfaceToRelease)
{
    if (interfaceToRelease != nullptr) {
        interfaceToRelease->Release();
        interfaceToRelease = nullptr;
    }
}

void acquireFrames() {
    while (true) {
        if (bodyFrameReader != nullptr) {
            IBodyFrame* bodyFrame = nullptr;
            HRESULT hr = bodyFrameReader->AcquireLatestFrame(&bodyFrame);
            if (SUCCEEDED(hr)) {
                // processing bodyFrame 
            } else {    
                // acquiring frame failed   
            }
            safeRelease(bodyFrame);
        }
    }
}

void setupKinect() {
    IKinectSensor * sensor = nullptr;
    HRESULT hr = GetDefaultKinectSensor(&sensor);
    if (SUCCEEDED(hr)) {
        hr = sensor->Open();
        if (SUCCEEDED(hr)) {
            IBodyFrameSource* bodyFrameSource = nullptr;
            hr = sensor->get_BodyFrameSource(&bodyFrameSource);
            if (SUCCEEDED(hr)) {
                hr = bodyFrameSource->OpenReader(&bodyFrameReader);

            }
            safeRelease(bodyFrameSource);
        }
    }
    safeRelease(sensor);
}

Why AcquireLatestFramemost often returns unsuccessful HRESULT? Some testing has shown that a function only succeeds about 30 times per second, so it seems that a certain frame will be received or returned no more than once by this function (Kinect frame rate is 30 frames per second). It is right?

+4
source share
1 answer

Yes you are right.

: . "30hz" " " : ( )

https://developer.microsoft.com/en-us/windows/kinect/hardware

:

: HRESULT

S_OK ; .

(: https://msdn.microsoft.com/en-us/library/microsoft.kinect.kinect.ibodyframereader.acquirelatestframe.aspx)

HRESULT, , - E_PENDING. , .


: AcquireLatestFrame HRESULT?

( , ).

+1

Source: https://habr.com/ru/post/1653616/


All Articles