首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >MapColorFrameToDepthFrame (未处理的异常,访问冲突)

MapColorFrameToDepthFrame (未处理的异常,访问冲突)
EN

Stack Overflow用户
提问于 2014-10-09 20:52:16
回答 1查看 506关注 0票数 0

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

代码语言:javascript
复制
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);

下面是Nui_GotDepthAlert的代码:

代码语言:javascript
复制
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;

}

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

谢谢

EN

回答 1

Stack Overflow用户

发布于 2014-12-01 14:12:57

那里,

我也遇到了一些类似的问题,在苦苦挣扎了很长时间之后,我终于找到了它的诀窍。

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

第二个问题是如何定义pTexture,

代码语言:javascript
复制
INuiFrameTexture* pTexture = imageFrame.pFrameTexture;

不会起作用。你必须使用

代码语言:javascript
复制
m_pNuiSensor->NuiImageFrameGetDepthImagePixelFrameTexture(m_hDepthStreamHandle, &imageFrame, &bNearMode, &pTexture)

请记住检查此函数是否成功。我已经深入挖掘,找出原因。

第三个问题是,你必须

代码语言:javascript
复制
delete[] depthPoints;

使用后释放到内存中,因为你对它使用了new运算符。

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

谢谢。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/26278917

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档