Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7806913
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T02:41:06+00:00 2026-06-02T02:41:06+00:00

I’m trying to get the Kinect depth camera pixels to overlay onto the RGB

  • 0

I’m trying to get the Kinect depth camera pixels to overlay onto the RGB camera. I am using the C++ Kinect 1.0 SDK with an Xbox Kinect, OpenCV and trying to use the new “NuiImageGetColorPixelCoordinateFrameFromDepthPixelFrameAtResolution” method.

I have watched the image render itself in slow motion and looks as if pixels are being drawn multiple times in the one frame. It first draws itself from the top and left borders, then it gets to a point (you can see a 45 degree angle in there) where it starts drawing weird.

I have been trying to base my code off of the C# code written by Adam Smith at the MSDN forums but no dice. I have stripped out the overlay stuff and just want to draw the depth normalized depth pixels where it “should” be in the RGB image.

The image on the left is what I’m getting when trying to fit the depth image to RGB space, and the image on the right is the “raw” depth image as I like to see it. I was hoping this my method would create a similar image to the one on the right with slight distortions.

Messed up depth map

This is the code and object definitions that I have at the moment:

// From initialization
INuiSensor *m_pNuiInstance;
NUI_IMAGE_RESOLUTION m_nuiResolution = NUI_IMAGE_RESOLUTION_640x480;
HANDLE m_pDepthStreamHandle;
IplImage *m_pIplDepthFrame;
IplImage *m_pIplFittedDepthFrame;


m_pIplDepthFrame = cvCreateImage(cvSize(640, 480), 8, 1);
m_pIplFittedDepthFrame = cvCreateImage(cvSize(640, 480), 8, 1);

// Method
IplImage *Kinect::GetRGBFittedDepthFrame() {
    static long *pMappedBits = NULL;

    if (!pMappedBits) {
         pMappedBits = new long[640*480*2];
    }

    NUI_IMAGE_FRAME pNuiFrame;
    NUI_LOCKED_RECT lockedRect;
    HRESULT hr = m_pNuiInstance->NuiImageStreamGetNextFrame(m_pDepthStreamHandle, 0, &pNuiFrame);

    if (FAILED(hr)) {
        // return the older frame
        return m_pIplFittedDepthFrame;
    }

    bool hasPlayerData = HasSkeletalEngine(m_pNuiInstance);

    INuiFrameTexture *pTexture = pNuiFrame.pFrameTexture;
    pTexture->LockRect(0, &lockedRect, NULL, 0);

    if (lockedRect.Pitch != 0) {
        cvZero(m_pIplFittedDepthFrame);

        hr = m_pNuiInstance->NuiImageGetColorPixelCoordinateFrameFromDepthPixelFrameAtResolution(
            m_nuiResolution,
            NUI_IMAGE_RESOLUTION_640x480,
            640 * 480, /* size is previous */ (unsigned short*) lockedRect.pBits,
            (640 * 480) * 2,  /* size is previous */ pMappedBits);

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

    for (int i = 0; i < lockedRect.size; i++) {
            unsigned char* pBuf = (unsigned char*) lockedRect.pBits + i;
            unsigned short* pBufS = (unsigned short*) pBuf;
            unsigned short depth = hasPlayerData ? ((*pBufS) & 0xfff8) >> 3 :  ((*pBufS) & 0xffff);
            unsigned char intensity = depth > 0 ? 255 - (unsigned char) (256 * depth / 0x0fff) : 0;

            long
                x = pMappedBits[i], // tried with *(pMappedBits + (i * 2)),
                y = pMappedBits[i + 1]; // tried with *(pMappedBits + (i * 2) + 1);

            if (x >= 0 && x < m_pIplFittedDepthFrame->width && y >= 0 && y < m_pIplFittedDepthFrame->height) {
                m_pIplFittedDepthFrame->imageData[x + y * m_pIplFittedDepthFrame->widthStep] = intensity;
            }

        }
    }

    pTexture->UnlockRect(0);
    m_pNuiInstance->NuiImageStreamReleaseFrame(m_pDepthStreamHandle, &pNuiFrame);

    return(m_pIplFittedDepthFrame);
}

Thanks

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-02T02:41:08+00:00Added an answer on June 2, 2026 at 2:41 am

    I have found that the problem was that the loop,

    for (int i = 0; i < lockedRect.size; i++) {
        // code
    }
    

    was iterating on a per-byte basis, not on a per-short (2 bytes) basis. Since lockedRect.size returns the number of bytes the fix was simply changing the increment to i += 2, even better would be changing it to sizeof(short), like so,

    for (int i = 0; i < lockedRect.size; i += sizeof(short)) {
        // code
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to understand how to use SyndicationItem to display feed which is
I'm trying to use string.replace('’','') to replace the dreaded weird single-quote character: ’ (aka
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
Basically, what I'm trying to create is a page of div tags, each has
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I am reading a book about Javascript and jQuery and using one of the
I am trying to render a haml file in a javascript response like so:
I want use html5's new tag to play a wav file (currently only supported

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.