1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123
|
/****************************************************************************
* *
* OpenNI 1.x Alpha *
* Copyright (C) 2011 PrimeSense Ltd. *
* *
* This file is part of OpenNI. *
* *
* OpenNI is free software: you can redistribute it and/or modify *
* it under the terms of the GNU Lesser General Public License as published *
* by the Free Software Foundation, either version 3 of the License, or *
* (at your option) any later version. *
* *
* OpenNI is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU Lesser General Public License for more details. *
* *
* You should have received a copy of the GNU Lesser General Public License *
* along with OpenNI. If not, see <http://www.gnu.org/licenses/>. *
* *
****************************************************************************/
//---------------------------------------------------------------------------
// Includes
//---------------------------------------------------------------------------
#include <XnOpenNI.h>
//---------------------------------------------------------------------------
// Defines
//---------------------------------------------------------------------------
#define SAMPLE_XML_PATH "/etc/openni/SamplesConfig.xml"
#define SAMPLE_XML_PATH_LOCAL "SamplesConfig.xml"
//---------------------------------------------------------------------------
// Macros
//---------------------------------------------------------------------------
#define CHECK_RC(rc, what) \
if (rc != XN_STATUS_OK) \
{ \
printf("%s failed: %s\n", what, xnGetStatusString(rc)); \
return rc; \
}
//---------------------------------------------------------------------------
// Code
//---------------------------------------------------------------------------
XnBool fileExists(const char *fn)
{
XnBool exists;
xnOSDoesFileExist(fn, &exists);
return exists;
}
int main()
{
XnStatus nRetVal = XN_STATUS_OK;
XnContext* pContext;
XnNodeHandle hScriptNode;
XnEnumerationErrors* pErrors;
XnNodeHandle hDepth;
XnDepthMetaData* pDepthMD;
const XnDepthPixel* pDepthMap;
XnDepthPixel middlePoint;
const char *fn = NULL;
nRetVal = xnEnumerationErrorsAllocate(&pErrors);
CHECK_RC(nRetVal, "Allocate errors object");
if (fileExists(SAMPLE_XML_PATH)) fn = SAMPLE_XML_PATH;
else if (fileExists(SAMPLE_XML_PATH_LOCAL)) fn = SAMPLE_XML_PATH_LOCAL;
else {
printf("Could not find '%s' nor '%s'. Aborting.\n" , SAMPLE_XML_PATH, SAMPLE_XML_PATH_LOCAL);
return XN_STATUS_ERROR;
}
printf("Reading config from: '%s'\n", fn);
nRetVal = xnInitFromXmlFileEx(fn, &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;
}
|