NuiImageStreamGetNextFrame(m_pColorStreamHandle,0和imageFrame); 如果(失败(小时)) { 返回; } INuiFrameTexture*pTexture=imageFrame.pFrameTexture; NUI_LOCKED_RECT LockedRect; //锁定帧数据,以便Kinect知道在我们读取时不要修改它 pTexture->LockRect(0,&LockedRect,NULL,0); //确保我们收到了有效的数据 如果(锁定俯仰!=0) { BYTE*pBuffer=(BYTE*)LockedRect.pBits; cvSetData(img,(字节*)pBuffer,img->widthStep); Mat&m=Mat(img); Mat&hsv=Mat(); 向量mv=向量(3,Mat(cvSize(640480),cv8uc1)); CVT颜色(m、hsv、CV_BGR2HSV); CVT颜色(hsv、m、CVHSV2BGR)//*/ IplImage-iplimg(m); cvNamedWindow(“rgb”,1); cvShowImage(“rgb”和iplimg); //使用Direct2D绘制数据 m_pDrawColor->Draw(静态投影(LockedRect.pBits)、LockedRect.size); //如果用户按下屏幕截图按钮,则保存屏幕截图 如果(m_bSaveScreenshot) { WCHAR statusMessage[cStatusMessageMaxLen]; //检索到我的照片的路径 WCHAR屏幕快照路径[最大路径]; GetScreenshotFileName(screenshotPath,_countof(screenshotPath)); //将位图写入磁盘 hr=SaveBitmapToFile(静态投影(LockedRect.pBits),cColor宽度,cColor高度,32,屏幕快照路径); 如果(成功(hr)) { //设置状态栏以显示屏幕截图的保存位置 StringCchPrintf(statusMessage,cStatusMessageMaxLen,L“屏幕截图保存到%s”,屏幕截图路径); } 其他的 { StringCchPrintf(statusMessage,cStatusMessageMaxLen,L“无法将屏幕截图写入%s”,屏幕截图路径); } 设置状态消息(statusMessage); //关闭此选项,以便下一帧不再保存屏幕截图 m_bSaveScreenshot=假; } } //纹理处理完毕,请解锁它 pTexture->UnlockRect(0); //松开框架 m_pNuiSensor->NuiImageStreamReleaseFrame(m_pColorStreamHandle和imageFrame); },visual-c++,opencv,kinect,Visual C++,Opencv,Kinect" /> NuiImageStreamGetNextFrame(m_pColorStreamHandle,0和imageFrame); 如果(失败(小时)) { 返回; } INuiFrameTexture*pTexture=imageFrame.pFrameTexture; NUI_LOCKED_RECT LockedRect; //锁定帧数据,以便Kinect知道在我们读取时不要修改它 pTexture->LockRect(0,&LockedRect,NULL,0); //确保我们收到了有效的数据 如果(锁定俯仰!=0) { BYTE*pBuffer=(BYTE*)LockedRect.pBits; cvSetData(img,(字节*)pBuffer,img->widthStep); Mat&m=Mat(img); Mat&hsv=Mat(); 向量mv=向量(3,Mat(cvSize(640480),cv8uc1)); CVT颜色(m、hsv、CV_BGR2HSV); CVT颜色(hsv、m、CVHSV2BGR)//*/ IplImage-iplimg(m); cvNamedWindow(“rgb”,1); cvShowImage(“rgb”和iplimg); //使用Direct2D绘制数据 m_pDrawColor->Draw(静态投影(LockedRect.pBits)、LockedRect.size); //如果用户按下屏幕截图按钮,则保存屏幕截图 如果(m_bSaveScreenshot) { WCHAR statusMessage[cStatusMessageMaxLen]; //检索到我的照片的路径 WCHAR屏幕快照路径[最大路径]; GetScreenshotFileName(screenshotPath,_countof(screenshotPath)); //将位图写入磁盘 hr=SaveBitmapToFile(静态投影(LockedRect.pBits),cColor宽度,cColor高度,32,屏幕快照路径); 如果(成功(hr)) { //设置状态栏以显示屏幕截图的保存位置 StringCchPrintf(statusMessage,cStatusMessageMaxLen,L“屏幕截图保存到%s”,屏幕截图路径); } 其他的 { StringCchPrintf(statusMessage,cStatusMessageMaxLen,L“无法将屏幕截图写入%s”,屏幕截图路径); } 设置状态消息(statusMessage); //关闭此选项,以便下一帧不再保存屏幕截图 m_bSaveScreenshot=假; } } //纹理处理完毕,请解锁它 pTexture->UnlockRect(0); //松开框架 m_pNuiSensor->NuiImageStreamReleaseFrame(m_pColorStreamHandle和imageFrame); },visual-c++,opencv,kinect,Visual C++,Opencv,Kinect" />

