在while循环中填充Mat

OpenCV: Fill Mat in while loop?

本文关键字:填充 Mat 循环 while      更新时间:2023-10-16

我正在使用OpenCV,我正在尝试填充大小

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

并将其填充为while循环中的depth值:

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

是否有一些方法迭代到垫,使每个深度值存储在一个HeightxWidth垫索引?

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

注意,你应该使用ptr(row#),因为每一行像素的开始可能与地址边界对齐。