Reputation: 1978
Trying to get a body tracked by Kinect V2 using C++ but its not working as its supposed to, Also the Microsoft's documentation on C++ API for kinect V2 is exceptionally poor
relevant code snippet:
HRESULT result;
if (BodyFrameReader != nullptr)
{
result = BodyFrameReader->AcquireLatestFrame(&BodyFrame);
if (result == S_OK)
{
IBody** bodies =nullptr;
result = BodyFrame->GetAndRefreshBodyData(BODY_COUNT, bodies);
if (result == S_OK)
Print("Success");
else
Print("Fail "+result );
BodyFrame->Release();
}
}
So the first result on reading the frame using AcquireLatestFrame
returns S_OK
however trying to get info for any tracked body using GetAndRefreshBodyData
always returns an error code in the variable result
which is some very large negative number (-ve MAXINT_32) .
Apart from this another thing I've noticed is in some docs it hints as if GetAndRefreshBodyData
needs an array of IBody
as a parameter now IBody
is an interface and it can't be instantiated so how are you supposed to do that.
Is there some additional setup needs to be done apart from Kinect->Open()
to get to body tracking?
Upvotes: 2
Views: 556
Reputation: 3149
You're right, Microsoft's documentation is pretty bad. But the SDK comes with quite a few sample projects, which are always a good starting point. For your case, take a look at the BodyBasics C++ sample. There you'll find code like the following:
IBody* ppBodies[BODY_COUNT] = {0}; // BODY_COUNT is 6
hr = pBodyFrame->GetAndRefreshBodyData(_countof(ppBodies), ppBodies);
Upvotes: 4