• Kinect SDK提取彩色像素


    #include <iostream>
    using namespace std;

    #include <Windows.h>
    #include "MSR_NuiApi.h"
    //#include "highgui.h"

    int main(int argc,char **argv)
    {
    // IplImage *img;
    // CvScalar s;
    // img=cvCreateImage(cvSize(640,480),IPL_DEPTH_8U,3);

    HRESULT hr = NuiInitialize( NUI_INITIALIZE_FLAG_USES_COLOR );
    if ( FAILED( hr ) )
    {
    cout<<"NuiInitialize failed"<<endl;
    return hr;
    }

    HANDLE h1=CreateEvent(NULL,TRUE,FALSE,NULL);
    HANDLE h2=NULL;

    hr=NuiImageStreamOpen(NUI_IMAGE_TYPE_COLOR,NUI_IMAGE_RESOLUTION_640x480,0,4,h1,&h2);
    if (hr != S_OK)
    {
    cout<<"NuiImageStreamOpen failed"<<endl;
    return hr;
    }

    while(1)
    {
    WaitForSingleObject(h1,INFINITE);
    const NUI_IMAGE_FRAME *pImageFrame = NULL;
    hr=NuiImageStreamGetNextFrame(h2,0,&pImageFrame);
    if ( hr != S_OK )
    {
    cout<<"Get Image Frame Failed"<<endl;
    continue;
    }

    INuiFrameTexture *pTexture=pImageFrame->pFrameTexture;
    NUI_LOCKED_RECT LockedRect;
    pTexture->LockRect(0,&LockedRect,NULL,0);
    if ( LockedRect.Pitch != 0 )
    {
    BYTE *pBuffer=(BYTE*)LockedRect.pBits;
    pBuffer+=(200+399*640)*4;
    cout<<"(200,400) pix is:";
    cout<<" r:"<<pBuffer[2];
    cout<<" g:"<<pBuffer[1];
    cout<<" b:"<<pBuffer[0];
    cout<<endl;
    /*
    for (int i=0;i<640;i++)
    {
    for (int j=0;j<480;j++)
    {
    s=cvGet2D(img,i,j);
    pBuffer=(BYTE*)((j+640*i)*4);
    s.val[0]=pBuffer[0];
    s.val[1]=pBuffer[1];
    s.val[2]=pBuffer[2];
    cvSet2D(img,i,j,s);
    }
    }

    cvNamedWindow("image");
    cvShowImage("image",img);
    */
    }
    else
    {
    cout<<"_______"<<endl;
    }
    NuiImageStreamReleaseFrame(h2,pImageFrame);

    }

    NuiShutdown();
    // cvDestroyAllWindows();
    // cvReleaseImage(&img);
    return 0;

    }
  • 相关阅读:
    HDU 1423
    POJ 3264
    POJ 3177
    CodeForces 81A
    SPOJ RATING
    ZOJ 2588
    POJ 1523
    POJ 3667
    递归
    数据结构
  • 原文地址:https://www.cnblogs.com/tiandsp/p/2396559.html
Copyright © 2020-2023  润新知