Visual c++ 将OpenCV添加到VC++;Kinect SDK示例 我是C++新手,想把OpenCV添加到微软的Kinect样本中。通过修改此函数,我可以为ColorBasics-D2D示例执行此操作 void CColorBasics::ProcessColor() { HRESULT hr; NUI_IMAGE_FRAME imageFrame; // Attempt to get the color frame hr = m_pNuiSensor->NuiImageStreamGetNextFrame(m_pColorStreamHandle, 0, &imageFrame); if (FAILED(hr)) { return; } INuiFrameTexture * pTexture = imageFrame.pFrameTexture; NUI_LOCKED_RECT LockedRect; // Lock the frame data so the Kinect knows not to modify it while we're reading it pTexture->LockRect(0, &LockedRect, NULL, 0); // Make sure we've received valid data if (LockedRect.Pitch != 0) { BYTE * pBuffer = (BYTE*) LockedRect.pBits; cvSetData(img,(BYTE*) pBuffer, img->widthStep); Mat &m = Mat(img); Mat &hsv = Mat(); vector<Mat> mv = vector<Mat>(3,Mat(cvSize(640,480),CV_8UC1)); cvtColor(m,hsv,CV_BGR2HSV); cvtColor(hsv,m,CV_HSV2BGR);//*/ IplImage iplimg(m); cvNamedWindow("rgb",1); cvShowImage("rgb",&iplimg); // Draw the data with Direct2D m_pDrawColor->Draw(static_cast<BYTE *>(LockedRect.pBits), LockedRect.size); // If the user pressed the screenshot button, save a screenshot if (m_bSaveScreenshot) { WCHAR statusMessage[cStatusMessageMaxLen]; // Retrieve the path to My Photos WCHAR screenshotPath[MAX_PATH]; GetScreenshotFileName(screenshotPath, _countof(screenshotPath)); // Write out the bitmap to disk hr = SaveBitmapToFile(static_cast<BYTE *>(LockedRect.pBits), cColorWidth, cColorHeight, 32, screenshotPath); if (SUCCEEDED(hr)) { // Set the status bar to show where the screenshot was saved StringCchPrintf( statusMessage, cStatusMessageMaxLen, L"Screenshot saved to %s", screenshotPath); } else { StringCchPrintf( statusMessage, cStatusMessageMaxLen, L"Failed to write screenshot to %s", screenshotPath); } SetStatusMessage(statusMessage); // toggle off so we don't save a screenshot again next frame m_bSaveScreenshot = false; } } // We're done with the texture so unlock it pTexture->UnlockRect(0); // Release the frame m_pNuiSensor->NuiImageStreamReleaseFrame(m_pColorStreamHandle, &imageFrame); } void CColorBasics::ProcessColor() { HRESULT-hr; NUI_图像_帧图像帧; //尝试获取颜色框 hr=m_pNuiSensor->NuiImageStreamGetNextFrame(m_pColorStreamHandle,0和imageFrame); 如果(失败(小时)) { 返回; } INuiFrameTexture*pTexture=imageFrame.pFrameTexture; NUI_LOCKED_RECT LockedRect; //锁定帧数据,以便Kinect知道在我们读取时不要修改它 pTexture->LockRect(0,&LockedRect,NULL,0); //确保我们收到了有效的数据 如果(锁定俯仰!=0) { BYTE*pBuffer=(BYTE*)LockedRect.pBits; cvSetData(img,(字节*)pBuffer,img->widthStep); Mat&m=Mat(img); Mat&hsv=Mat(); 向量mv=向量(3,Mat(cvSize(640480),cv8uc1)); CVT颜色(m、hsv、CV_BGR2HSV); CVT颜色(hsv、m、CVHSV2BGR)//*/ IplImage-iplimg(m); cvNamedWindow(“rgb”,1); cvShowImage(“rgb”和iplimg); //使用Direct2D绘制数据 m_pDrawColor->Draw(静态投影(LockedRect.pBits)、LockedRect.size); //如果用户按下屏幕截图按钮,则保存屏幕截图 如果(m_bSaveScreenshot) { WCHAR statusMessage[cStatusMessageMaxLen]; //检索到我的照片的路径 WCHAR屏幕快照路径[最大路径]; GetScreenshotFileName(screenshotPath,_countof(screenshotPath)); //将位图写入磁盘 hr=SaveBitmapToFile(静态投影(LockedRect.pBits),cColor宽度,cColor高度,32,屏幕快照路径); 如果(成功(hr)) { //设置状态栏以显示屏幕截图的保存位置 StringCchPrintf(statusMessage,cStatusMessageMaxLen,L“屏幕截图保存到%s”,屏幕截图路径); } 其他的 { StringCchPrintf(statusMessage,cStatusMessageMaxLen,L“无法将屏幕截图写入%s”,屏幕截图路径); } 设置状态消息(statusMessage); //关闭此选项,以便下一帧不再保存屏幕截图 m_bSaveScreenshot=假; } } //纹理处理完毕,请解锁它 pTexture->UnlockRect(0); //松开框架 m_pNuiSensor->NuiImageStreamReleaseFrame(m_pColorStreamHandle和imageFrame); }

Visual c++ 将OpenCV添加到VC++;Kinect SDK示例 我是C++新手,想把OpenCV添加到微软的Kinect样本中。通过修改此函数,我可以为ColorBasics-D2D示例执行此操作 void CColorBasics::ProcessColor() { HRESULT hr; NUI_IMAGE_FRAME imageFrame; // Attempt to get the color frame hr = m_pNuiSensor->NuiImageStreamGetNextFrame(m_pColorStreamHandle, 0, &imageFrame); if (FAILED(hr)) { return; } INuiFrameTexture * pTexture = imageFrame.pFrameTexture; NUI_LOCKED_RECT LockedRect; // Lock the frame data so the Kinect knows not to modify it while we're reading it pTexture->LockRect(0, &LockedRect, NULL, 0); // Make sure we've received valid data if (LockedRect.Pitch != 0) { BYTE * pBuffer = (BYTE*) LockedRect.pBits; cvSetData(img,(BYTE*) pBuffer, img->widthStep); Mat &m = Mat(img); Mat &hsv = Mat(); vector<Mat> mv = vector<Mat>(3,Mat(cvSize(640,480),CV_8UC1)); cvtColor(m,hsv,CV_BGR2HSV); cvtColor(hsv,m,CV_HSV2BGR);//*/ IplImage iplimg(m); cvNamedWindow("rgb",1); cvShowImage("rgb",&iplimg); // Draw the data with Direct2D m_pDrawColor->Draw(static_cast<BYTE *>(LockedRect.pBits), LockedRect.size); // If the user pressed the screenshot button, save a screenshot if (m_bSaveScreenshot) { WCHAR statusMessage[cStatusMessageMaxLen]; // Retrieve the path to My Photos WCHAR screenshotPath[MAX_PATH]; GetScreenshotFileName(screenshotPath, _countof(screenshotPath)); // Write out the bitmap to disk hr = SaveBitmapToFile(static_cast<BYTE *>(LockedRect.pBits), cColorWidth, cColorHeight, 32, screenshotPath); if (SUCCEEDED(hr)) { // Set the status bar to show where the screenshot was saved StringCchPrintf( statusMessage, cStatusMessageMaxLen, L"Screenshot saved to %s", screenshotPath); } else { StringCchPrintf( statusMessage, cStatusMessageMaxLen, L"Failed to write screenshot to %s", screenshotPath); } SetStatusMessage(statusMessage); // toggle off so we don't save a screenshot again next frame m_bSaveScreenshot = false; } } // We're done with the texture so unlock it pTexture->UnlockRect(0); // Release the frame m_pNuiSensor->NuiImageStreamReleaseFrame(m_pColorStreamHandle, &imageFrame); } void CColorBasics::ProcessColor() { HRESULT-hr; NUI_图像_帧图像帧; //尝试获取颜色框 hr=m_pNuiSensor->NuiImageStreamGetNextFrame(m_pColorStreamHandle,0和imageFrame); 如果(失败(小时)) { 返回; } INuiFrameTexture*pTexture=imageFrame.pFrameTexture; NUI_LOCKED_RECT LockedRect; //锁定帧数据,以便Kinect知道在我们读取时不要修改它 pTexture->LockRect(0,&LockedRect,NULL,0); //确保我们收到了有效的数据 如果(锁定俯仰!=0) { BYTE*pBuffer=(BYTE*)LockedRect.pBits; cvSetData(img,(字节*)pBuffer,img->widthStep); Mat&m=Mat(img); Mat&hsv=Mat(); 向量mv=向量(3,Mat(cvSize(640480),cv8uc1)); CVT颜色(m、hsv、CV_BGR2HSV); CVT颜色(hsv、m、CVHSV2BGR)//*/ IplImage-iplimg(m); cvNamedWindow(“rgb”,1); cvShowImage(“rgb”和iplimg); //使用Direct2D绘制数据 m_pDrawColor->Draw(静态投影(LockedRect.pBits)、LockedRect.size); //如果用户按下屏幕截图按钮,则保存屏幕截图 如果(m_bSaveScreenshot) { WCHAR statusMessage[cStatusMessageMaxLen]; //检索到我的照片的路径 WCHAR屏幕快照路径[最大路径]; GetScreenshotFileName(screenshotPath,_countof(screenshotPath)); //将位图写入磁盘 hr=SaveBitmapToFile(静态投影(LockedRect.pBits),cColor宽度,cColor高度,32,屏幕快照路径); 如果(成功(hr)) { //设置状态栏以显示屏幕截图的保存位置 StringCchPrintf(statusMessage,cStatusMessageMaxLen,L“屏幕截图保存到%s”,屏幕截图路径); } 其他的 { StringCchPrintf(statusMessage,cStatusMessageMaxLen,L“无法将屏幕截图写入%s”,屏幕截图路径); } 设置状态消息(statusMessage); //关闭此选项,以便下一帧不再保存屏幕截图 m_bSaveScreenshot=假; } } //纹理处理完毕,请解锁它 pTexture->UnlockRect(0); //松开框架 m_pNuiSensor->NuiImageStreamReleaseFrame(m_pColorStreamHandle和imageFrame); },visual-c++,opencv,kinect,Visual C++,Opencv,Kinect,这个很好用。然而,当我想在SkeletalViewer示例中添加类似的内容时,它只是显示一个空窗口 /// <summary> /// Handle new color data /// </summary> /// <returns>true if a frame was processed, false otherwise</returns> bool CSkeletalViewerApp::Nui_GotColorAlert( ) { NUI

这个很好用。然而,当我想在SkeletalViewer示例中添加类似的内容时,它只是显示一个空窗口

/// <summary>
/// Handle new color data
/// </summary>
/// <returns>true if a frame was processed, false otherwise</returns>
bool CSkeletalViewerApp::Nui_GotColorAlert( )
{
NUI_IMAGE_FRAME imageFrame;
bool processedFrame = true;

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

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

INuiFrameTexture * pTexture = imageFrame.pFrameTexture;
NUI_LOCKED_RECT LockedRect;
pTexture->LockRect( 0, &LockedRect, NULL, 0 );
if ( LockedRect.Pitch != 0 )
{
    BYTE * pBuffer = (BYTE*) LockedRect.pBits;

    cvSetData(img,(BYTE*) pBuffer, img->widthStep);
    Mat m(img);
    IplImage iplimg(m);
    cvNamedWindow("rgb",1);
    cvShowImage("rgb",&iplimg);
    m_pDrawColor->Draw( static_cast<BYTE *>(LockedRect.pBits), LockedRect.size );
}
else
{
    OutputDebugString( L"Buffer length of received texture is bogus\r\n" );
    processedFrame = false;
}

pTexture->UnlockRect( 0 );

m_pNuiSensor->NuiImageStreamReleaseFrame( m_pVideoStreamHandle, &imageFrame );

return processedFrame;
}
//
///处理新的颜色数据
/// 
///如果处理了帧,则为true,否则为false
bool CSkeletalViewerApp::Nui_GotColorAlert()
{
NUI_图像_帧图像帧;
bool processedFrame=true;
HRESULT hr=m_pNuiSensor->NuiImageStreamGetNextFrame(m_pVideoStreamHandle、0和imageFrame);
如果(失败(小时))
{
返回false;
}
INuiFrameTexture*pTexture=imageFrame.pFrameTexture;
NUI_LOCKED_RECT LockedRect;
pTexture->LockRect(0,&LockedRect,NULL,0);
如果(锁定节距!=0)
{
BYTE*pBuffer=(BYTE*)LockedRect.pBits;
cvSetData(img,(字节*)pBuffer,img->widthStep);
matm(img);
IplImage-iplimg(m);
cvNamedWindow(“rgb”,1);
cvShowImage(“rgb”和iplimg);
m_pDrawColor->Draw(static_cast(LockedRect.pBits)、LockedRect.size);
}
其他的
{
OutputDebugString(L“接收到的纹理的缓冲区长度是假的\r\n”);
processedFrame=false;
}
pTexture->UnlockRect(0);
m_pNuiSensor->NuiImageStreamReleaseFrame(m_pVideoStreamHandle和imageFrame);
返回处理帧;
}
我不确定为什么相同的代码在这个例子中不起作用。我正在使用VisualStudio2010和OpenCV 2.4.2


谢谢

把它弄明白了。改成这个

if ( LockedRect.Pitch != 0 )
{
    BYTE * pBuffer = static_cast<BYTE *>(LockedRect.pBits);

    cvSetData(img,(BYTE*) pBuffer, img->widthStep);
    Mat m(img);
    IplImage iplimg(m);
    cvNamedWindow("rgb",1);
    cvShowImage("rgb",&iplimg);
    waitKey(1);
    m_pDrawColor->Draw( static_cast<BYTE *>(LockedRect.pBits), LockedRect.size );
}
if(锁定节距!=0)
{
字节*pBuffer=静态(LockedRect.pBits);
cvSetData(img,(字节*)pBuffer,img->widthStep);
matm(img);
IplImage-iplimg(m);
cvNamedWindow(“rgb”,1);
cvShowImage(“rgb”和iplimg);
等待键(1);
m_pDrawColor->Draw(static_cast(LockedRect.pBits)、LockedRect.size);
}

在哪里初始化
img
变量?如果您可以添加代码的这一部分,那就太好了。