Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/136.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++ MapColorFrameToDepthFrame(未处理的异常、访问冲突)_C++_Kinect Sdk - Fatal编程技术网

C++ MapColorFrameToDepthFrame(未处理的异常、访问冲突)

C++ MapColorFrameToDepthFrame(未处理的异常、访问冲突),c++,kinect-sdk,C++,Kinect Sdk,我尝试使用MapColorFrameToDepthFrame函数将深度图像与彩色图像对齐,但这行代码存在问题(未处理的异常,访问冲突): 以下是Nui_Gottepthalert的代码: bool CSkeletalViewerApp::Nui_GotDepthAlert( ){ NUI_IMAGE_FRAME imageFrame; bool processedFrame = true; HRESULT hr = m_pNuiSensor->NuiImageStreamGetNextF

我尝试使用MapColorFrameToDepthFrame函数将深度图像与彩色图像对齐,但这行代码存在问题(未处理的异常,访问冲突):

以下是Nui_Gottepthalert的代码:

bool CSkeletalViewerApp::Nui_GotDepthAlert( ){
NUI_IMAGE_FRAME imageFrame;
bool processedFrame = true;

HRESULT hr = m_pNuiSensor->NuiImageStreamGetNextFrame(
    m_pDepthStreamHandle,
    0,
    &imageFrame );

if ( FAILED( hr ) )
{
    return false;
}

m_depthTimeStamp = imageFrame.liTimeStamp;

INuiFrameTexture * pTexture = imageFrame.pFrameTexture;
NUI_LOCKED_RECT LockedRect;
pTexture->LockRect( 0, &LockedRect, NULL, 0 );
if ( 0 != LockedRect.Pitch )
{
    INuiCoordinateMapper* pMapper;
    NUI_DEPTH_IMAGE_POINT* depthPoints;

    depthPoints = new NUI_DEPTH_IMAGE_POINT[640 * 480];
    m_pNuiSensor->NuiGetCoordinateMapper(&pMapper);

    //NUI_DEPTH_IMAGE_PIXEL* pdepthpixel = (NUI_DEPTH_IMAGE_PIXEL*)LockedRect.Pitch;

    pMapper->MapColorFrameToDepthFrame(
        NUI_IMAGE_TYPE_COLOR,
        NUI_IMAGE_RESOLUTION_640x480,
        NUI_IMAGE_RESOLUTION_640x480,
        640 * 480, 
        (NUI_DEPTH_IMAGE_PIXEL*)LockedRect.Pitch,
        640 * 480, 
        depthPoints);

    //memcpy(m_depthD16, LockedRect.pBits, LockedRect.size);

    DWORD frameWidth, frameHeight;

    NuiImageResolutionToSize( imageFrame.eResolution, frameWidth, frameHeight );

    // draw the bits to the bitmap
    BYTE * rgbrun = m_depthRGBX;
    const USHORT * pBufferRun = (const USHORT *)LockedRect.pBits;

    depthData = (USHORT *)LockedRect.pBits;


    // end pixel is start + width*height - 1
    const USHORT * pBufferEnd = pBufferRun + (frameWidth * frameHeight);

    assert( frameWidth * frameHeight * g_BytesPerPixel <= ARRAYSIZE(m_depthRGBX) );
    USHORT depth;
    USHORT* depth1=(USHORT *)LockedRect.pBits;
    USHORT realDepth;
    while ( pBufferRun < pBufferEnd )//&& pDepth < depthEnd)
    {
        /**depthValues = pDepth->depth;
        depthValues++;*/

        //USHORT depth     = *pBufferRun;
        depth     = *pBufferRun;
        USHORT realDepth = NuiDepthPixelToDepth(depth);
        USHORT player    = NuiDepthPixelToPlayerIndex(depth);

        // transform 13-bit depth information into an 8-bit intensity appropriate
        // for display (we disregard information in most significant bit)
        BYTE intensity = static_cast<BYTE>(~(realDepth >> 4));

        // tint the intensity by dividing by per-player values
        *(rgbrun++) = intensity >> g_IntensityShiftByPlayerB[player];
        *(rgbrun++) = intensity >> g_IntensityShiftByPlayerG[player];
        *(rgbrun++) = intensity >> g_IntensityShiftByPlayerR[player];

        // no alpha information, skip the last byte
        ++rgbrun;

        ++pBufferRun;
    }



    m_pDrawDepth->Draw( m_depthRGBX, frameWidth * frameHeight * g_BytesPerPixel );


}
else
{
    processedFrame = false;
    OutputDebugString( L"Buffer length of received texture is bogus\r\n" );
}

pTexture->UnlockRect( 0 );

if(m_pDepthStreamHandle != NULL)
    m_pNuiSensor->NuiImageStreamReleaseFrame( m_pDepthStreamHandle, &imageFrame );  




return processedFrame;
bool CSkeletalViewerApp::Nui_gottepthalert(){
NUI_图像_帧图像帧;
bool processedFrame=true;
HRESULT hr=m_pNuiSensor->NuiImageStreamGetNextFrame(
m_pDepthStreamHandle,
0,
&图像框);
如果(失败(小时))
{
返回false;
}
m_depthTimeStamp=imageFrame.liTimeStamp;
INuiFrameTexture*pTexture=imageFrame.pFrameTexture;
NUI_LOCKED_RECT LockedRect;
pTexture->LockRect(0,&LockedRect,NULL,0);
如果(0!=锁定节距)
{
InuicoordinationMapper*pMapper;
数字深度图像点*深度点;
深度点=新的数字深度图像点[640*480];
m_pNuiSensor->NuigetCoordinationMapper(&pMapper);
//NUI_DEPTH_IMAGE_PIXEL*pdepthpixel=(NUI_DEPTH_IMAGE_PIXEL*)LockedRect.Pitch;
pMapper->MapColorFrameToDepthFrame(
NUI_图像_类型_颜色,
NUI_图像_分辨率_640x480,
NUI_图像_分辨率_640x480,
640 * 480, 
(NUI_深度_图像_像素*)LockedRect.Pitch,
640 * 480, 
深度点);
//memcpy(m_深度16,LockedRect.pBits,LockedRect.size);
DWORD帧宽,帧高;
NuiImageResolutionOnSize(imageFrame.eResolution、frameWidth、frameHeight);
//将位绘制到位图
字节*rgbrun=m_深度rgbx;
const USHORT*pBufferRun=(const USHORT*)LockedRect.pBits;
depthData=(USHORT*)LockedRect.pBits;
//结束像素为开始+宽度*高度-1
常量USHORT*pBufferEnd=pBufferRun+(帧宽*帧高);
断言(帧宽*帧高*g_字节/像素深度;
深度值++*/
//USHORT深度=*pBufferRun;
深度=*pBufferRun;
USHORT realDepth=NuiDepthPixelToDepth(深度);
USHORT player=NuiDepthPixelToPlayerIndex(深度);
//将13位深度信息转换为适合的8位强度
//用于显示(我们忽略最高有效位中的信息)
字节强度=静态_转换(~(realDepth>>4));
//通过除以每个玩家的值来着色强度
*(rgbrun++)=强度>>g_强度移位ByPlayerB[玩家];
*(rgbrun++)=强度>>g_强度移位比帕雷[玩家];
*(rgbrun++)=强度>>g_强度移位比帕耶尔[玩家];
//无alpha信息,跳过最后一个字节
++rgbrun;
++普布费伦;
}
m_pDrawDepth->Draw(m_depthRGBX,frameWidth*frameHeight*g_字节/像素);
}
其他的
{
processedFrame=false;
OutputDebugString(L“接收到的纹理的缓冲区长度是假的\r\n”);
}
pTexture->UnlockRect(0);
if(m_pDepthStreamHandle!=NULL)
m_pNuiSensor->NuiImageStreamReleaseFrame(m_pDepthStreamHandle和imageFrame);
返回处理帧;
}

有人能告诉我如何解决这个问题吗

谢谢你

我也遇到了一些类似的问题,经过长时间的努力,终于找到了解决的办法

我在代码中发现的第一个问题是MapColorFrameToDepthFrame函数,第五个参数似乎应该是LockedRect.pBits

第二个问题是如何定义pTexture

INuiFrameTexture* pTexture = imageFrame.pFrameTexture;
不起作用。你必须使用

m_pNuiSensor->NuiImageFrameGetDepthImagePixelFrameTexture(m_hDepthStreamHandle, &imageFrame, &bNearMode, &pTexture)
记得检查一下你是否成功完成了这个功能。我已经深入研究了原因

第三个问题是,你必须

delete[] depthPoints;
使用后将其释放到内存中,因为您在其上使用了新运算符

经过这一切,我的代码终于可以工作了。希望它能对你有所帮助

谢谢

delete[] depthPoints;