none
how to get color information RGB and depth information XYZ in C++ RRS feed

  • Question

  • I use kinect windows SDK 1.6.I want to combine depth data with the color color camera to display a colored CD image using openGL. I want to get the points clounds X,Y,Z and the R,G,B corresponding.,I don't get what I want, X,Y,Z are bigger than 0xfff.Besides,R,G,B can't be gotten.

    My code paste below.Thank you for your time and your attention.

    void collectdata(long  &d)

    {

          HRESULT hr;
    long& degree = d;
    HANDLE h1 =CreateEvent(NULL,TRUE,FALSE,NULL);
    HANDLE m_pDepthStreamHandle = NULL;
    HANDLE h3 = CreateEvent(NULL,TRUE,FALSE,NULL);
    HANDLE m_pVideoStreamHandle = NULL;
    hr= NuiImageStreamOpen(NUI_IMAGE_TYPE_COLOR,NUI_IMAGE_RESOLUTION_640x480,0,2,h1,&m_pDepthStreamHandle);
    hr= NuiImageStreamOpen(NUI_IMAGE_TYPE_DEPTH,NUI_IMAGE_RESOLUTION_640x480,0,2,h3,&m_pVideoStreamHandle);
    if(labs(degree)%ANGLE==0)
    {
    const NUI_IMAGE_FRAME *pImageFrame1 = NULL;
    const NUI_IMAGE_FRAME *pImageFrame2 = NULL;
    if(WaitForSingleObject(h1,INFINITE)==WAIT_OBJECT_0&&WaitForSingleObject(h3,INFINITE)==WAIT_OBJECT_0);
    {
       hr = NuiImageStreamGetNextFrame(m_pDepthStreamHandle,0,&pImageFrame1);
    hr = NuiImageStreamGetNextFrame(m_pVideoStreamHandle,0,&pImageFrame2);
    if(S_OK==hr)
    {
    INuiFrameTexture *pTexture2 = pImageFrame2->pFrameTexture;
            NUI_LOCKED_RECT lockrect2;
    pTexture2->LockRect(0,&lockrect2,NULL,0);
    if(lockrect2.Pitch!=0)
    {
    KinectPoint temp;
    long colorx,colory;
    for(int i=0;i<480;i++)
    {
    byte *pBuffer = (byte*)lockrect2.pBits;
    USHORT *pBufferRun = (USHORT*)pBuffer;
    for(int j=0;j<640;j++)
    {
       Vector4 v = NuiTransformDepthImageToSkeleton(j/640.0f,i/480.0f,*pBufferRun<<3);
    temp.x = v.x;
    temp.y = v.y;
    temp.z = -v.z;
    NuiImageGetColorPixelCoordinatesFromDepthPixel(NUI_IMAGE_RESOLUTION_640x480,0,j/2,i/2,*pBufferRun<<3,&colorx,&colory);

    int a = (colorx+(colory-1)*640)*4;
    temp.R = pBuffer[a+2];
    temp.G = pBuffer[a+1];
    temp.B = pBuffer[a];

    pBufferRun++;
    VectorPointClouds.push_back(temp);
    }
    }
    }
    }  
    }
    NuiImageStreamReleaseFrame(m_pDepthStreamHandle,pImageFrame1);
    NuiImageStreamReleaseFrame( m_pVideoStreamHandle, pImageFrame2);
          }

    }

    Thursday, November 22, 2012 7:21 AM

All replies

  • I want to show point clouds(X,Y,Z) with color(R,G,B) in OpenGL,the data gotten through kinect in SDK 1.6.But I don't know how to change depth to XYZ ,and how to align color information RGB with depth information XYZ.This question confused me few days,hope you will help me.Thanks a lot.I am looking forward to you reply.Thanks again!
    Tuesday, November 27, 2012 2:14 AM
  • Have a look at this
    http://social.msdn.microsoft.com/Forums/en-US/kinectsdknuiapi/thread/92b45ec7-041c-4614-ad6d-55410eb144f6
    Wednesday, November 28, 2012 1:44 AM