none
Copy cropped image with RGB format directly from the kinect RRS feed

  • Question

  • When I try to copy cropped image to my byte array using colorFrame.LockRawImageBuffer() I get it as yuy2 format.

    Is there way to copy the cropped data as RGB (without of copping all the frame from the kinect)?

    I would appreciate any advice


    • Edited by TTroyAA Thursday, June 4, 2015 6:51 AM
    Thursday, June 4, 2015 6:51 AM

Answers

  • Locking the image buffer will always give you a YUY2 buffer. If you want RGBA, you will have to use CopyConvertedFrameDataToArray with the image format RGBA and an array of size 1920 * 1080 * 4.

    If you want a cropped image, you will have to copy the desired segment of data from this buffer, or use a source rectangle when rendering the texture:

    https://msdn.microsoft.com/en-us/library/windows/desktop/dd371880%28v=vs.85%29.aspx?f=255&MSPPError=-2147217396

    D2D_RECT_F dstRect;
    dstRect.left = 0;
    dstRect.right = 640;
    dstRect.top = 0;
    dstRect.bottom = 480;
    
    D2D_RECT_F sourceRect;
    dstRect.left = 50;
    dstRect.right = 150;
    dstRect.top = 0;
    dstRect.bottom = 300;
    
    m_pRenderTarget->DrawBitmap(
        m_pBitmap,
        dstRect, 
        1.0f,
        D2D1_BITMAP_INTERPOLATION_MODE_NEAREST_NEIGHBOR,
        sourceRect);

    If you just want a buffer of RGB, you would have to iterate over the array and discard the Alpha value.  However, this will be slow, so I would recommend just using the RGBA array and ignoring the Alpha value in your rendering logic.

    Thursday, June 4, 2015 7:24 AM
    Moderator