2
votes

I'm using OpenCV, and I'm trying to fill a Mat of size

cv::Mat Mat = cv::Mat(DEPTH_HEIGHT, DEPTH_WIDTH, CV_16U);

and fill it with the depth value in this while loop:

        while (curr < dataEnd) {
        // Get depth in millimeters
        USHORT depth = NuiDepthPixelToDepth(*curr++);
        cv::Mat Mat++ = depth;
        }

Is there some way to iterate into the Mat such that each depth value is stored in a HeightxWidth Mat index?

1

1 Answers

2
votes
for (i=0;i<mat.rows;i++)
{
 uint16_t* ptr = mat.ptr<uint16_t>(i);
 for (j=0;j<mat.cols;j++)
 {
   *ptr++ = value for pixel (i,j)
 }     
}

Note you should use ptr(row#) because the start of each row of pixels may be aligned to an address boundary.