示例#1
0
int main()
{
    XnStatus nRetVal = XN_STATUS_OK;
    XnContext* pContext;
    XnNodeHandle hScriptNode;
    XnEnumerationErrors* pErrors;
    XnNodeHandle hDepth;
    XnDepthMetaData* pDepthMD;
    const XnDepthPixel* pDepthMap;
    XnDepthPixel middlePoint;

    nRetVal = xnEnumerationErrorsAllocate(&pErrors);
    CHECK_RC(nRetVal, "Allocate errors object");

    nRetVal = xnInitFromXmlFileEx(SAMPLE_XML_PATH, &pContext, pErrors, &hScriptNode);
    if (nRetVal == XN_STATUS_NO_NODE_PRESENT)
    {
        XnChar strError[1024];
        xnEnumerationErrorsToString(pErrors, strError, 1024);
        printf("%s\n", strError);
        xnEnumerationErrorsFree(pErrors);
        return (nRetVal);
    }
    else if (nRetVal != XN_STATUS_OK)
    {
        printf("Open failed: %s\n", xnGetStatusString(nRetVal));
        xnEnumerationErrorsFree(pErrors);
        return (nRetVal);
    }

    xnEnumerationErrorsFree(pErrors);

    nRetVal = xnFindExistingRefNodeByType(pContext, XN_NODE_TYPE_DEPTH, &hDepth);
    CHECK_RC(nRetVal, "Find depth generator");

    pDepthMD = xnAllocateDepthMetaData();

    while (!xnOSWasKeyboardHit())
    {
        nRetVal = xnWaitOneUpdateAll(pContext, hDepth);
        if (nRetVal != XN_STATUS_OK)
        {
            printf("UpdateData failed: %s\n", xnGetStatusString(nRetVal));
            continue;
        }

        xnGetDepthMetaData(hDepth, pDepthMD);
        pDepthMap = pDepthMD->pData;
        middlePoint = pDepthMap[pDepthMD->pMap->Res.X * pDepthMD->pMap->Res.Y/2 + pDepthMD->pMap->Res.X/2];

        printf("Frame %d Middle point is: %u\n", pDepthMD->pMap->pOutput->nFrameID, middlePoint);
    }

    xnFreeDepthMetaData(pDepthMD);

    xnProductionNodeRelease(hDepth);
    xnProductionNodeRelease(hScriptNode);
    xnContextRelease(pContext);

    return 0;
}
示例#2
0
BP::object Context_FindExistingNode_wrapped(xn::Context& self, XnProductionNodeType type) {
    XnNodeHandle ret = NULL;
    xnFindExistingRefNodeByType(self.GetUnderlyingObject(), type, &ret);
    return wrapNode(ret);
}