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 8351793
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T08:45:15+00:00 2026-06-09T08:45:15+00:00

I’m new to C++ and trying to add OpenCV into Microsoft’s Kinect samples. I

  • 0

I’m new to C++ and trying to add OpenCV into Microsoft’s Kinect samples. I was able to do it for the ColorBasics-D2D sample by modifying this function

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);
}

This works fine. However, when I wanted to add something like this to the SkeletalViewer example, it is just displaying an empty window.

/// <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;
}

I’m not sure why the same code doesn’t work in this example. I’m using Visual Studio 2010 and OpenCV 2.4.2.

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-09T08:45:17+00:00Added an answer on June 9, 2026 at 8:45 am

    Figured it out. Changed it to this

    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 );
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
this is what i have right now Drawing an RSS feed into the php,
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
For some reason, after submitting a string like this Jack’s Spindle from a text
I am trying to understand how to use SyndicationItem to display feed which is
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
I have this code to decode numeric html entities to the UTF8 equivalent character.

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.