我正在使用 OpenCV,并且我正在尝试填充尺寸的垫子
cv::Mat Mat = cv::Mat(DEPTH_HEIGHT, DEPTH_WIDTH, CV_16U);
并在此 while 循环中用深度
值填充它:
while (curr < dataEnd) {
// Get depth in millimeters
USHORT depth = NuiDepthPixelToDepth(*curr++);
cv::Mat Mat++ = depth;
}
是否有某种方法可以迭代 Mat,以便将每个深度值存储在 HeightxWidth Mat 索引中?
最佳答案
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#),因为每行像素的开头可能与地址边界对齐。
关于c++ - OpenCV:在while循环中填充Mat?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24664090/