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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T01:35:17+00:00 2026-06-11T01:35:17+00:00

The following piece of code works well in retrieving depth value at row 240

  • 0

The following piece of code works well in retrieving depth value at row 240 and col 320.

    capture.retrieve( rawdepth, CV_CAP_OPENNI_DEPTH_MAP); // Mat rawdepth(Size(640,480), CV_16UC1);
    cout << "rows: " << rawdepth.rows << " cols: " << rawdepth.cols << endl;
    cout << "depth is " << rawdepth.at<unsigned short>(rawdepth.rows/2,rawdepth.cols/2) << endl;

If I stand in front of Kinect at 1m, it gives value approx. 900-1100. But when I added this following code, and I stand in front of kinect camera, both yield different result.

        uint16_t* depthdata = (uint16_t*)rawdepth.data;
        cout << "depthdata is " << depthdata[76800] << endl;

depthdata[76800] always yields 0, even if I move kinect to face other direction.

If I use the following code, and face the Kinect against a flat wall, (rawdepth.rows/2,rawdepth.cols/2) gives same result as depthdata[78600].

        uint16_t* depthdata = (uint16_t*)rawdepth.data;
        cout << "depthdata is " << depthdata[78600] << endl;

My question is, if depthdata at 76800 is not equal to (rawdepth.rows/2, rawdepth.cols/2), I wonder, what is? I obtained 76800 from 240*320.

  • 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-11T01:35:18+00:00Added an answer on June 11, 2026 at 1:35 am

    If a matrix is row aligned, the way to access an element at position (x, y) is by using something like:

        matrix[y*elements_per_row + x]
    

    Matrices in OpenCV are designed to be 32-bit aligned, so there is often some padding at the end of each row. CvMat has a field size_t step which tells you the width of each row in bytes.

    try this, and see if it gives the result you expect:

        uint8_t* depthdata = (uint8_t*)rawdepth.data;
        uint16_t middle_element = *(uint16_t *)(depthdata + rawdepth.step*240 + sizeof(uint16_t)*320);
        cout << "depthdata is " << middle_element << endl;
    

    ref:
    OpenCV's cv::Mat & CvMat row alignment

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following piece of code that works well in Windows Server 2003.
Following piece works very well in silverlight , <Grid x:Name=ContentPanelInner Grid.Row=1 Margin=12,0,12,0> <StackPanel x:Name=stackPanelInner>
the following piece of code works fine when i use it among some code
The following piece of code works perfectly in script/console but returns the following error
I've the following piece of code which works on one page and doesn't work
I am a little confused why the following piece of code actually works: String.instance_eval
The following piece of code works perfectly in all browsers, bar IE. As usual.
this following piece of code works, but it sort of makes the browser quirk
I have the following piece of code which works fine and does what it
Following piece of code works in my localhost, but when i upload files in

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.