Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/135.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ 在C+中通过OpenNI显示深度和Rgb图像时出现异常+;_C++_Kinect_Openni - Fatal编程技术网

C++ 在C+中通过OpenNI显示深度和Rgb图像时出现异常+;

C++ 在C+中通过OpenNI显示深度和Rgb图像时出现异常+;,c++,kinect,openni,C++,Kinect,Openni,我是openNI和Kinect的新手,我尝试通过openNI.org中的教程在以下链接实现openNI SimpleViewer: 我已经实现了本教程中描述的代码,但我仍然面临着问题,因为程序正在抛出异常,并且没有显示任何输出 我已链接所有库并正确安装了kinect。我还将OpenCV库包含在openNI中 这是我已经实现的C++代码: int main() { rc = context.InitFromXmlFile(XML_PATH,&errors); if(rc =

我是openNI和Kinect的新手,我尝试通过openNI.org中的教程在以下链接实现openNI SimpleViewer:

我已经实现了本教程中描述的代码,但我仍然面临着问题,因为程序正在抛出异常,并且没有显示任何输出

我已链接所有库并正确安装了kinect。我还将OpenCV库包含在openNI中

这是我已经实现的C++代码:

int main()
{
    rc = context.InitFromXmlFile(XML_PATH,&errors);
    if(rc == XN_STATUS_NO_NODE_PRESENT)
    {
        XnChar strError[1024];
        errors.ToString(strError,1024);
        printf("%s\n",strError);
        return(rc);
    }
    else if(rc != XN_STATUS_OK)
    {
        printf("Open failed : %s\n", xnGetStatusString(rc));
        return(rc);
    }

    rc = context.FindExistingNode(XN_NODE_TYPE_DEPTH,depth);
    if(rc != XN_STATUS_OK)
    {
        printf("No Depth Node Found. Check XML!\n");
        return -1;
    }
    depth.GetMetaData(depthMD);
    image.GetMetaData(imageMD);

    if(imageMD.FullXRes() != depthMD.FullXRes() || imageMD.FullYRes() != depthMD.FullYRes())
    {
        printf("The device depth and image resolution must be equal\n");
        return -1;
    }
    if(imageMD.PixelFormat() != XN_PIXEL_FORMAT_RGB24)
    {
        printf("The Device Image Format must be RGB24\n");
        return -1;
    }

    unsigned short textMapX = (((unsigned short)(depthMD.FullXRes() - 1)/512) + 1 * 512);
    unsigned short textMapY = (((unsigned short)(depthMD.FullYRes() - 1)/512) + 1 * 512);
    XnRGB24Pixel* pTextMap = (XnRGB24Pixel*) malloc(textMapX * textMapY * sizeof(XnRGB24Pixel));
    rc = context.WaitOneUpdateAll(depth);
    depth.GetMetaData(depthMD);
    image.GetMetaData(imageMD);
    const XnDepthPixel* pDepth = depthMD.Data();
    const XnUInt8* pImage = imageMD.Data();
    unsigned int imageScale = GL_WIN_SIZE_X/depthMD.FullXRes();

    xnOSMemSet(depthHist,0,MAX * sizeof(float));
    unsigned int numberOfPoints = 0;
    for(XnUInt y = 0; y < depthMD.YRes(); ++ y)
    {
        for(XnUInt x = 0; x < depthMD.XRes(); ++x, ++pDepth);
        {
            if(*pDepth != 0)
            {
                depthHist[*pDepth]++;
                numberOfPoints++;
            }
        }
    }
    for(int index = 1; index < MAX; index++)
    {
        depthHist[index] += depthHist[index - 1];
    }
    if(numberOfPoints)
    {
        for(int index = 1; index < MAX; index++)
        {
            depthHist[index] = (unsigned int)(256 * (1.0f - (depthHist[index]/numberOfPoints)));
        }
    }
    return 0;
}
intmain()
{
rc=context.InitFromXmlFile(XML_路径和错误);
如果(rc==XN\u状态\u无节点\u存在)
{
新罕布什尔州斯特里罗[1024];
错误。ToString(strError,1024);
printf(“%s\n”,strError);
返回(rc);
}
否则如果(rc!=XN\u状态\u正常)
{
printf(“打开失败:%s\n”,xnGetStatusString(rc));
返回(rc);
}
rc=context.FindExistingNode(XN\u节点\u类型\u深度,深度);
如果(rc!=XN\u状态\u正常)
{
printf(“未找到深度节点。请检查XML!\n”);
返回-1;
}
获取元数据(depthMD);
GetMetaData(imageMD);
if(imageMD.FullXRes()!=depthMD.FullXRes()| | imageMD.FullYRes()!=depthMD.FullYRes())
{
printf(“设备深度和图像分辨率必须相等\n”);
返回-1;
}
if(imageMD.PixelFormat()!=XN\u PIXEL\u格式\u RGB24)
{
printf(“设备图像格式必须为RGB24\n”);
返回-1;
}
无符号短文本映射x=((无符号短文本)(depthMD.FullXRes()-1)/512)+1*512);
无符号短文本映射=((无符号短)(depthMD.FullYRes()-1)/512)+1*512);
XnRGB24Pixel*pTextMap=(XnRGB24Pixel*)malloc(textmappx*textmappy*sizeof(XnRGB24Pixel));
rc=context.waitoneUpdatell(深度);
获取元数据(depthMD);
GetMetaData(imageMD);
常数XnDepthPixel*pDepth=depthMD.Data();
const XnUInt8*pImage=imageMD.Data();
无符号整数imageScale=GL_WIN_SIZE_X/depthMD.FullXRes();
xnOSMemSet(深度历史,0,最大*sizeof(浮动));
无符号整数numberOfPoints=0;
对于(XnUInt y=0;y

我在理解代码的后面部分时也遇到了问题。

您得到的异常是什么?您是否考虑过所有if语句都返回false这一事实?然后它返回0并关闭